当前位置: 首页>>代码示例>>PHP>>正文


PHP Game::pick_move方法代码示例

本文整理汇总了PHP中Game::pick_move方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::pick_move方法的具体用法?PHP Game::pick_move怎么用?PHP Game::pick_move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game的用法示例。


在下文中一共展示了Game::pick_move方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Game

    <head>
        <title>Hello COMP4711</title>
    </head>
    <body>
        <?php 
$game = new Game($_GET['board']);
// $game->display();
if ($game->winner('o')) {
    echo 'You win. Lucky guesses! ';
    echo '<a href="?board=---------">Replay?</a>';
} else {
    if ($game->is_draw()) {
        echo 'It\'s a draw! ';
        echo '<a href="?board=---------">Replay?</a>';
    } else {
        if ($game->pick_move()) {
            echo 'I win. Muahahahaha! ';
            echo '<a href="?board=---------">Replay?</a>';
        } else {
            if ($game->is_draw()) {
                echo 'It\'s a draw! ';
                echo '<a href="?board=---------">Replay?</a>';
            }
        }
    }
}
$game->display();
class Game
{
    var $position;
    function __construct($squares)
开发者ID:wrybri,项目名称:COMP4711_lab1,代码行数:31,代码来源:index.php

示例2: winner

// check if the board is set
if (isset($_GET['board'])) {
    $position = $_GET['board'];
    $game = new Game($position);
    // check different states of the board
    if ($game->winner('x')) {
        $won = true;
        echo 'You win. Lucky guesses!';
    } else {
        if ($game->winner('o')) {
            $won = true;
            echo 'I win. Muahahahaha';
        } else {
            $won = false;
            echo 'No winner yet, but you are losing.';
            $game->pick_move();
            // no winner so the computer is picking a move
        }
    }
    $game->display();
}
class Game
{
    var $position;
    function __construct($squares)
    {
        $this->position = str_split($squares);
    }
    public function winner($token)
    {
        //check if there is a win
开发者ID:jessicasaini,项目名称:COMP4711_Lab1,代码行数:31,代码来源:index.php

示例3: Game

// start new game if no board given, else continue from board state
if (isset($_GET['board'])) {
    $squares = $_GET['board'];
} else {
    $squares = '---------';
}
$game = new Game($squares);
// assumed player is o and AI is x
if ($game->winner('o')) {
    echo "You win. Lucky guesses!";
} else {
    if ($game->winner('x')) {
        echo "I win. Muahahahaha";
    } else {
        // pick_move returns board state after AI makes its move
        $squares = $game->pick_move();
        $game = new Game($squares);
        if ($game->winner('x')) {
            echo "I win. Muahahahaha";
        }
    }
}
$game->display();
?>
    </body>
</html>
<?php 
class Game
{
    var $position;
    // couldn't figure out how to overload constructors
开发者ID:codylin,项目名称:ACIT4850Lab1,代码行数:31,代码来源:index.php

示例4: Game

$numbers = [0, 0, 0, 0, 0, 0, 0, 0];
//set up an initlal board convertered to numbers.
for ($i = 0; $i < 9; $i++) {
    if ($squares[$i] == 'x') {
        $numbers[$i] = 1;
    } else {
        if ($squares[$i] == 'o') {
            $numbers[$i] = '3';
        } else {
            $numbers[$i] = 0;
        }
    }
    //otherwise put 0
}
$game = new Game($squares);
$squares[$game->pick_move($numbers)] = 'o';
//make the AI play
$game = new Game($squares);
$game->display();
if ($game->winner('x', $squares)) {
    echo 'You win.';
} else {
    if ($game->winner('o', $squares)) {
        echo 'I win.';
    } else {
        echo 'No winner yet.';
    }
}
?>
    </body>
</html>
开发者ID:bluewave41,项目名称:4711-Lab-1-PHP,代码行数:31,代码来源:index.php

示例5: Game

<?php 
$squares = $_GET['board'];
$game = new Game($squares);
echo '<h1>Tic Tac Toe</h1>';
echo '<h3>World Championship Simulator</h3>';
echo "<h4>You are 'x'</h4>";
if ($game->is_empty()) {
    echo 'You have the first move.';
} else {
    if ($game->winner('x')) {
        echo 'You win. Lucky guesses!';
    } else {
        if ($game->winner('o')) {
            echo 'I win. Muahahaaa';
        } else {
            if ($game->pick_move() && $game->winner('o')) {
                echo 'I win. Muahahahaha';
            } else {
                if ($game->is_full()) {
                    echo "Game over. It's a tie this time....";
                } else {
                    echo 'So far so good. Your move, if you dare...';
                }
            }
        }
    }
}
$game->display();
echo '<br/>';
echo '<a href="./?board=---------">New Game</a>';
// 0 1 2
开发者ID:JoePelz,项目名称:BCIT4711Lab1,代码行数:31,代码来源:index.php

示例6: Game

echo "<h1>You are player " . $player . "</h1>";
if (isset($_GET['board'])) {
    $position = $_GET['board'];
} else {
    $position = "---------";
}
$game = new Game($position);
$game->display();
if ($game->winner('x')) {
    echo "X wins";
} else {
    if ($game->winner('o')) {
        echo "O wins";
    } else {
        echo "No winner yet. ";
        echo $game->pick_move($player);
    }
}
?>
        <h1><a href="?board=---------&player=o">Start a new game!</a></h1>
    </body>
</html>


<?php 
//Game class, handles all the game functions
class Game
{
    var $position;
    //Constructor requires the squares of the game in the format of a string
    //being either dashes or x/o
开发者ID:labsquid,项目名称:A4850-Lab01,代码行数:31,代码来源:index.php

示例7: Game

    <title>Tic-Tac-Toe</title>
    <link rel="stylesheet" type="text/css" href="Styles/style.css">
  </head>
  <body>
    <h1>Tic-Tac-Toe Game</h1>
    <?php 
if (!isset($_GET['board'])) {
    $squares = '---------';
} else {
    $squares = $_GET['board'];
}
$game = new Game($squares);
if ($squares == '---------') {
    $game->display();
} else {
    if ($game->pick_move() == -1) {
        echo '<div class="msg">A Tie!</div>';
    } else {
        if ($game->winner('x')) {
            echo '<div class="msg">You win!</div>';
        } else {
            if ($game->winner('o')) {
                echo '<div class="msg">I win!</div>';
            } else {
                $game->display();
            }
        }
    }
}
?>
    <br />
开发者ID:josephtam,项目名称:COMP4711,代码行数:31,代码来源:index.php


注:本文中的Game::pick_move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。