本文整理汇总了PHP中Game::display方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::display方法的具体用法?PHP Game::display怎么用?PHP Game::display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::display方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Game
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
// gets URL and translates into board
$position = $_GET['board'];
//splits string into array for each square
$squares = str_split($position);
$game = new Game($squares);
$game->display();
//-----------------------------------------------------------------
//Main game logic
//-----------------------------------------------------------------
if ($game->winner('x')) {
echo 'You win. Lucky Guesses!';
} else {
if ($game->winner('o')) {
echo 'I win. Muahahah';
} else {
echo 'No winner yet. But you are losing >:)';
}
}
class Game
{
var $position;
var $squaresLocal;
function __construct($squares)
示例2: Game
}
}
// Updates the current board upon every request
if (isset($_GET['board'])) {
$squares = $_GET['board'];
} else {
$squares = "---------";
}
$game = new Game($squares);
// Stops the game if a winner is found
if ($game->winner('o')) {
$game->game_finished = true;
echo 'You win. Lucky guesses!';
} else {
// Make a move
$game->pick_move();
// Check if the move wins the game
if ($game->winner('x')) {
$game->game_finished = true;
echo 'I win. Muahahahaha';
} else {
echo "No winner yet, but you are losing!";
}
}
// Display the game board after this round
$game->display($squares);
// Restart resets board to empty state
echo '<br/><a href="?board=---------">Restart</a>';
?>
</body>
</html>
示例3: Game
for ($i = 0; $i < 9; $i++) {
if ($this->position[$i] == '-') {
return false;
}
}
return true;
}
}
//Get the Xs,Os and -s in the board.
$position = $_GET['board'];
$game1 = new Game($position);
//Check if x won
if ($game1->winner('x')) {
$game1->isWinner = true;
echo '<h1 align="center">Congratulations, You Win!</h1>';
//Check if o won
} else {
if ($game1->winner('o')) {
$game1->isWinner = true;
echo '<h1 align="center">O wins</h1>';
} else {
//No winner
echo '<h1 align="center">No Winner Yet</h1>';
}
}
//Display the game
$game1->display();
?>
</body>
</html>
示例4: Game
$squares = $_GET['board'];
// gettings all the different squares
if ($squares == "") {
// check to see if board squares were declared
$squares = "---------";
}
$gamefinished = false;
// variable to see if game has ended
$game = new Game($squares);
// create new Game object
$game->pick_move();
// AI picks a moves
if ($game->winner('x')) {
//checks to see if it meets winning conditions
echo 'You win';
$gamefinished = true;
} else {
if ($game->winner('o')) {
echo 'I win';
$gamefinished = true;
} else {
echo 'Draw';
}
}
$game->display($gamefinished);
//displays board
?>
</body>
</html>
示例5: 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.';
}
}
}