public static void DrawHighScore() { Color buttonColor = Color.White; if (UpdateStates.CurrentSelectedButton == 1) //change color of button to denote currently selected button (for keyboard controls) { buttonColor = Color.Red; } PacmanGame.spriteBatch.Draw(PacmanGame.boxPurple, HighScoreMenu.BackToMenuRectangle, buttonColor); List <int> highScores = HighScoreMenu.GetHighScores(); //print the high scores for (int i = 0; i < 5; i++) { string stringToDraw = (i + 1).ToString() + ". " + highScores[i].ToString(); PacmanGame.spriteBatch.DrawString(PacmanGame.spriteFont, stringToDraw, new Vector2(PacmanGame.screenWidth / 2 - PacmanGame.spriteFont.MeasureString(stringToDraw).X / 2, (i + 1) * PacmanGame.screenHeight / 7 - PacmanGame.spriteFont.MeasureString(stringToDraw).Y / 2), Color.Black); } //draw the back button PacmanGame.spriteBatch.DrawString(PacmanGame.spriteFont, "Back", new Vector2(HighScoreMenu.BackToMenuRectangle.Center.X - PacmanGame.spriteFont.MeasureString("Back").X / 2, HighScoreMenu.BackToMenuRectangle.Center.Y - PacmanGame.spriteFont.MeasureString("Back").Y / 2), buttonColor); }
public static void UpdateGameEnd(GameTime gameTime) { timerGameEnd.tick(gameTime); if (timerGameEnd.TimeMilliseconds >= timerNextLevel.Interval) { //save the high score to file if it's in the top 5 int score = Map.Paddles[0].totalScore; //read the high score + list List <int> highScores = HighScoreMenu.GetHighScores(); highScores.Add(score); //add the highscore to the list highScores.Sort(); highScores.Reverse(); //reverse, since sort does it backwards highScores.RemoveAt(5); //remove the sixth element (we only want five) using (StreamWriter writer = new StreamWriter("HighScores.txt")) { foreach (int i in highScores) //rewrite the list to file { writer.WriteLine(i.ToString()); } } Maze = true; timerGame.reset(); timerNextLevel.reset(); timerGame.reset(); PacmanGame.gameState = GameState.HighScore; } }