}//end turn event /// <summary> /// stops times, calculates score, displays message with score, correct answers, time, and missed problems. /// Creates a highscore object, and adds to whatever list the level was. /// sorts the list based on score /// closes Form4 /// </summary> public void endGame() { timer.Enabled = false; SoundPlayer music1 = new SoundPlayer(Properties.Resources.cheer2); music1.Play(); double totalScore; //if you play on higher difficulty, you get more points. Difficulty based on age if (age <= 5) { totalScore = (100 - time) * score; } else if (age <= 10) { totalScore = (100 - time) * score * 1.5; } else if (age <= 15) { totalScore = (100 - time) * score * 2; } else { totalScore = (100 - time) * score * 2.5; } MessageBox.Show("Your score: " + totalScore + "\nAnswered Correctly: " + score + "\nTime: " + time + " seconds" + "\nProblems missed:\n" + missed); Highscores highscore = new Highscores(GameUtil.playerList[(GameUtil.selectedPlayer)].getName(), op, score, time, totalScore); if (op == "+") { GameUtil.additionList.Add(highscore); } else if (op == "-") { GameUtil.substrationList.Add(highscore); } else if (op == "*") { GameUtil.multiplicationList.Add(highscore); } else if (op == "/") { GameUtil.divisionList.Add(highscore); } //GameUtil.additionList.OrderBy(a => a.score).ThenBy(a => a.time).ToList(); GameUtil.additionList.Sort((y, x) => x.totalScore.CompareTo(y.totalScore)); GameUtil.substrationList.Sort((y, x) => x.totalScore.CompareTo(y.totalScore)); GameUtil.multiplicationList.Sort((y, x) => x.totalScore.CompareTo(y.totalScore)); GameUtil.divisionList.Sort((y, x) => x.totalScore.CompareTo(y.totalScore)); this.Close(); SoundPlayer music2 = new SoundPlayer(Properties.Resources.ole_ole); music2.Play(); } //end endgame()
}//end sublist /// <summary> /// adds highscores to the division listview /// </summary> public void setDivisionlist() { for (int i = 0; i < GameUtil.divisionList.Count; i++) { Highscores hs = GameUtil.divisionList[i]; listDivide.Items.Add(hs.name + "\t" + hs.totalScore); } } //end divlist
}//end mullist /// <summary> /// adds highscores to the subtraction listview /// </summary> public void setSubtrationlist() { for (int i = 0; i < GameUtil.substrationList.Count; i++) { Highscores hs = GameUtil.substrationList[i]; listSubtract.Items.Add(hs.name + "\t" + hs.totalScore); } }//end sublist
}//end addlist /// <summary> /// adds highscores to the multiplication listview /// </summary> public void setMultiplicationlist() { for (int i = 0; i < GameUtil.multiplicationList.Count; i++) { Highscores hs = GameUtil.multiplicationList[i]; listMultiply.Items.Add(hs.name + "\t" + hs.totalScore); } }//end mullist
}//end click() /// <summary> /// adds all highscores to the addition listview /// </summary> public void setAdditionlist() { for (int i = 0; i < GameUtil.additionList.Count; i++) { Highscores hs = GameUtil.additionList[i]; listAdd.Items.Add(hs.name + "\t" + hs.totalScore); } }//end addlist