/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { //DONE: Complete this method and utilize the rest of the class structure to play the game. /* * While there isn't a winner determined or too many turns have been taken, * allow each player to see the board and take a turn. * A turn consists of picking a position on the board, and then putting their appropriate marker * in the board. Be sure to display the board after every turn to show the most up to date * board so the next player can accurately choose. * Once a winner is determined, display the board and return a winner */ Player winner; while (!CheckForWinner(Board)) { Player nextPlayer = NextPlayer(); nextPlayer.TakeTurn(Board); Board.DisplayBoard(); SwitchPlayer(); } SwitchPlayer(); winner = NextPlayer(); return(winner); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { int turnCounter = 0; bool winner = false; Player whosTurn = new Player(); while (turnCounter < 9) { Console.Clear(); whosTurn = NextPlayer(); Board.DisplayBoard(); whosTurn.TakeTurn(Board); Board.DisplayBoard(); winner = CheckForWinner(Board); if (winner) { turnCounter = 9; } SwitchPlayer(); turnCounter++; } return(winner ? whosTurn : new Player() { Name = "draw" }); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play(Player playerOne, Player playerTwo) { //for (int i = 0; i < 9; i++) //{ playerOne.TakeTurn(Board); //} //TODO: Complete this method and utilize the rest of the class structure to play the game. /* * Complete this method by constructing the logic for the actual playing of Tic Tac Toe. * * A few things to get you started: * 1. A turn consists of a player picking a position on the board with their designated marker. * 2. Display the board after every turn to show the most up to date state of the game * 3. Once a Winner is determined, display the board one final time and return a winner * * Few additional hints: * Be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * Use any and all pre-existing methods in this program to help construct the method logic. */ return(new Player()); // fixing compiler bug }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { //DONE: Complete this method and utilize the rest of the class structure to play the game. /* * While there isn't a winner determined or too many turns have been taken, * allow each player to see the board and take a turn. * A turn consists of picking a position on the board, and then putting their appropriate marker * in the board. Be sure to display the board after every turn to show the most up to date * board so the next player can accurately choose. * Once a winner is determined, display the board and return a winner */ int currentTurn = 1; Player currentPlayer = PlayerOne; bool haveWinner = false; while (!haveWinner && currentTurn <= 9) { Board.DisplayBoard(); currentPlayer = PlayerOne.IsTurn ? PlayerOne : PlayerTwo; currentPlayer.TakeTurn(Board); currentTurn += 1; haveWinner = CheckForWinner(Board); SwitchPlayer(); } Board.DisplayBoard(); return(currentTurn == 10 ? new Player() { Name = "Draw" } : currentPlayer); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { string[,] board = Board.GameBoard; int counter = 0; //Board.DisplayBoard(); while (counter < 9 && !CheckForWinner(Board)) { Board.DisplayBoard(); Player nextPlayer = NextPlayer(); nextPlayer.TakeTurn(Board); SwitchPlayer(); counter++; } if (counter == 9) { Console.WriteLine("its a draw"); return(Winner); } Console.WriteLine($"{Winner.Name} is the winner!"); return(Winner); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Reference to winner player, else returns ref to null</returns> public Player Play() { //DONE: Complete this method and utilize the rest of the class structure to play the game. int maxTurnCount = 9; Player currentPlayer = null; int i = 0; for (i = 0; i < maxTurnCount; i++) { Board.DisplayBoard(); currentPlayer = NextPlayer(); currentPlayer.TakeTurn(Board); if (CheckForWinner(Board)) { break; } SwitchPlayer(); } //Default return is null (signals a draw) Board.DisplayBoard(); if (i == 9) { return(null); } else { return(currentPlayer); } }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner of the game</returns> public Player Play() { Console.WriteLine("\nWelcome to Tic-Tac-Toe, " + PlayerOne.Name + " and " + PlayerTwo.Name + ". Now, let's play!"); Player tie = new Player { Name = "Nobody won" }; Player activePlayer = PlayerOne; Game TestGame = new Game(PlayerOne, PlayerTwo); //PlayerOne gets the first move //Only 9 locations - end in a tie if neither win after 9 moves int positionsLeft = 9; bool gameRunning = true; while (gameRunning) { if (positionsLeft == 0) { TestGame.Board.DisplayBoard(); return(tie); } TestGame.Board.DisplayBoard(); activePlayer.TakeTurn(TestGame.Board); if (CheckForWinner(TestGame.Board)) { TestGame.Board.DisplayBoard(); return(activePlayer); } positionsLeft--; SwitchPlayer(); activePlayer = NextPlayer(); } return(tie); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { int counter = 0; Player currentPlayer = NextPlayer(); while (!CheckForWinner(this.Board) && counter < 9) { SwitchPlayer(); currentPlayer = NextPlayer(); currentPlayer.TakeTurn(this.Board); Board.DisplayBoard(); counter++; } if (counter > 8) { Console.WriteLine("Tie"); return(null); } else { Console.WriteLine($"you have won: {currentPlayer.Name}"); return(currentPlayer); } //Whos turn is it //let player take that turn //end the turn //display the board //check for tie and win, if they win display the board and return a winner //todo: complete this method and utilize the rest of the class structure to play the game. /* * complete this method by constructing the logic for the actual playing of tic tac toe. * * a few things to get you started: * 1. a turn consists of a player picking a position on the board with their designated marker. * * 2. display the board after every turn to show the most up to date state of the game * 3. once a winner is determined, display the board one final time and return a winner * * few additional hints: * be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * use any and all pre-existing methods in this program to help construct the method logic. */ }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { int turns = 0; // Dislay board Board.DisplayBoard(); while (true) { // the current player takes turn on board and are counted Player currentPlayer = NextPlayer(); currentPlayer.TakeTurn(Board); turns++; Console.Clear(); Board.DisplayBoard(); //checks to see if there is a winner on the board if (CheckForWinner(Board)) { Winner = currentPlayer; return(Winner); } //checks to see if the players have used the positions on the board if (turns >= 9) { Winner = null; return(Winner); } SwitchPlayer(); } //TODO: Complete this method and utilize the rest of the class structure to play the game. /* * Complete this method by constructing the logic for the actual playing of Tic Tac Toe. * * A few things to get you started: * 1. A turn consists of a player picking a position on the board with their designated marker. * 2. Display the board after every turn to show the most up to date state of the game * 3. Once a Winner is determined, display the board one final time and return a winner * * Few additional hints: * Be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * Use any and all pre-existing methods in this program to help construct the method logic. */ //Player One = new Player(); //return One; }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { //Done: Complete this method and utilize the rest of the class structure to play the game. // Total Avaliable Turns int totalTurns = 9; // Keep track of whos turn it is. Player currentPlayer = null; // Keep track of current turn count int currentTurn; // Turn Sequence for (currentTurn = 0; currentTurn < totalTurns; currentTurn++) { //Show Board Board.DisplayBoard(); //Set Current Player currentPlayer = NextPlayer(); //Current Player Takes Turn currentPlayer.TakeTurn(Board); //Check if Turn Caused Player to Win //If Yes End Game if (CheckForWinner(Board) == true) { break; } //If No Switch to Other Player else { SwitchPlayer(); } } // Show the final board Board.DisplayBoard(); //Return with who the current player is if the game hasn't ended. Else return nothing. if (currentTurn == totalTurns) { return(null); } else { return(currentPlayer); } }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { //TODO: Complete this method and utilize the rest of the class structure to play the game. /* * Complete this method by constructing the logic for the actual playing of Tic Tac Toe. * * A few things to get you started: * 1. A turn consists of a player picking a position on the board with their designated marker. * 2. Display the board after every turn to show the most up to date state of the game * 3. Once a Winner is determined, display the board one final time and return a winner * * Few additional hints: * Be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * Use any and all pre-existing methods in this program to help construct the method logic. */ bool isWinner = false; int count = 0; Player current = new Player(); while (!isWinner) { count++; SwitchPlayer(); Console.Clear(); Board.DisplayBoard(); current = NextPlayer(); bool taken = false; while (!taken) { taken = current.TakeTurn(Board); } isWinner = CheckForWinner(Board); if (count == 9) { current.Name = "draw"; isWinner = true; } } Winner = current; return(Winner); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play(Player PlayerOne, Player PlayerTwo, Board board) { int counter = 0; while (counter < 9) { Console.Clear(); Board.DisplayBoard(); if (PlayerOne.IsTurn) { PlayerOne.TakeTurn(board); } else { PlayerTwo.TakeTurn(board); } counter++; if (CheckForWinner(board)) { counter = 9; } Console.WriteLine(NextPlayer().Name); SwitchPlayer(); } return(Winner); //TODO: Complete this method and utilize the rest of the class structure to play the game. /* * Complete this method by constructing the logic for the actual playing of Tic Tac Toe. * * A few things to get you started: * 1. A turn consists of a player picking a position on the board with their designated marker. * 2. Display the board after every turn to show the most up to date state of the game * 3. Once a Winner is determined, display the board one final time and return a winner * * Few additional hints: * Be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * Use any and all pre-existing methods in this program to help construct the method logic. */ }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Player that triggered the true flag of method CheckForWinner</returns> public Player Play() { int turnCounter = 0; while (turnCounter < 9) { Console.Clear(); Board.DisplayBoard(); SwitchPlayer(); Player player = NextPlayer(); player.TakeTurn(Board); if (CheckForWinner()) { Console.Clear(); Board.DisplayBoard(); return(player); } turnCounter += 1; } Console.Clear(); Board.DisplayBoard(); return(Draw); }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { int totalTurn = 9; int currentTurn = 0; Player player = null; while (currentTurn < totalTurn && !CheckForWinner(Board)) { Board.DisplayBoard(); player = NextPlayer(); player.TakeTurn(Board); if (CheckForWinner(Board)) { break; } else { SwitchPlayer(); } currentTurn++; } Console.Clear(); Board.DisplayBoard(); if (currentTurn == totalTurn) { return(null); } else { return(player); } }
/// <summary> /// Activate the Play of the game /// </summary> /// <returns>Winner</returns> public Player Play() { //TODO: Complete this method and utilize the rest of the class structure to play the game. /* * Complete this method by constructing the logic for the actual playing of Tic Tac Toe. * * A few things to get you started: * 1. A turn consists of a player picking a position on the board with their designated marker. * 2. Display the board after every turn to show the most up to date state of the game * 3. Once a Winner is determined, display the board one final time and return a winner * * Few additional hints: * Be sure to keep track of the number of turns that have been taken to determine if a draw is required * and make sure that the game continues while there are unmarked spots on the board. * * Use any and all pre-existing methods in this program to help construct the method logic. */ bool checker = CheckForWinner(Board); int count = 0; while (checker != true && count < 9) { Player currPlayer = NextPlayer(); Board.DisplayBoard(); currPlayer.TakeTurn(Board); checker = CheckForWinner(Board); if (checker == true) { return(currPlayer); } SwitchPlayer(); count++; } return(new Player("C", "Cat's Game")); }