static void Main(string[] args) { Player p1, p2; bool playing = true; // Init the Yatttg facade IYatttgFacade yatttg = new YatttgModel.YatttgModel(); Console.WriteLine("Welcome to Yatttg! (Yet another tic-tac-toe game)."); Console.WriteLine("The current characters for the norts and crosses are {0} and {1} respectively.", yatttg.Nort.Character, yatttg.Cross.Character); // Users can change the characters for the norts and crosses, if they wish. HandleChangeChars(yatttg); // Set up each player Console.Write("Enter player name for norts: "); string name = Console.ReadLine(); p1 = new Player(name, yatttg.Nort); Console.Write("Enter player name for crosses: "); name = Console.ReadLine(); p2 = new Player(name, yatttg.Cross); // Start the game while (playing) { Tuple <Player, Constant.GameState> game = PlayGame(yatttg, p1, p2); bool reprompt = true; if (game.Item2 == Constant.GameState.Win) { Console.WriteLine("{0} Wins!", game.Item1.Name); } else if (game.Item2 == Constant.GameState.Tie) { Console.WriteLine("{0} tied the game!", game.Item1.Name); } while (reprompt) { Console.Write("Play again (y/N)? "); char choice = GetChar(); if (choice == 'y') { break; } // Reprompt if the choice wasn't n or empty reprompt = ((choice != 'n') && (choice != '\0')); } if (!reprompt) { playing = false; } } }
static void Main(string[] args) { Player p1, p2; bool playing = true; // Init the Yatttg facade IYatttgFacade yatttg = new YatttgModel.YatttgModel(); Console.WriteLine("Welcome to Yatttg! (Yet another tic-tac-toe game)."); Console.WriteLine("The current characters for the norts and crosses are {0} and {1} respectively.", yatttg.Nort.Character, yatttg.Cross.Character); // Users can change the characters for the norts and crosses, if they wish. HandleChangeChars(yatttg); // Set up each player Console.Write("Enter player name for norts: "); string name = Console.ReadLine(); p1 = new Player(name, yatttg.Nort); Console.Write("Enter player name for crosses: "); name = Console.ReadLine(); p2 = new Player(name, yatttg.Cross); // Start the game while (playing) { Tuple<Player, Constant.GameState> game = PlayGame(yatttg, p1, p2); bool reprompt = true; if (game.Item2 == Constant.GameState.Win) Console.WriteLine("{0} Wins!", game.Item1.Name); else if (game.Item2 == Constant.GameState.Tie) Console.WriteLine("{0} tied the game!", game.Item1.Name); while (reprompt) { Console.Write("Play again (y/N)? "); char choice = GetChar(); if (choice == 'y') break; // Reprompt if the choice wasn't n or empty reprompt = ((choice != 'n') && (choice != '\0')); } if (!reprompt) playing = false; } }