Ejemplo n.º 1
0
        /// <summary>
        /// Updates button
        /// </summary>
        public override void Update()
        {
            base.Update();

            //Check if mouse is pressed
            if (Input.MouseButtonReleased(MouseButton.Left))
            {
                // Check if button is pressed before
                if (!Program.pressed)
                {
                    // Check if cursor position is in button bounds
                    if (Util.InRect(Scene.MouseX, Scene.MouseY, X, Y, 80, 30))
                    {
                        Program.pressed = true;

                        // Get player input and adds it to leaderboard
                        var inputText = Scene.GetEntity <TextBox>().inputString;

                        Leaderboard.AddScore(inputText, Program.curScoreTxt);

                        ReadXML.WriteScores();

                        Scene scene = new HighScoresScene();

                        Program.game.SwitchScene(scene);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Stuff in the HighScores Scene
        public HighScoresScene() : base()
        {
            OnBegin = delegate
            {
                HighScoresScene _scene = Program.game.GetScene <HighScoresScene>();
                //Highscore walls
                #region HighScoreWalls
                Image otherWall = Image.CreateRectangle(1, 350);
                otherWall.SetPosition(549, 150);
                otherWall.Color = Color.Blue;
                AddGraphic(otherWall);

                Image bottomWall = Image.CreateRectangle(300, 1);
                bottomWall.SetPosition(250, 500);
                bottomWall.Color = Color.Blue;
                AddGraphic(bottomWall);
                #endregion
                //Adds Textbox and button and highscore leaderboard (hslb)
                Program.game.MouseVisible = true;
                _scene.Add(new TextBox(250, 100));
                _scene.Add(new Button(420, 95));

                hslb = new HighScoreLeaderboard(250, 150);
                _scene.Add(hslb);

                ReadXML.WriteScores();
            };
            Program.game.AddScene(this);
        }
Ejemplo n.º 3
0
        public static void WriteScores()
        {
            HighScoresScene scene = Program.game.GetScene <HighScoresScene>();

            //Checks if XML exists, if so, loads it
            if (!System.IO.File.Exists("savefile.xml"))
            {
                return;
            }
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("savefile.xml");

            XmlNodeList       xmlElements = xmlDoc.DocumentElement.ChildNodes;
            List <XmlElement> xmlnodes    = new List <XmlElement>();

            //Adds xml elements to a list
            foreach (XmlElement i in xmlElements)
            {
                xmlnodes.Add(i);
            }

            int count;

            //Checks list count
            if (xmlnodes.Count < 5)
            {
                count = xmlnodes.Count;
            }
            else
            {
                count = 5;
            }
            //For loop for going through top 5 scores
            for (int i = 0; i < count; i++)
            {
                XmlElement curElement = xmlnodes[0];

                RichText name = new RichText();
                name.Name = "scoreName";
                RichText score = new RichText();
                score.Name = "scoreScore";

                //Checks if the attributes are empty, if not, then sets current element the score value
                for (int j = 0; j < xmlnodes.Count; j++)
                {
                    if (xmlnodes[j].Attributes["score"].Value != "")
                    {
                        if (xmlnodes[j].Attributes["name"].Value != "")
                        {
                            if (Int32.Parse(curElement.Attributes["score"].Value) < Int32.Parse(xmlnodes[j].Attributes["score"].Value))
                            {
                                curElement = xmlnodes[j];
                            }
                        }
                    }
                }

                //Sets position and value for the names and scores displayd on the screen.
                name.String = curElement.Attributes["name"].Value;
                name.SetPosition(8, i * 50 + 116);
                scene.hslb.AddGraphic(name);
                score.String = curElement.Attributes["score"].Value;
                score.SetPosition(200, i * 50 + 116);
                scene.hslb.AddGraphic(score);
                xmlnodes.Remove(curElement);
            }
        }