<?php
header ( "Content-Type: text/plain; charset=utf-8" ) ; ?>
<?php
class Player
{
public $name ;
public $icon ;
public $x ;
public $y ;
public $isWinner ;
public function __construct( $name , $icon )
{
$this -> name = $name ;
$this -> icon = $icon ;
$this -> x = 1 ;
$this -> y = 0 ;
}
public function getMove( )
{
$lastX = $this -> x ;
$lastY = $this -> y ;
$this -> x = $this -> x + $roll ;
$position = $this -> y * 10 + $this -> x ;
echo "Rolling the dice for $this->name : $roll \n " ;
if ( $position < 100 ) {
$length = 10 - $lastX ;
if ( $length < $roll ) {
$roll = $roll - $length ;
$this -> x = 0 ;
$this -> y = $this -> y + 1 ;
}
if ( 100 - $position < $roll ) {
$position = 100 ;
}
switch ( $position ) {
case 4 :
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
$this -> x = 2 ;
$this -> y = 4 ;
break ;
case 16 :
$this -> x = 8 ;
$this -> y = 0 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 9 :
$this -> x = 10 ;
$this -> y = 3 ;
echo "Congratulation: $this->name new position is $this->y0 \n " ;
break ;
case 32 :
$this -> x = 2 ;
$this -> y = 1 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 14 :
$this -> x = 7 ;
$this -> y = 7 ;
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
break ;
case 62 :
$this -> x = 9 ;
$this -> y = 1 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 80 :
$this -> x = 8 ;
$this -> y = 9 ;
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
break ;
case 96 :
$this -> x = 6 ;
$this -> y = 7 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 71 :
$this -> x = 7 ;
$this -> y = 6 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 48 :
$this -> x = 3 ;
$this -> y = 7 ;
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
break ;
case 37 :
$this -> x = 8 ;
$this -> y = 5 ;
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
break ;
case 47 :
$this -> x = 6 ;
$this -> y = 2 ;
echo "Sorry, but $this->name new position is $this->y $this->x \n " ;
break ;
case 70 :
$this -> x = 9 ;
$this -> y = 8 ;
echo "Congratulation: $this->name new position is $this->y $this->x \n " ;
break ;
default :
echo "$this->name new position is $position \n " ;
}
} else {
echo "CONGRATULATION: $this->name - THE WINNER!!!" ;
return $this -> isWinner = 1 ;
}
}
}
$player1 = new Player( 'Player1' , '@' ) ;
$player2 = new Player( 'Player2' , '#' ) ;
$player3 = new Player( 'Player3' , '$' ) ;
$player4 = new Player( 'Player4' , '%' ) ;
$player1 ,
$player2 ,
$player3 ,
$player4
) ;
function getGame( $array )
{
while ( $player -> isWinner == 0 ) {
foreach ( $array as $player ) {
if ( $player -> isWinner == 0 ) {
$player -> getMove ( ) ;
} elseif ( $player -> isWinner == 1 ) {
return $player -> name ;
break ;
}
}
}
}
getGame( $players ) ;
function getShow( )
{
$x = 0 ;
for ( $i = 1 ; $i <= 10 ; $i ++ ) {
foreach ( range ( $x * 10 + 1 , $x * 10 + 10 ) as $point ) { $line [ ] = $point ;
}
$zone [ ] = $line ;
$x ++;
}
return $zone ;
}
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKPz4KCjw/cGhwCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwpjbGFzcyBQbGF5ZXIKewogICAgcHVibGljICRuYW1lOwogICAgcHVibGljICRpY29uOwogICAgcHVibGljICR4OwogICAgcHVibGljICR5OwogICAgcHVibGljICRpc1dpbm5lcjsKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkbmFtZSwgJGljb24pCiAgICB7CiAgICAgICAgJHRoaXMtPm5hbWUgPSAkbmFtZTsKICAgICAgICAkdGhpcy0+aWNvbiA9ICRpY29uOwogICAgICAgICR0aGlzLT54ICAgID0gMTsKICAgICAgICAkdGhpcy0+eSAgICA9IDA7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0TW92ZSgpCiAgICB7CiAgICAgICAgJHJvbGwgICAgID0gbXRfcmFuZCgxLCA2KTsKICAgICAgICAkbGFzdFggICAgPSAkdGhpcy0+eDsKICAgICAgICAkbGFzdFkgICAgPSAkdGhpcy0+eTsKICAgICAgICAkdGhpcy0+eCAgPSAkdGhpcy0+eCArICRyb2xsOwogICAgICAgICRwb3NpdGlvbiA9ICR0aGlzLT55ICogMTAgKyAkdGhpcy0+eDsKICAgICAgICBlY2hvICJSb2xsaW5nIHRoZSBkaWNlIGZvciAkdGhpcy0+bmFtZTogJHJvbGwgXG4iOwogICAgICAgIGlmICgkcG9zaXRpb24gPCAxMDApIHsKICAgICAgICAgICAgCiAgICAgICAgICAgICRsZW5ndGggPSAxMCAtICRsYXN0WDsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmICgkbGVuZ3RoIDwgJHJvbGwpIHsKICAgICAgICAgICAgICAgICRyb2xsICAgID0gJHJvbGwgLSAkbGVuZ3RoOwogICAgICAgICAgICAgICAgJHRoaXMtPnggPSAwOwogICAgICAgICAgICAgICAgJHRoaXMtPnkgPSAkdGhpcy0+eSArIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKDEwMCAtICRwb3NpdGlvbiA8ICRyb2xsKSB7CiAgICAgICAgICAgICAgICAkcG9zaXRpb24gPSAxMDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc3dpdGNoICgkcG9zaXRpb24pIHsKICAgICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgICAgICBlY2hvICJDb25ncmF0dWxhdGlvbjogJHRoaXMtPm5hbWUgbmV3IHBvc2l0aW9uIGlzICR0aGlzLT55JHRoaXMtPnggXG4iOwogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gMjsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDE2OgogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gODsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDA7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiU29ycnksIGJ1dCAkdGhpcy0+bmFtZSBuZXcgcG9zaXRpb24gaXMgJHRoaXMtPnkkdGhpcy0+eCBcbiI7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDk6CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnggPSAxMDsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDM7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiQ29uZ3JhdHVsYXRpb246ICR0aGlzLT5uYW1lIG5ldyBwb3NpdGlvbiBpcyAkdGhpcy0+eTAgXG4iOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAzMjoKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eCA9IDI7CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnkgPSAxOwogICAgICAgICAgICAgICAgICAgIGVjaG8gIlNvcnJ5LCBidXQgJHRoaXMtPm5hbWUgbmV3IHBvc2l0aW9uIGlzICR0aGlzLT55JHRoaXMtPnggXG4iOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAxNDoKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eCA9IDc7CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnkgPSA3OwogICAgICAgICAgICAgICAgICAgIGVjaG8gIkNvbmdyYXR1bGF0aW9uOiAkdGhpcy0+bmFtZSBuZXcgcG9zaXRpb24gaXMgJHRoaXMtPnkkdGhpcy0+eCBcbiI7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDYyOgogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gOTsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDE7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiU29ycnksIGJ1dCAkdGhpcy0+bmFtZSBuZXcgcG9zaXRpb24gaXMgJHRoaXMtPnkkdGhpcy0+eCBcbiI7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDgwOgogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gODsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDk7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiQ29uZ3JhdHVsYXRpb246ICR0aGlzLT5uYW1lIG5ldyBwb3NpdGlvbiBpcyAkdGhpcy0+eSR0aGlzLT54IFxuIjsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgOTY6CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnggPSA2OwogICAgICAgICAgICAgICAgICAgICR0aGlzLT55ID0gNzsKICAgICAgICAgICAgICAgICAgICBlY2hvICJTb3JyeSwgYnV0ICR0aGlzLT5uYW1lIG5ldyBwb3NpdGlvbiBpcyAkdGhpcy0+eSR0aGlzLT54IFxuIjsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgNzE6CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnggPSA3OwogICAgICAgICAgICAgICAgICAgICR0aGlzLT55ID0gNjsKICAgICAgICAgICAgICAgICAgICBlY2hvICJTb3JyeSwgYnV0ICR0aGlzLT5uYW1lIG5ldyBwb3NpdGlvbiBpcyAkdGhpcy0+eSR0aGlzLT54IFxuIjsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgNDg6CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnggPSAzOwogICAgICAgICAgICAgICAgICAgICR0aGlzLT55ID0gNzsKICAgICAgICAgICAgICAgICAgICBlY2hvICJDb25ncmF0dWxhdGlvbjogJHRoaXMtPm5hbWUgbmV3IHBvc2l0aW9uIGlzICR0aGlzLT55JHRoaXMtPnggXG4iOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAzNzoKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eCA9IDg7CiAgICAgICAgICAgICAgICAgICAgJHRoaXMtPnkgPSA1OwogICAgICAgICAgICAgICAgICAgIGVjaG8gIkNvbmdyYXR1bGF0aW9uOiAkdGhpcy0+bmFtZSBuZXcgcG9zaXRpb24gaXMgJHRoaXMtPnkkdGhpcy0+eCBcbiI7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDQ3OgogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gNjsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDI7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiU29ycnksIGJ1dCAkdGhpcy0+bmFtZSBuZXcgcG9zaXRpb24gaXMgJHRoaXMtPnkkdGhpcy0+eCBcbiI7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDcwOgogICAgICAgICAgICAgICAgICAgICR0aGlzLT54ID0gOTsKICAgICAgICAgICAgICAgICAgICAkdGhpcy0+eSA9IDg7CiAgICAgICAgICAgICAgICAgICAgZWNobyAiQ29uZ3JhdHVsYXRpb246ICR0aGlzLT5uYW1lIG5ldyBwb3NpdGlvbiBpcyAkdGhpcy0+eSR0aGlzLT54IFxuIjsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICAgICAgZWNobyAiJHRoaXMtPm5hbWUgbmV3IHBvc2l0aW9uIGlzICRwb3NpdGlvbiBcbiI7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBlY2hvICJDT05HUkFUVUxBVElPTjogJHRoaXMtPm5hbWUgLSBUSEUgV0lOTkVSISEhIjsKICAgICAgICAgICAgcmV0dXJuICR0aGlzLT5pc1dpbm5lciA9IDE7CiAgICAgICAgfQogICAgICAgIAogICAgfQogICAgCn0KJHBsYXllcjEgPSBuZXcgUGxheWVyKCdQbGF5ZXIxJywgJ0AnKTsKJHBsYXllcjIgPSBuZXcgUGxheWVyKCdQbGF5ZXIyJywgJyMnKTsKJHBsYXllcjMgPSBuZXcgUGxheWVyKCdQbGF5ZXIzJywgJyQnKTsKJHBsYXllcjQgPSBuZXcgUGxheWVyKCdQbGF5ZXI0JywgJyUnKTsKCiRwbGF5ZXJzID0gYXJyYXkoCiAgICAkcGxheWVyMSwKICAgICRwbGF5ZXIyLAogICAgJHBsYXllcjMsCiAgICAkcGxheWVyNAopOwoKZnVuY3Rpb24gZ2V0R2FtZSgkYXJyYXkpCnsKICAgIHdoaWxlICgkcGxheWVyLT5pc1dpbm5lciA9PSAwKSB7CiAgICAgICAgCiAgICAgICAgZm9yZWFjaCAoJGFycmF5IGFzICRwbGF5ZXIpIHsKICAgICAgICAgICAgaWYgKCRwbGF5ZXItPmlzV2lubmVyID09IDApIHsKICAgICAgICAgICAgICAgICRwbGF5ZXItPmdldE1vdmUoKTsKICAgICAgICAgICAgfSBlbHNlaWYgKCRwbGF5ZXItPmlzV2lubmVyID09IDEpIHsKICAgICAgICAgICAgICAgIHJldHVybiAkcGxheWVyLT5uYW1lOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgfQogICAgfQogICAgCn0KZ2V0R2FtZSgkcGxheWVycyk7CmZ1bmN0aW9uIGdldFNob3coKQp7CiAgICAkem9uZSA9IGFycmF5KCk7CiAgICAkbGluZSA9IGFycmF5KCk7CiAgICAkeCAgICA9IDA7CiAgICBmb3IgKCRpID0gMTsgJGkgPD0gMTA7ICRpKyspIHsKICAgICAgICBmb3JlYWNoIChyYW5nZSgkeCAqIDEwICsgMSwgJHggKiAxMCArIDEwKSBhcyAkcG9pbnQpIHsKICAgICAgICAgICAgJGxpbmVbXSA9ICRwb2ludDsKICAgICAgICB9CiAgICAgICAgJHpvbmVbXSA9ICRsaW5lOwogICAgICAgIHVuc2V0KCRsaW5lKTsKICAgICAgICAkeCsrOwogICAgfQogICAgcmV0dXJuICR6b25lOwp9CnByaW50X3IoZ2V0U2hvdygpKTsKCgoKCg==
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