Created
February 4, 2017 05:38
-
-
Save tolmicl/d3c0d27cbcd86b0f14fc3ce0855ec92b to your computer and use it in GitHub Desktop.
p1010test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TicTacToe Test program | |
using System; | |
class p1010test | |
{ | |
static void Main(string[] args) | |
{ | |
p1010 game = new p1010(); | |
while (!game.checkDraw()) | |
{ | |
// prompt player 1 for a row and column | |
Console.Write("Player 1- Choose a row (0, 1, or 2): "); | |
int player1Row = int.Parse(Console.ReadLine()); | |
Console.Write("Player 1- Choose a column (0, 1, or 2): "); | |
int player1Col = int.Parse(Console.ReadLine()); | |
// check if the space is available | |
// if its not available, prompt again | |
while (!game.checkEmpty(player1Row, player1Col)) | |
{ | |
Console.WriteLine("Square already taken."); | |
Console.WriteLine("Choose a row (0, 1, or 2): "); | |
player1Row = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Choose a column (0, 1, or 2): "); | |
player1Col = int.Parse(Console.ReadLine()); | |
} | |
// put the player 1's row and column move onto the board | |
game.player1Move(player1Row, player1Col); | |
// check if player 1 has won | |
if (game.checkPlayer1Win()) | |
{ | |
game.displayBoard(); | |
Console.WriteLine("Player 1 wins!"); | |
break; | |
// check if the game is a draw | |
} | |
else if (game.checkDraw()) | |
{ | |
game.displayBoard(); | |
Console.WriteLine("Game is a draw."); | |
break; | |
} | |
game.displayBoard(); | |
// prompt player 2 for a row and column | |
Console.Write("Player 2- Choose a row (0, 1, or 2): "); | |
int player2Row = int.Parse(Console.ReadLine()); | |
Console.Write("Player 2- Choose a column (0, 1, or 2): "); | |
int player2Col = int.Parse(Console.ReadLine()); | |
// check if the space is available | |
// if its not available, prompt again | |
while (!game.checkEmpty(player2Row, player2Col)) | |
{ | |
Console.WriteLine("Square already taken."); | |
Console.Write("Choose a row (0, 1, or 2): "); | |
player2Row = int.Parse(Console.ReadLine()); | |
Console.Write("Choose a column (0, 1, or 2): "); | |
player2Col = int.Parse(Console.ReadLine()); | |
} | |
game.player2Move(player2Row, player2Col); | |
if (game.checkPlayer2Win()) | |
{ | |
game.displayBoard(); | |
Console.WriteLine("Player 2 wins!"); | |
break; | |
} | |
else if (game.checkDraw()) | |
{ | |
game.displayBoard(); | |
Console.WriteLine("Game is a draw"); | |
break; | |
} | |
game.displayBoard(); | |
} | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment