Exemple #1
0
        private void updateGameOver(GameTime gameTime)
        {
            if (saveScores == true)
            {
                saveScores = false;

                //save score into the list of highscores
                highscores.Add(new User(username, score));
                //highscores.Insert(0, score);//hint not zero unless its the high score

                //loop thorugh highscores
                //compare score with highscores[i]
                //if score > highscores[i]
                //highscores.Insert(i, score)
                for (int i = 0; i < highscores.Count; i++)
                {
                    for (int j = 0; j < highscores.Count; j++)
                    {
                        if (highscores[i].score > highscores[j].score)
                        {
                            User temp = highscores[i];
                            highscores[i] = highscores[j];
                            highscores[j] = temp;
                        }
                    }
                }

                document.Element("Scores").RemoveAll();

                for (int f = 0; f < highscores.Count; f++)
                {
                    XElement score = new XElement("Score", new XAttribute("name", highscores[f].name));
                    score.Value = highscores[f].score.ToString();

                    document.Element("Scores").Add(score);
                }
                document.Save("HighScores.xml");
            }

            if (ks.IsKeyDown(Keys.R))
            {
                enemies = new List <Enemies>();
                lives   = 2;
                level   = 1;
                rows    = 0;
                cols    = 0;
                score   = 0;
                Spawn();
                SoundEffect laserSound = Content.Load <SoundEffect>("laser1");
                arwing = new ArWing(arwingTexture, bombTexture, laser, new Vector2(100, 825), Color.White, new Vector2(5), laserSound);

                gameState = GameState.Game;
            }

            else if (ks.IsKeyDown(Keys.Q))
            {
                Exit();
            }
        }
Exemple #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            hitboxSprite = Content.Load <Texture2D>("WhitePixel");
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch    = new SpriteBatch(GraphicsDevice);
            enemyImages    = new Texture2D[2];
            enemyImages[0] = Content.Load <Texture2D>("Jaewon");
            enemyImages[1] = Content.Load <Texture2D>("Alex");

            enemies = new List <Enemies>();

            Spawn();

            //enemies.Add(new Enemies(enemiesImage, new Vector2(40, 10), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImageAlex, new Vector2(700, 20), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(800, 10), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(700, 70), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(300,10), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(750, 20), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(670, 207), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(300, 10), Color.White, 5, 5));
            //enemies.Add(new Enemies(enemiesImage, new Vector2(720, 20), Color.White, 5, 5));

            arwingTexture = Content.Load <Texture2D>("arwing");
            laser         = Content.Load <Texture2D>("Laser");
            bombTexture   = Content.Load <Texture2D>("plasma1");
            scoreFont     = Content.Load <SpriteFont>("Scorefont");
            SpriteFont keyFont = Content.Load <SpriteFont>("KeyboardFont");
            Texture2D  keyTex  = Content.Load <Texture2D>("key");

            SoundEffect laserSound = Content.Load <SoundEffect>("laser1");

            arwing     = new ArWing(arwingTexture, bombTexture, laser, new Vector2(100, 825), Color.White, new Vector2(5), laserSound);
            background = Content.Load <Texture2D>("SpaceBackground");
            GameOver   = Content.Load <Texture2D>("GameOver");
            ScoreBoard = Content.Load <Texture2D>("leaderboard");
            KeyBoard   = Content.Load <Texture2D>("keyboard-aplhabet");
            GameOverD  = new Sprite(GameOver, Vector2.Zero, Color.White);
            space      = new Sprite(background, Vector2.Zero, Color.White);
            scoreBoard = new Sprite(ScoreBoard, new Vector2(1300, 30), Color.White);
            keyBoard   = new Sprite(KeyBoard, new Vector2(700, 200), Color.White);
            // TODO: use this.Content to load your game content here

            document = XDocument.Load("HighScores.xml");
            //load attribute here
            foreach (XElement score in document.Elements("Scores").Elements("Score"))
            {
                string name = score.Attribute("name").Value;

                int number = int.Parse(score.Value);

                highscores.Add(new User(name, number));
            }

            keyPadKeys = new List <KeyPadKey>();

            //create a y position that starts at the top of the keypad
            int xPos = 200;
            int yPos = 200;

            int xOff;
            int yOff;

            for (int i = 0; i < 26; i++)
            {
                xOff = i % 7 * 76;
                yOff = i / 7 * 76;

                string value = char.ConvertFromUtf32(i + 65);
                keyPadKeys.Add(new KeyPadKey(keyTex, new Vector2(xPos + xOff, yPos + yOff), Color.Black, value, keyFont));
                //add a new KeyPadKey to the list keyPadKeys
                //the new KeyPadKey's new Rectangle's x position will be at the left most x + i % 7 * 77
                //the y position will be added by 77 every 7 rectangles
                //the letter for each KeyPadKey will be a new char with a value of 65 + i\
            }

            //add a new keypadkey to the list
            keyPadKeys.Add(new KeyPadKey(keyTex, new Vector2(xPos + 380, yPos + 282), Color.Black, "DEL", keyFont));

            gameState = GameState.Login;
        }