/// <summary> /// Give the user instructions for piece placement and return /// the 2D location of the position they select /// </summary> /// <param name="activePlayer"></param> /// <returns></returns> public int[] PiecePlacement(_2DGameLib.Player activePlayer) { //you need to be using the .NET framework 4.6 for this line to work (C# 6) Console.WriteLine(); Console.WriteLine($"{activePlayer.Name}, it's your turn:"); Console.WriteLine("Make your move by entering the number of the square you'd like to take:"); PrintBoardMap(); Console.Write("Enter the number: "); //todo: Prevent returning a location that's already been used int[] temp = { 0, 0 }; bool validInput = true; do { try { temp = ConvertToArrayLocation(Console.ReadLine()); } catch (FormatException) { validInput = false; Console.WriteLine("Input must be a number between 1 and 9"); } if (temp[0] < 0 || temp[0] >= 3 || temp[1] < 0 || temp[1] >= 3) { validInput = false; Console.WriteLine("Input must be a number between 1 and 9"); } else if ((temp[0] >= 0 && temp[0] < 3) && (temp[1] >= 0 && temp[1] < 3)) { if (game.board.board[temp[0], temp[1]] == 'X' || game.board.board[temp[0], temp[1]] == 'O') { validInput = false; Console.WriteLine("That space has already been taken. Please try again."); } else { validInput = true; } } } while (!validInput); return(temp); }
/// <summary> /// Get and set the player's desired location on the board /// </summary> /// <param name="activePlayer"></param> public void TakeTurn(_2DGameLib.Player activePlayer) { int[] position = PiecePlacement(activePlayer); game.SetBoard(position[0], position[1], activePlayer.Token); Console.Clear(); }