<?php
header("Content-Type: text/plain; charset=utf-8");
?>

<?php
mb_internal_encoding("UTF-8");
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()
    {
        $roll     = mt_rand(1, 6);
        $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', '%');

$players = array(
    $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()
{
    $zone = array();
    $line = array();
    $x    = 0;
    for ($i = 1; $i <= 10; $i++) {
        foreach (range($x * 10 + 1, $x * 10 + 10) as $point) {
            $line[] = $point;
        }
        $zone[] = $line;
        unset($line);
        $x++;
    }
    return $zone;
}
print_r(getShow());




