diff options
author | Arun Persaud <arun@nubati.net> | 2009-01-15 19:14:17 -0800 |
---|---|---|
committer | Arun Persaud <arun@nubati.net> | 2009-01-15 19:29:28 -0800 |
commit | 8114e8920b56b4f078d2b3ff8d283cdf4d18c679 (patch) | |
tree | 371a36593350f8caa08ccad1cf71d9ec0296db5e /include/output.php | |
parent | c3f011c01dbab0d02321859a03d91dc88a7b560b (diff) | |
download | e-DoKo-8114e8920b56b4f078d2b3ff8d283cdf4d18c679.tar.gz e-DoKo-8114e8920b56b4f078d2b3ff8d283cdf4d18c679.tar.bz2 e-DoKo-8114e8920b56b4f078d2b3ff8d283cdf4d18c679.zip |
BUGFIX: better default for selecting players in a new game
the player is now automatically on pos 4 and the other positions are filled randomly. Also make sure that no player shows up more than once.
Diffstat (limited to 'include/output.php')
-rw-r--r-- | include/output.php | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/include/output.php b/include/output.php index f694c5b..9564b82 100644 --- a/include/output.php +++ b/include/output.php @@ -28,6 +28,10 @@ function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid) function output_form_for_new_game($names) { + $copy_names = $names; /* local copy, so that we can delete names from it + * after we selected them to make sure that each name + * only shows up once + */ ?> <form action="index.php?action=new" method="post"> <h2> Select players (Remember: you need to be one of the players) </h2> @@ -35,13 +39,27 @@ function output_form_for_new_game($names) <div class="table"> <img class="table" src="pics/table.png" alt="table" /> <?php - /* ask for player names */ - $i=0; + /* ask for player names */ + $i=0; + /* delete players name, since he will be on position D anyway */ + unset($copy_names[array_search($_SESSION["name"],$copy_names)]); + + srand((float) microtime() * 10000000); foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player) { - srand((float) microtime() * 10000000); - $randkey = array_rand($names); - $rand = $names[$randkey]; + /* pick 3 names at random and put the players name on position D*/ + if($i<3) + { + $randkey = array_rand($copy_names); + $rand = $copy_names[$randkey]; + /* delete this name from the list of possible names */ + unset($copy_names[$randkey]); + } + else + { + $rand = $_SESSION["name"]; + } + echo " <div class=\"table".$i."\">\n"; $i++; echo " <select name=\"$player\" size=\"1\"> \n"; |