Пример #1
0
<!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
0
    }
}
// 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
0
        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
0
$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
0
<?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.';
        }
    }
}