private static void InitializeHeapsizes(heap[] Heaps) { for (int i = 0; i < Heaps.Length; i++) { Heaps[i] = new heap(GetIntInRange(0, int.MaxValue, String.Format("Please enter how many objects you wish there to be in heap {0}.", i + 1))); } Console.WriteLine(); }
private static void StartGame() { Players CurrentPlayer = Players.User; NimAi Computer = new NimAi(); int HeapNumber = 0, ObjectsToRemove = 0; bool Winner = false; heap[] Heaps = new heap[GetIntInRange(0, 10, "How many heaps do you want this game to have?")]; InitializeHeapsizes(Heaps); CurrentPlayer = GetFirstPlayer(); while (!Winner) { PrintHeaps(Heaps); Console.WriteLine(); if (CurrentPlayer == Players.User) { GetPlayerMove(Heaps, out HeapNumber, out ObjectsToRemove); Heaps[HeapNumber].Count -= ObjectsToRemove; StateMove(CurrentPlayer, HeapNumber, ObjectsToRemove); } else // This means that the player is the computer. { Computer.GetMove(Heaps, out HeapNumber, out ObjectsToRemove); Heaps[HeapNumber].Count -= ObjectsToRemove; StateMove(CurrentPlayer, HeapNumber, ObjectsToRemove); } Winner = CheckWhoIsWinner(Heaps); if (Winner) { AnnounceWinner(CurrentPlayer); } else if (CurrentPlayer == Players.User) { CurrentPlayer = Players.Computer; } else { CurrentPlayer = Players.User; } } }