}//end Game /// <summary> /// This method updates currentPlayer and CurrentPlayerIndex /// and end game is all player finished all combinations /// </summary> public void NexTurn() { currentPlayer = players[(currentPlayerIndex) % players.Count]; playersFinished = 0; form.ShowPlayerName(currentPlayer.Name); form.DisableAndClearCheckBoxes(); form.EnableRollButton(); numRolls = 1; currentPlayer.ShowScores(); //check end game and finish the game foreach (Player player in players) { if (player.IsFinished()) { playersFinished++; } } if (playersFinished == players.Count) { string name = ""; int grandTotal = 0; foreach (Player player in players) { if (player.GrandTotal > grandTotal) { grandTotal = player.GrandTotal; name = player.Name; } } DialogResult newGame = MessageBox.Show("Game has ended and the winner is " + name + ".\nDo you want to start a new game?", "Game finished", MessageBoxButtons.YesNo); if (newGame == DialogResult.Yes) { form.StartNewGame(); } else { form.Close(); } } currentPlayerIndex++; }//end NextTurn
private void FinishGame() { List <int> scores = new List <int>(); foreach (Player player in players) { scores.Add(player.GrandTotal); } int max = int.MinValue; int index = 0; int j = 0; foreach (int s in scores) { if (s > max) { index = j; max = s; } j++; } form.DisableAndClearCheckBoxes(); form.DisableRollButton(); for (int i = 0; i < Form1.NUM_BUTTONS + Form1.NUM_TOTALS; i++) { form.DisableScoreButton((ScoreType)i); } string builder = (index >= scores.Count) ? string.Format("There was a tie with {0} points.\nPlay Again?", scores.Max()):string.Format("The Winner is {0} with a score of {1},\nPlay Again?", players[index].Name, scores.Max().ToString()); switch (MessageBox.Show(builder, "Game Over", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false)) { case DialogResult.Yes: form.StartNewGame(); break; case DialogResult.No: form.Close(); break; } }