Any ideas?
Code: Select all
<?php
global $stock;
global $turns;
//global $harvestCount;
$harvestCount = $_POST['harvest'];
echo '<!DOCTYPE HTML>';
session_start();
$stock = $_SESSION['stock1'];
$turns = $_SESSION['turns1'];
$harvestX = $_SESSION['totalH1'];
echo "Last stock was " . floor($_SESSION['stock1']) . "</br>";
function Birth(){
global $stock;
$birthCount = $stock * abs(((rand(0,10))/10)+(rand(0,10)/10));
if($birthCount > 0){
$stock += $birthCount;
$_SESSION['birthCount'] = floor($birthCount);
echo floor($birthCount) . " " . "fish born!</br>";
echo floor($stock) . " " . "fish are now in population</br>";
}
return $stock;
}
function Death(){
global $stock;
$deathCount = $stock * abs(((rand(0,10))/10)-(rand(0,10)/10));
if($deathCount > 0){
$stock -= $deathCount;
$_SESSION['deathCount'] = floor($deathCount);
echo floor($deathCount) . " " . "fish died...</br>";
echo floor($stock) . " " . "fish remain after death cycle</br>";
}
return $stock;
}
function Harvest(){
global $stock;
global $harvestCount;
global $harvestX;
$harvestX = $harvestX + $harvestCount;
if($harvestCount > 0){
$stock -= $harvestCount;
echo floor($harvestCount) . " " . "fish harvested.</br>";
echo floor($stock) . " " . "fish remain after harvesting.</br>";
}
return $stock;
}
if($stock > 0){
Birth();
Death();
Harvest();
$stock = $_SESSION['stock'] = $stock;
$turns = $turns + 1;
$turns = $_SESSION['turns'] = $turns;
$harvestX = $_SESSION['totalH'] = $harvestX;
if($harvestCount){
$harvestCount = 0;
}
// HTML Coding
echo '<div id = "div">';
echo 'Input Harvest Rate';
echo '<form action = "newfish.php" method = "post">';
echo '<input type="text" name="harvest" id="harvest">';
echo '<input type = "submit" value="Submit" id="submit">';
echo '</form>';
echo "Stock equals" . " " . floor($stock) . "</br>";
echo '</div>';
echo '</html>';
echo "You've taken " . $turns . " turns</br>";
echo "You've harvested " . $harvestX . " total fish.";
}elseif($stock <= 0){
echo '</html>' . "Your fish population crashed.";
die;
}
?>Code: Select all
<?php
global $stock;
global $turns;
//global $harvestCount;
$harvestCount = $_POST['harvest'];
echo '<!DOCTYPE HTML>';
session_start();
$stock = $_SESSION['stock'];
$turns = $_SESSION['turns'];
$harvestX = $_SESSION['totalH'];
echo "Last stock was " . floor($_SESSION['stock']) . "</br>";
function Birth(){
global $stock;
$birthCount = $stock * abs(((rand(0,10))/10)+(rand(0,10)/10));
if($birthCount > 0){
$stock += $birthCount;
$_SESSION['birthCount'] = floor($birthCount);
echo floor($birthCount) . " " . "fish born!</br>";
echo floor($stock) . " " . "fish are now in population</br>";
}
return $stock;
}
function Death(){
global $stock;
$deathCount = $stock * abs(((rand(0,10))/10)-(rand(0,10)/10));
if($deathCount > 0){
$stock -= $deathCount;
$_SESSION['deathCount'] = floor($deathCount);
echo floor($deathCount) . " " . "fish died...</br>";
echo floor($stock) . " " . "fish remain after death cycle</br>";
}
return $stock;
}
function Harvest(){
global $stock;
global $harvestCount;
global $harvestX;
$harvestX = $harvestX + $harvestCount;
if($harvestCount > 0){
$stock -= $harvestCount;
echo floor($harvestCount) . " " . "fish harvested.</br>";
echo floor($stock) . " " . "fish remain after harvesting.</br>";
}
return $stock;
}
if($stock > 0){
Birth();
Death();
Harvest();
$stock = $_SESSION['stock1'] = $stock;
$turns = $turns + 1;
$turns = $_SESSION['turns1'] = $turns;
$harvestX = $_SESSION['totalH1'] = $harvestX;
if($harvestCount){
$harvestCount = 0;
}
// HTML Coding
echo '<div id = "div">';
echo 'Input Harvest Rate';
echo '<form action = "newfish1.php" method = "post">';
echo '<input type="text" name="harvest" id="harvest">';
echo '<input type = "submit" value="Submit" id="submit">';
echo '</form>';
echo "Stock equals" . " " . floor($stock) . "</br>";
echo '</div>';
echo '</html>';
echo "You've taken " . $turns . " turns</br>";
echo "You've harvested " . $harvestX . " total fish.";
}elseif($stock <= 0){
echo '</html>' . "Your fish population crashed.";
die;
}
?>