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


PHP Game::winner方法代码示例

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


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

示例1: Game

<!DOCTYPE html>
<html>
<head>
    <meta http-equip="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
</head>
    <body>
    <?php 
/* Sets the game board if unavailable */
$game = new Game(!isset($_GET['board']) ? '---------' : $_GET['board']);
if ($game->winner('x')) {
    echo 'x wins';
} else {
    if ($game->winner('o')) {
        echo 'o wins';
    } else {
        $game->pick_move();
        echo $game->winner('o') ? 'o wins' : 'no winner';
    }
}
$game->display();
echo '<a href="index.php">play again</a>';
?>
    </body>
</html>

<?php 
class Game
{
    var $position;
    // an array that remembers the current game state of the board
开发者ID:rjgodia,项目名称:test,代码行数:31,代码来源:index.php

示例2: pick_move

    return '<td><a href="' . $link . '">-</a></td>';
}
function pick_move()
{
    for ($pos = 0; $pos <= 8; $pos++) {
        if ($this->position[$pos] == '-') {
            $this->position[$pos] = 'x';
        } else {
            echo 'Your Move, Buddy';
        }
    }
}
//Main Game Logic
$squares = $_GET['board'];
echo "Welcome to George, the evil Tic-Tac-Toe Game.";
if ($squares == null) {
    $squares = '---------';
}
$game = new Game($squares);
if ($game->winner('x')) {
    echo 'You win. Lucky guesses!';
} else {
    if ($game->winner('o')) {
        echo 'I win. Muahahahaha';
    } else {
        echo 'No winner yet, but you are losing.';
    }
}
?>
	</body>
</html>
开发者ID:tseng111,项目名称:4711,代码行数:31,代码来源:tictactoe.php

示例3: Game

 * Time: 10:06 AM
 */
//We check if our board was set
if (!isset($_GET['board'])) {
    //If it is not set then allow the player to start the game
    echo '<form action="index.php" method="GET" >';
    echo 'Tic Tac Toe!</br>';
    //We set our board to a blank board
    echo '<input type="hidden" name="board" value="---------">';
    echo '<input type="submit" value="Play">';
    echo '</form>';
} else {
    //Start a new game
    $game = new Game($_GET['board']);
    //Check if the computer wins
    if ($game->winner('x')) {
        echo 'Computer wins!';
        reset_board();
    } elseif ($game->winner('o')) {
        echo 'Player wins!';
        reset_board();
    } else {
        //If neither won let the computer take its turn
        $game->pick_move();
        //Check if the computer wins
        if ($game->winner('x')) {
            echo 'Computer wins!';
            reset_board();
        } else {
            $game->display();
        }
开发者ID:KChow23,项目名称:comp4711_lab1,代码行数:31,代码来源:index.php

示例4: Game

        $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>

<?php 
class Game
{
开发者ID:bluewave41,项目名称:4711-Lab-1-PHP,代码行数:31,代码来源:index.php

示例5: Game

<html lang="en-CA">
<head>
	<title>Tic Tac Toe</title>
	<link rel="stylesheet" href="TTT.css">
</head>
<body>
<?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...';
                }
            }
        }
开发者ID:JoePelz,项目名称:BCIT4711Lab1,代码行数:31,代码来源:index.php

示例6: Game

        if ($this->position[2] == $token && $this->position[4] == $token && $this->position[6] == $token) {
            return true;
        }
        // return false if game is not yet won
        return false;
    }
}
//gets board state if applicable
if (isset($_GET['board'])) {
    $board = $_GET['board'];
} else {
    $board = "---------";
}
$game = new Game($board);
$done = false;
if ($game->winner('X')) {
    echo 'You win. Lucky guesses!';
    $done = true;
} else {
    if ($game->winner('O')) {
        echo 'I win. Muahahahaha';
        $done = true;
    } else {
        echo 'No winner yet, but you are losing.';
    }
}
if (implode($game->position) != '---------') {
    $game->pick_move();
}
$game->display();
//displays restart option when game has been won
开发者ID:risatronic,项目名称:ACIT4850_Lab1,代码行数:31,代码来源:index.php

示例7: testPlayer1Won

 /**
  * @covers \Florin\TicTacToe\Game::winner
  */
 public function testPlayer1Won()
 {
     $grid = ['X', 'X', 'O', 'X', 'O', null, 'O', null, null];
     $game = new Game(self::getPlayersPositions($grid));
     $this->assertEquals(1, $game->winner());
 }
开发者ID:zendka,项目名称:TicTacToe-Old,代码行数:9,代码来源:GameTest.php

示例8: Game

                }
            }
            if ($result == 3) {
                $winner = true;
            }
        }
        //horizontal bottom left to top right
        if ($this->position[6] == $token && $this->position[4] == $token && $this->position[2] == $token) {
            $winner = true;
        } else {
            if ($this->position[0] == $token && $this->position[4] == $token && $this->position[8] == $token) {
                $winner = true;
            } else {
                $winner = false;
            }
        }
        return $winner;
    }
}
$position = $_GET['board'];
$game = new Game($position);
$game->display();
if ($game->winner('x') == true) {
    echo 'You win. Lucky guesses!';
} else {
    if ($game->winner('o') == true) {
        echo 'I win. muhahahah!';
    } else {
        echo 'No winner yet.';
    }
}
开发者ID:kotarubaru,项目名称:Lab-1-Repository,代码行数:31,代码来源:index.php

示例9: Game

<?php 
/*
Designer: Jim Parry & Gabriel Seonghyoung Lee
Programmer: Gabriel Seonghyoung Lee
Date created: January 12, 2016
Revision: 
    January 12, 2016 - File created
    January 15, 2016 - Implemented tic-tac-toe 
*/
require "game.php";
// Get the current board state from the URL
$squares = $_GET['board'];
// Check if the current board state is set in the URL
if (isset($_GET['board'])) {
    // Instantiate new Game object with the current board state
    $gg = new Game($squares);
    // Display the board state
    $gg->display();
    echo '<br/>';
    // Check to see if anyone has won
    if ($gg->winner('x')) {
        echo 'You win. Lucky guesses!';
    } else {
        if ($gg->winner('o')) {
            echo 'I win. Muahahahaha';
        } else {
            echo 'No winner yet, but you are losing.';
        }
    }
}
开发者ID:ScrawnySquirrel,项目名称:COMP4711-Lab01,代码行数:30,代码来源:index.php


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