Advertisement
kajacx

opraveno

May 14th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. class Hledani {
  5.   private $trefa;
  6.   private $vedle;
  7.   private $prachy;
  8.   private $sance;
  9.  
  10.   public function __construct() {
  11.     $this->trefa = 0;
  12.     $this->vedle = 0;
  13.     $this->prachy = 1000;
  14.     $this->sance = 33;
  15.   }
  16.  
  17.   public function zkuz_to($castka) {
  18.     $vyhra = rand(1, 100) < $this->sance;
  19.     if($vyhra) {
  20.       $this->trefa++;
  21.       $this->sance--;
  22.       $this->prachy += $castka * 2;
  23.       $text = "Uhodli jste<br/>\n";
  24.     }
  25.     else {
  26.       $this->vedle++;
  27.       $this->sance++;
  28.       $this->prachy -= $castka;
  29.       $text = "Smula<br/>\n";
  30.     }
  31.     $text .= "dobre: " . $this->trefa . "<br/>\n";
  32.     $text .= "spatne: " . $this->vedle . "<br/>\n";
  33.     $text .= "vase penize: " . $this->prachy;
  34.     return $text;
  35.   }
  36.  
  37. }
  38.  
  39. if(isset($_GET["reset"])) {
  40.   unset($_SESSION["kulicky"]);
  41. }
  42.  
  43. if(isset($_SESSION["kulicky"])) {
  44.   $hra = unserialize($_SESSION["kulicky"]);
  45. }
  46. else {
  47.   $hra = new Hledani();
  48.   echo "mate 1000 penez";
  49. }
  50.  
  51. if(isset($_GET["hadej"])) {
  52.   echo $hra->zkuz_to($_GET["sazka"]);
  53.  
  54. }
  55. ?>
  56. <br/>
  57. <form action="hledani_kulicky.php" method="get">
  58.   Vase sazka: <input name="sazka"><br/>
  59.  
  60.   <input type="submit" name="hadej" value="Tady jsem">
  61.   <input type="submit" name="hadej" value="Ne, tady">
  62.   <input type="submit" name="hadej" value="Nene, tady!">
  63.   <br/>
  64.   <input type="submit" name="reset" value="Reset">
  65. </form>
  66.  
  67.  
  68. <?php
  69. $_SESSION["kulicky"] = serialize($hra);
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement