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 List<Tuple<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 List<Tuple<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 var scoreTuple = new Tuple<String, int>(parts[0], int.Parse(parts[1]));
63 Scores.Add (scoreTuple);
67 catch (FileNotFoundException)
72 public override void CleanUp()
78 public override void Draw(SpriteBatch spriteBatch)
80 base.Draw(spriteBatch);
81 spriteBatch.DrawString(Font, "YOUR SCORE WAS: " + Game.Player.Score.ToString(), new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2), Color.Black);
82 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));
83 nameChooser.Draw(spriteBatch);
84 DrawScores(spriteBatch);
87 public override void Update(GameTime gameTime)
89 base.Update(gameTime);
90 InputController.UpdateInput(false);
91 nameChooser.Update(gameTime);
94 protected void DrawScores(SpriteBatch spriteBatch)
96 var sortedList = (from entry in Scores orderby entry.Item2 descending select entry)
102 foreach (Tuple<string, int> entry in sortedList) {
104 spriteBatch.DrawString(Font, entry.Item1 + " " + entry.Item2, new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2 + 100 + (32 * i)), new Color(0, 0, 0, 64));