login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Spellen > Rock, paper, scissors

Rock, paper, scissors

Auteur: GTW - 21 mei 2006 - 09:41 - Gekeurd door: nemesiskoen - Hits: 7380 - Aantal punten: 3.46 (14 stemmen)




Je maakt het bestand aan, zet het online, en je kunt spelen.
zo simpel is het.
je kunt het bestand noemen zoals je wilt, omdat je wordt terugverwezen naar de referer, oftewel, de hoofdpagina van dit script

Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Rock, Paper, scissors</title>
  6. </head>
  7.  
  8. <body>
  9. <center>
  10. <?php
  11. if(isset($_POST['submit'])){
  12.  
  13. $actions = array("paper", "rock", "scissors");
  14. $mogelijkheden = array("paper" => 1, "rock" => 2, "scissors" => 4);
  15.  
  16. $speler = $mogelijkheden[$_POST['rps']];
  17.  
  18. $c = $actions[rand(0,2)];
  19. $comp = $mogelijkheden[$c];
  20.  
  21. $gewonnen = ((($speler > $comp && $comp / $speler != 0.5) || $speler / $comp == 0.5) && $comp != $speler);
  22.  
  23.  
  24. if($gewonnen){
  25. ?>
  26. <font color="green">
  27. Je hebt gewonnen!<br />
  28. Gefeliciteerd
  29. </font>
  30. <?php
  31. }
  32. elseif($speler == $comp){
  33. ?>
  34. Jullie hadden dezelfde actie,<br />
  35. Gelijkspel
  36. <?php
  37. }
  38. else{
  39. ?>
  40. <font color="red">Je hebt verloren!</font>
  41. <?php
  42. }
  43.  
  44. ?>
  45. <br /><br />
  46. <table>
  47. <tr>
  48. <td width="50%">Jouw actie:</td>
  49. <td><?=ucfirst($_POST['rps']); ?></td>
  50. </tr>
  51. <tr>
  52. <td>Pc actie:</td>
  53. <td><?=ucfirst($c); ?></td>
  54. </tr>
  55. </table>
  56. <br /><br />
  57. <a href="<?=$_SERVER['HTTP_REFERER']; ?>">Begin opnieuw</a>
  58. <?php
  59. exit();
  60. }
  61. ?>
  62. Welkom bij Rock, paper, scissors<br />
  63. <br />
  64. <table>
  65. <form name="rps" action="?action" method="post">
  66. <tr>
  67. <td><input type="radio" name="rps" value="paper" /></td>
  68. <td align="left">Paper</td>
  69. </tr>
  70. <tr>
  71. <td width="50%"><input type="radio" name="rps" value="rock" /></td>
  72. <td align="left">Rock</td>
  73. </tr>
  74. <tr>
  75. <td><input type="radio" name="rps" value="scissors" /></td>
  76. <td align="left"><label for="scissors">Scissors</label></td>
  77. </tr>
  78. <tr>
  79. <td colspan="2"><input type="submit" name="submit" value="Strijd" /></td>
  80. </tr>
  81. </form>
  82. </table>
  83. </center>
  84. </body>
  85. </html>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (10)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.027s