fork download
  1. <?php
  2. header("Content-Type: text/plain; charset=utf-8");
  3. ?>
  4.  
  5. <?php
  6. class Player
  7. {
  8. public $name;
  9. public $icon;
  10. public $x;
  11. public $y;
  12. public $isWinner;
  13. public function __construct($name, $icon)
  14. {
  15. $this->name = $name;
  16. $this->icon = $icon;
  17. $this->x = 1;
  18. $this->y = 0;
  19. }
  20. public function getMove()
  21. {
  22. $roll = mt_rand(1, 6);
  23. $lastX = $this->x;
  24. $lastY = $this->y;
  25. $this->x = $this->x + $roll;
  26. $position = $this->y * 10 + $this->x;
  27. echo "Rolling the dice for $this->name: $roll \n";
  28. if ($position < 100) {
  29.  
  30. $length = 10 - $lastX;
  31.  
  32. if ($length < $roll) {
  33. $roll = $roll - $length;
  34. $this->x = 0;
  35. $this->y = $this->y + 1;
  36. }
  37. if (100 - $position < $roll) {
  38. $position = 100;
  39. }
  40. switch ($position) {
  41. case 4:
  42. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  43. $this->x = 2;
  44. $this->y = 4;
  45. break;
  46. case 16:
  47. $this->x = 8;
  48. $this->y = 0;
  49. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  50. break;
  51. case 9:
  52. $this->x = 10;
  53. $this->y = 3;
  54. echo "Congratulation: $this->name new position is $this->y0 \n";
  55. break;
  56. case 32:
  57. $this->x = 2;
  58. $this->y = 1;
  59. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  60. break;
  61. case 14:
  62. $this->x = 7;
  63. $this->y = 7;
  64. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  65. break;
  66. case 62:
  67. $this->x = 9;
  68. $this->y = 1;
  69. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  70. break;
  71. case 80:
  72. $this->x = 8;
  73. $this->y = 9;
  74. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  75. break;
  76. case 96:
  77. $this->x = 6;
  78. $this->y = 7;
  79. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  80. break;
  81. case 71:
  82. $this->x = 7;
  83. $this->y = 6;
  84. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  85. break;
  86. case 48:
  87. $this->x = 3;
  88. $this->y = 7;
  89. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  90. break;
  91. case 37:
  92. $this->x = 8;
  93. $this->y = 5;
  94. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  95. break;
  96. case 47:
  97. $this->x = 6;
  98. $this->y = 2;
  99. echo "Sorry, but $this->name new position is $this->y$this->x \n";
  100. break;
  101. case 70:
  102. $this->x = 9;
  103. $this->y = 8;
  104. echo "Congratulation: $this->name new position is $this->y$this->x \n";
  105. break;
  106. default:
  107. echo "$this->name new position is $position \n";
  108. }
  109. } else {
  110. echo "CONGRATULATION: $this->name - THE WINNER!!!";
  111. return $this->isWinner = 1;
  112. }
  113.  
  114. }
  115.  
  116. }
  117. $player1 = new Player('Player1', '@');
  118. $player2 = new Player('Player2', '#');
  119. $player3 = new Player('Player3', '$');
  120. $player4 = new Player('Player4', '%');
  121.  
  122. $players = array(
  123. $player1,
  124. $player2,
  125. $player3,
  126. $player4
  127. );
  128.  
  129. function getGame($array)
  130. {
  131. while ($player->isWinner == 0) {
  132.  
  133. foreach ($array as $player) {
  134. if ($player->isWinner == 0) {
  135. $player->getMove();
  136. } elseif ($player->isWinner == 1) {
  137. return $player->name;
  138. break;
  139. }
  140.  
  141. }
  142. }
  143.  
  144. }
  145. getGame($players);
  146. function getShow()
  147. {
  148. $zone = array();
  149. $line = array();
  150. $x = 0;
  151. for ($i = 1; $i <= 10; $i++) {
  152. foreach (range($x * 10 + 1, $x * 10 + 10) as $point) {
  153. $line[] = $point;
  154. }
  155. $zone[] = $line;
  156. unset($line);
  157. $x++;
  158. }
  159. return $zone;
  160. }
  161. print_r(getShow());
  162.  
  163.  
  164.  
  165.  
  166.  
Success #stdin #stdout #stderr 0.02s 20568KB
stdin
Standard input is empty
stdout
Rolling the dice for Player1: 2 
Player1 new position is 3 
Rolling the dice for Player2: 2 
Player2 new position is 3 
Rolling the dice for Player3: 2 
Player3 new position is 3 
Rolling the dice for Player4: 5 
Player4 new position is 6 
Rolling the dice for Player1: 2 
Player1 new position is 5 
Rolling the dice for Player2: 2 
Player2 new position is 5 
Rolling the dice for Player3: 1 
Congratulation: Player3 new position is 04 
Rolling the dice for Player4: 4 
Player4 new position is 10 
Rolling the dice for Player1: 2 
Player1 new position is 7 
Rolling the dice for Player2: 6 
Player2 new position is 11 
Rolling the dice for Player3: 1 
Player3 new position is 43 
Rolling the dice for Player4: 1 
Player4 new position is 11 
Rolling the dice for Player1: 1 
Player1 new position is 8 
Rolling the dice for Player2: 6 
Sorry, but Player2 new position is 08 
Rolling the dice for Player3: 5 
Congratulation: Player3 new position is 73 
Rolling the dice for Player4: 2 
Player4 new position is 12 
Rolling the dice for Player1: 2 
Player1 new position is 10 
Rolling the dice for Player2: 2 
Player2 new position is 10 
Rolling the dice for Player3: 1 
Player3 new position is 74 
Rolling the dice for Player4: 2 
Congratulation: Player4 new position is 77 
Rolling the dice for Player1: 3 
Player1 new position is 13 
Rolling the dice for Player2: 4 
Congratulation: Player2 new position is 77 
Rolling the dice for Player3: 3 
Player3 new position is 77 
Rolling the dice for Player4: 3 
Congratulation: Player4 new position is 98 
Rolling the dice for Player1: 6 
Sorry, but Player1 new position is 08 
Rolling the dice for Player2: 6 
Player2 new position is 83 
Rolling the dice for Player3: 4 
Player3 new position is 81 
Rolling the dice for Player4: 4 
CONGRATULATION: Player4 - THE WINNER!!!Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
            [4] => 5
            [5] => 6
            [6] => 7
            [7] => 8
            [8] => 9
            [9] => 10
        )

    [1] => Array
        (
            [0] => 11
            [1] => 12
            [2] => 13
            [3] => 14
            [4] => 15
            [5] => 16
            [6] => 17
            [7] => 18
            [8] => 19
            [9] => 20
        )

    [2] => Array
        (
            [0] => 21
            [1] => 22
            [2] => 23
            [3] => 24
            [4] => 25
            [5] => 26
            [6] => 27
            [7] => 28
            [8] => 29
            [9] => 30
        )

    [3] => Array
        (
            [0] => 31
            [1] => 32
            [2] => 33
            [3] => 34
            [4] => 35
            [5] => 36
            [6] => 37
            [7] => 38
            [8] => 39
            [9] => 40
        )

    [4] => Array
        (
            [0] => 41
            [1] => 42
            [2] => 43
            [3] => 44
            [4] => 45
            [5] => 46
            [6] => 47
            [7] => 48
            [8] => 49
            [9] => 50
        )

    [5] => Array
        (
            [0] => 51
            [1] => 52
            [2] => 53
            [3] => 54
            [4] => 55
            [5] => 56
            [6] => 57
            [7] => 58
            [8] => 59
            [9] => 60
        )

    [6] => Array
        (
            [0] => 61
            [1] => 62
            [2] => 63
            [3] => 64
            [4] => 65
            [5] => 66
            [6] => 67
            [7] => 68
            [8] => 69
            [9] => 70
        )

    [7] => Array
        (
            [0] => 71
            [1] => 72
            [2] => 73
            [3] => 74
            [4] => 75
            [5] => 76
            [6] => 77
            [7] => 78
            [8] => 79
            [9] => 80
        )

    [8] => Array
        (
            [0] => 81
            [1] => 82
            [2] => 83
            [3] => 84
            [4] => 85
            [5] => 86
            [6] => 87
            [7] => 88
            [8] => 89
            [9] => 90
        )

    [9] => Array
        (
            [0] => 91
            [1] => 92
            [2] => 93
            [3] => 94
            [4] => 95
            [5] => 96
            [6] => 97
            [7] => 98
            [8] => 99
            [9] => 100
        )

)
stderr
PHP Notice:  Undefined variable: player in /home/tqO7cS/prog.php on line 132
PHP Notice:  Trying to get property of non-object in /home/tqO7cS/prog.php on line 132