Exemple #1
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            //graphics.IsFullScreen = true;

            graphics.PreferredBackBufferWidth  = 1920 / 2;
            graphics.PreferredBackBufferHeight = 540;

            Content.RootDirectory = "Content";

            Window.AllowUserResizing = true;

            scoreboard = new Scoreboard();
            try
            {
                scoreboard.LoadFromXML(scoreboardFilename);
            }
            catch (FileNotFoundException e)
            {
                // no save file was found, a new one will be generated
                scoreboard.addScore(new ScoreboardEntry("Simon", 60));
                scoreboard.addScore(new ScoreboardEntry("Ben", 55));
                scoreboard.addScore(new ScoreboardEntry("Jeremy", 50));
                scoreboard.addScore(new ScoreboardEntry("Deen", 45));
                scoreboard.addScore(new ScoreboardEntry("George", 40));
                scoreboard.addScore(new ScoreboardEntry("David", 35));
                scoreboard.addScore(new ScoreboardEntry("Brett", 30));
                scoreboard.addScore(new ScoreboardEntry("Jonathan", 25));
                scoreboard.addScore(new ScoreboardEntry("Joel", 20));
                scoreboard.addScore(new ScoreboardEntry("Aaron", 15));
                scoreboard.SaveToXML(scoreboardFilename);
            }
        }
Exemple #2
0
        public void LoadFromXML(string filename)
        {
            TextReader    reader     = new StreamReader(filename);
            XmlSerializer serializer = new XmlSerializer(typeof(Scoreboard));
            Scoreboard    loaded     = (Scoreboard)serializer.Deserialize(reader);

            reader.Close();
            this.Size   = loaded.Size;
            this.Scores = loaded.Scores;
        }
Exemple #3
0
        public static void test()
        {
            Scoreboard s = new Scoreboard(5);

            if (s.Size != 5)
            {
                throw new Exception("size is wrong");
            }
            s.addScore(new ScoreboardEntry("10", 10));
            s.addScore(new ScoreboardEntry("1", 1));
            s.addScore(new ScoreboardEntry("9", 9));
            s.addScore(new ScoreboardEntry("8", 8));
            s.addScore(new ScoreboardEntry("2", 2));
            s.addScore(new ScoreboardEntry("7", 7));
            s.addScore(new ScoreboardEntry("6", 6));
            s.addScore(new ScoreboardEntry("3", 3));
            s.addScore(new ScoreboardEntry("5", 5));
            s.addScore(new ScoreboardEntry("4", 4));

            if (s.Scores.Count != 5)
            {
                throw new Exception("Wrong number of scores" + s.Scores.Count + " != " + 5);
            }

            for (int i = 0; i < 5; i++)
            {
                if (s.Scores[i].Value != 10 - i)
                {
                    throw new Exception("Incorrect score value for '" + s.Scores[i].Name + "': " + s.Scores[i].Value + " should be " + (10 - i));
                }
            }

            //test serializer
            s.SaveToXML("scoreboard.xml");
            Scoreboard t = new Scoreboard();

            t.LoadFromXML("scoreboard.xml");

            if (t.Scores.Count != 5)
            {
                throw new Exception("Wrong number of scores" + t.Scores.Count + " != " + 5);
            }
            for (int i = 0; i < 5; i++)
            {
                if (t.Scores[i].Value != 10 - i)
                {
                    throw new Exception("Incorrect score value for '" + t.Scores[i].Name + "': " + t.Scores[i].Value + " should be " + (10 - i));
                }
            }
        }