static void HandleChangeChars(IYatttgFacade yatttg) { bool reprompt = true; while (reprompt) { Console.Write("{0}Would you like to change these (y/N)? ", Environment.NewLine); char choice = GetChar(); if (choice == 'y') { Console.Write("Enter the new Nort character (Default: {0}): ", yatttg.Nort.Character); char newNort = GetChar(); if (newNort != '\0') yatttg.Nort.Character = newNort; Console.Write("Enter the new Cross character (Default: {0}): ", yatttg.Cross.Character); char newCross = GetChar(); if (newCross != '\0') yatttg.Cross.Character = newCross; Console.WriteLine("Norts = {0}, Crosses = {1}", yatttg.Nort.Character, yatttg.Cross.Character); break; } // Reprompt if the choice wasn't n or empty reprompt = ((choice != 'n') && (choice != '\0')); } }
static void DisplayGrid(IYatttgFacade yatttg) { Cell[,] currentGrid = yatttg.GetGrid(); int counter = 1; Console.WriteLine("-------"); for (int row = 0; row < Constant.GridSize; row++) { Console.Write("|"); for (int column = 0; column < Constant.GridSize; column++) { char value = Char.Parse(counter.ToString()); if (currentGrid[row, column].Marker != null) { value = currentGrid[row, column].Marker.Character; } Console.Write("{0}|", value); counter++; } Console.WriteLine(); } Console.WriteLine("-------"); }
static Tuple <Player, Constant.GameState> PlayGame(IYatttgFacade yatttg, Player p1, Player p2) { Constant.GameState currentGameState_; currentGameState_ = yatttg.InitGame(p1, p2); Player turn = null; bool error = false; while (currentGameState_ == Constant.GameState.InProgress) { Console.Clear(); if (!error) { turn = yatttg.StartNextTurn(); } Console.WriteLine("{0}'s Turn ({1}):", turn.Name, turn.Marker.Character); Console.WriteLine(); DisplayGrid(yatttg); Console.WriteLine("Press the number of the cell you would like to select."); try { int option = Convert.ToInt32(Console.ReadKey(true).KeyChar.ToString()); currentGameState_ = yatttg.MakeMove(turn, option); error = false; } catch (Exception ex) { Console.WriteLine("An error occured."); Console.WriteLine(ex.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); error = true; } } return(new Tuple <Player, Constant.GameState>(turn, currentGameState_)); }
static void DisplayGrid(IYatttgFacade yatttg) { Cell[,] currentGrid = yatttg.GetGrid(); int counter = 1; Console.WriteLine("-------"); for (int row = 0; row < Constant.GridSize; row++) { Console.Write("|"); for (int column = 0; column < Constant.GridSize; column++) { char value = Char.Parse(counter.ToString()); if (currentGrid[row, column].Marker != null) value = currentGrid[row, column].Marker.Character; Console.Write("{0}|", value); counter++; } Console.WriteLine(); } Console.WriteLine("-------"); }
static void HandleChangeChars(IYatttgFacade yatttg) { bool reprompt = true; while (reprompt) { Console.Write("{0}Would you like to change these (y/N)? ", Environment.NewLine); char choice = GetChar(); if (choice == 'y') { Console.Write("Enter the new Nort character (Default: {0}): ", yatttg.Nort.Character); char newNort = GetChar(); if (newNort != '\0') { yatttg.Nort.Character = newNort; } Console.Write("Enter the new Cross character (Default: {0}): ", yatttg.Cross.Character); char newCross = GetChar(); if (newCross != '\0') { yatttg.Cross.Character = newCross; } Console.WriteLine("Norts = {0}, Crosses = {1}", yatttg.Nort.Character, yatttg.Cross.Character); break; } // Reprompt if the choice wasn't n or empty reprompt = ((choice != 'n') && (choice != '\0')); } }
static Tuple<Player, Constant.GameState> PlayGame(IYatttgFacade yatttg, Player p1, Player p2) { Constant.GameState currentGameState_; currentGameState_ = yatttg.InitGame(p1, p2); Player turn = null; bool error = false; while (currentGameState_ == Constant.GameState.InProgress) { Console.Clear(); if (!error) turn = yatttg.StartNextTurn(); Console.WriteLine("{0}'s Turn ({1}):", turn.Name, turn.Marker.Character); Console.WriteLine(); DisplayGrid(yatttg); Console.WriteLine("Press the number of the cell you would like to select."); try { int option = Convert.ToInt32(Console.ReadKey(true).KeyChar.ToString()); currentGameState_ = yatttg.MakeMove(turn, option); error = false; } catch (Exception ex) { Console.WriteLine("An error occured."); Console.WriteLine(ex.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); error = true; } } return new Tuple<Player, Constant.GameState>(turn, currentGameState_); }