public static void GamePlay() { Player playerOne = new Player(); Player playerTwo = new Player(); bool PlayerOnesTurn = true; bool OneIsWinner = false; bool TwoIsWinner = false; var Piles = new SetPiles(); Console.Write("Player 1, enter your name: "); playerOne.Name = Console.ReadLine(); Console.Write("Player 2, enter your name: "); playerTwo.Name = Console.ReadLine(); Console.WriteLine(""); Console.WriteLine(playerOne.Name + playerTwo.Name); Console.WriteLine("A: " + Piles.StackA + " B: " + Piles.StackB + " C: " + Piles.StackC); while (OneIsWinner == false && TwoIsWinner == false) { if (PlayerOnesTurn == true) { PlayersTurn.Turn(playerOne, Piles); if (Piles.StackA == 0 && Piles.StackB == 0 && Piles.StackC == 0) { TwoIsWinner = true; } PlayerOnesTurn = false; } else if (PlayerOnesTurn == false) { PlayersTurn.Turn(playerTwo, Piles); if (Piles.StackA == 0 && Piles.StackB == 0 && Piles.StackC == 0) { OneIsWinner = true; } PlayerOnesTurn = true; } else { Console.WriteLine("Please select a valid option"); } } if (OneIsWinner == true) { Console.WriteLine(playerOne.Name + " there are no counters left, so you win!"); } else if (TwoIsWinner == true) { Console.WriteLine(playerTwo.Name + " there are no counters left, so you win!"); } }
public static void Turn(Player Player, SetPiles Piles) { Console.Write(Player.Name + " choose a pile: "); PlayersPileChoice = Console.ReadLine(); PlayersPileChoice = PlayersPileChoice.ToUpper(); if (PlayersPileChoice == "A") { Console.Write("How many to remove from pile A: "); PlayersAmountChoice = Convert.ToInt32(Console.ReadLine()); if (PlayersAmountChoice > 0) { if (PlayersAmountChoice > Piles.StackA) { Console.WriteLine("There is not that many left. Please choose again."); Turn(Player, Piles); } else { Piles.StackA = Piles.StackA - PlayersAmountChoice; Console.WriteLine("A: " + Piles.StackA + " B: " + Piles.StackB + " C: " + Piles.StackC); } } else { Console.WriteLine("Please select a positive Integer"); Turn(Player, Piles); } } else if (PlayersPileChoice == "B") { Console.Write("How many to remove from pile B: "); PlayersAmountChoice = Convert.ToInt32(Console.ReadLine()); if (PlayersAmountChoice > 0) { if (PlayersAmountChoice > Piles.StackB) { Console.WriteLine("There is not that many left. Please choose again."); Turn(Player, Piles); } else { Piles.StackB = Piles.StackB - PlayersAmountChoice; Console.WriteLine("A: " + Piles.StackA + " B: " + Piles.StackB + " C: " + Piles.StackC); } } else { Console.WriteLine("Please select a positive Integer"); Turn(Player, Piles); } } else if (PlayersPileChoice == "C") { Console.Write("How many to remove from pile C: "); PlayersAmountChoice = Convert.ToInt32(Console.ReadLine()); if (PlayersAmountChoice > 0) { if (PlayersAmountChoice > Piles.StackC) { Console.WriteLine("There is not that many left. Please choose again."); Turn(Player, Piles); } else { Piles.StackC = Piles.StackC - PlayersAmountChoice; Console.WriteLine("A: " + Piles.StackA + " B: " + Piles.StackB + " C: " + Piles.StackC); } } else { Console.WriteLine("Please select a positive Integer"); Turn(Player, Piles); } } else { Console.WriteLine("Please enter a valid amount"); Turn(Player, Piles); } }