2 using System.Collections.Generic;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
10 namespace SuperPolarity
12 class ScoreScreen : Screen
14 protected SpriteFont Font;
15 protected NameChooserWidget nameChooser;
16 protected Dictionary<string, int> Scores;
18 public ScoreScreen(SuperPolarity newGame) : base(newGame) { }
20 public override void Initialize()
23 nameChooser = new NameChooserWidget(Game, new Vector2(40, Game.GraphicsDevice.Viewport.Height / 4));
24 InputController.RegisterEventForButton("OK", Buttons.A);
25 InputController.RegisterEventForKey("OK", Keys.Z);
26 Scores = new Dictionary<string, int>();
30 public override void LoadContent()
33 Font = Game.Content.Load<SpriteFont>("Fonts\\bigfont");
34 InputController.Bind("OK", HandleNext);
37 public void HandleNext(float value)
39 if (!Active) { return; }
44 public void WriteScore()
46 using (StreamWriter swriter = new StreamWriter("scores.txt", true))
48 swriter.WriteLine(nameChooser.Value() + "," + Game.Player.Score.ToString());
52 public void ReadScore()
56 using (StreamReader sreader = new StreamReader("scores.txt"))
59 while ((line = sreader.ReadLine()) != null)
61 string[] parts = line.Split(',');
62 Scores.Add(parts[0], int.Parse(parts[1]));
66 catch (FileNotFoundException)
71 public override void CleanUp()
77 public override void Draw(SpriteBatch spriteBatch)
79 base.Draw(spriteBatch);
80 spriteBatch.DrawString(Font, "YOUR SCORE WAS: " + Game.Player.Score.ToString(), new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2), Color.Black);
81 spriteBatch.DrawString(Font, "Use Left Stick or Arrows to Choose Name Press A when done", new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2 + 40), new Color(0, 0, 0, 128));
82 nameChooser.Draw(spriteBatch);
83 DrawScores(spriteBatch);
86 public override void Update(GameTime gameTime)
88 base.Update(gameTime);
89 InputController.UpdateInput(false);
90 nameChooser.Update(gameTime);
93 protected void DrawScores(SpriteBatch spriteBatch)
95 var sortedDict = (from entry in Scores orderby entry.Value descending select entry)
97 .ToDictionary(pair => pair.Key, pair => pair.Value);
101 foreach (KeyValuePair<string, int> entry in sortedDict) {
103 spriteBatch.DrawString(Font, entry.Key + " " + entry.Value, new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2 + 100 + (32 * i)), new Color(0, 0, 0, 64));