Designing solutions through programming - June 1 Lesson Notes: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with " __NOTOC__ <table cellspacing="10" style="width:100%;"> <tr> <td style="width:50%; margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1...") |
Mr. MacKenty (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 9: | Line 9: | ||
session_start(); | session_start(); | ||
function monster($current_player_location, $current_monster_location,$ | function monster($current_player_location, $current_monster_location,$destination) { | ||
echo "player is: $current_player_location Monster is: $ | echo "player is: $current_player_location Monster is: $current_monster_location <br />"; | ||
if($destination == $current_monster_location){ | if($destination == $current_monster_location){ | ||
echo "from function: MONSTER!!! <br />"; | echo "from function: MONSTER!!! <br />"; | ||
} | } | ||
Line 20: | Line 20: | ||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$current_player_location = $_SESSION['current_player_location']; | $current_player_location = $_SESSION['current_player_location']; | ||
$current_monster_location = $_SESSION['current_monster_location']; | $current_monster_location = $_SESSION['current_monster_location']; | ||
$grid = $_SESSION['grid']; | $grid = $_SESSION['grid']; | ||
$move = $_POST['move']; | $move = $_POST['move']; | ||
if($move == 'W' || $move == 'w'){ | if($move == 'W' || $move == 'w'){ | ||
monster($current_player_location,$current_monster_location,($current_player_location-1)); | |||
if($current_player_location==50){ $grid[50]=1; } | |||
$grid[$current_player_location] = $_SESSION['terrain_in_destination']; | |||
$terrain_in_destination = $grid[($current_player_location-1)]; | |||
$_SESSION['terrain_in_destination'] = $terrain_in_destination; | |||
$grid[($current_player_location-1)] = 4; | |||
} elseif($move == 'E' || $move == 'e'){ | } elseif($move == 'E' || $move == 'e'){ | ||
monster($current_player_location,$current_monster_location,($current_player_location+1)); | |||
if($current_player_location==50){ $grid[50]=1; } | |||
$grid[$current_player_location] = $_SESSION['terrain_in_destination']; | |||
$terrain_in_destination = $grid[($current_player_location+1)]; | |||
$_SESSION['terrain_in_destination'] = $terrain_in_destination; | |||
$grid[($current_player_location+1)] = 4; | |||
} elseif($move == 'N' || $move == 'n'){ | } elseif($move == 'N' || $move == 'n'){ | ||
monster($current_player_location,$current_monster_location,($current_player_location-20)); | |||
if($current_player_location==50){ $grid[50]=1; } | |||
$grid[$current_player_location] = $_SESSION['terrain_in_destination']; | |||
$terrain_in_destination = $grid[($current_player_location-20)]; | |||
$_SESSION['terrain_in_destination'] = $terrain_in_destination; | |||
$grid[($current_player_location-20)] = 4; | |||
} elseif($move == 'S' || $move == 's'){ | } elseif($move == 'S' || $move == 's'){ | ||
monster($current_player_location,$current_monster_location,($current_player_location+20)); | |||
if($current_player_location==50){ $grid[50]=1; } | |||
$grid[$current_player_location] = $_SESSION['terrain_in_destination']; | |||
$terrain_in_destination = $grid[($current_player_location+20)]; | |||
$_SESSION['terrain_in_destination'] = $terrain_in_destination; | |||
$grid[($current_player_location+20)] = 4; | |||
} | } | ||
} else { | } else { | ||
Line 77: | Line 80: | ||
$grid[123]=5; | $grid[123]=5; | ||
} // this ends the ISPOST | } // this ends the ISPOST | ||
// print the array so it looks like a grid | // print the array so it looks like a grid | ||
Line 118: | Line 121: | ||
echo "<br /><hr /><br />"; | echo "<br /><hr /><br />"; | ||
echo "The player is currently at position: $current_player_location <br />"; | echo "The player is currently at position: $current_player_location <br />"; | ||
echo "The monster is currently at position: $current_monster_location <br /> | echo "The monster is currently at position: $current_monster_location <br />"; | ||
echo "<br /><hr /><br />"; | echo "<br /><hr /><br />"; | ||
// print_r($count_terrain_features); | // print_r($count_terrain_features); |
Latest revision as of 09:25, 1 June 2017
|
|
|
|
||
|
|
|
|