-
-
Save s3gfau1t/7013550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$velocities = array("turtle", "donkey", "rabbit"); | |
$players = array( | |
'1' => array( | |
'name' => 'Foo', | |
'velocity' => $velocities[rand(0,2)]), | |
'actions' => array(), | |
'2' => array( | |
'name' => 'Bar', | |
'velocity' => $velocities[rand(0,2)]), | |
'actions' => array(), | |
); | |
echo "(player 1) {$players['1']['name']} :: will go as fast as a {$players['1']['velocity']}\r\n"; | |
echo "(player 2) {$players['2']['name']} :: will go as fast as a {$players['2']['velocity']}\r\n"; | |
$actionsFunc = function(){ | |
return array( | |
array('action' => 'stumbles', 'distance' => 0 ), | |
array('action' => 'leaps', 'distance' => rand(1,3) ), | |
array('action' => 'strides', 'distance' => rand(1,3) ), | |
array('action' => 'sprints', 'distance' => rand(1,5) ), | |
array('action' => 'falls', 'distance' => 0 ), | |
array('action' => 'shuffles', 'distance' => rand(1,2) ), | |
array('action' => 'walks', 'distance' => rand(0,2) ), | |
array('action' => 'runs', 'distance' => rand(0,2) ), | |
array('action' => 'skips', 'distance' => rand(0,2) ), | |
array('action' => 'gasps', 'distance' => 0 ), | |
array('action' => 'cavorts', 'distance' => rand(1,3) ), | |
array('action' => 'dances', 'distance' => rand(1,3) ), | |
array('action' => 'pauses', 'distance' => 0 ), | |
array('action' => 'zips', 'distance' => rand(1,5) ), | |
array('action' => 'zooms', 'distance' => rand(1,5) ), | |
array('action' => 'collapses', 'distance' => 0 ), | |
array('action' => 'faceplants', 'distance' => 0 ), | |
); | |
}; | |
$track_length = rand(50, 1000); | |
$playerDistance = | |
function($player){ | |
$distance = 0; | |
foreach($player['actions'] as $action) | |
$distance += $action['distance']; | |
return $distance; | |
}; | |
$raceEnded = | |
function($players){ | |
$p1_distance = $playerDistance($players[0]); | |
$p2_distance = $playerDistance($players[1]); | |
if( $p1_distance >= $track_length && $p2_distance >= $track_length ) return true; | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment