Exemple #1
0
        /// <summary>
        /// Inicjalizuje pliki odpowiedzialne za zapisywanie gry i najlepszych wynikow.
        /// </summary>
        private void initFile()
        {
            string fullpath = "highscores.dat";

            if (!File.Exists(fullpath))
            {
                //If the file doesn't exist, make a fake one...
                // Create the data to save
                data = new HighScores();
                data.Players.Add(new Score {
                    name = "neil", score = 5000
                });
                data.Players.Add(new Score {
                    name = "shawn", score = 4500
                });
                data.Players.Add(new Score {
                    name = "mark", score = 4000
                });
                data.Players.Add(new Score {
                    name = "cindy", score = 3500
                });
                data.Players.Add(new Score {
                    name = "sam", score = 3000
                });
                data.Players.Add(new Score {
                    name = "neil", score = 2500
                });
                data.Players.Add(new Score {
                    name = "shawn", score = 2000
                });
                data.Players.Add(new Score {
                    name = "mark", score = 1500
                });
                data.Players.Add(new Score {
                    name = "cindy", score = 1000
                });
                data.Players.Add(new Score {
                    name = "sam", score = 500
                });
                HighScores.SaveHighScores(data);
            }
            loadScore();
            fullpath = "mysave.dat";
            if (!File.Exists(fullpath))
            {
                LoadGame.SaveGame(new SaveGame {
                    currlevel = 1, currLife = 3, currpoint = 0
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            MouseState mouse = Mouse.GetState();

            switch (CurrentGameState)
            {
            case GameState.MainMenu:
                if (Button[Buttons.btnPlay].isClicked)
                {
                    CurrentGameState = GameState.Difficulty;
                }
                if (Button[Buttons.btnExit].isClicked)
                {
                    this.Exit();
                }
                if (Button[Buttons.btnHightScores].isClicked)
                {
                    CurrentGameState = GameState.HighScore;
                }
                if (Button[Buttons.btnHelp].isClicked)
                {
                    CurrentGameState = GameState.Help;
                }
                if (Button[Buttons.btnLoadGame].isClicked)
                {
                    CurrentGameState = GameState.Load;
                }
                Button[Buttons.btnLoadGame].Update(mouse);
                Button[Buttons.btnPlay].Update(mouse);
                Button[Buttons.btnHelp].Update(mouse);
                Button[Buttons.btnHightScores].Update(mouse);
                Button[Buttons.btnExit].Update(mouse);
                break;

            case GameState.Playing:
                oLogic.Update(gameTime);
                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    LoadGame.SaveGame(new SaveGame {
                        currpoint = oLogic.StartPoints, currlevel = Logic.numLevel, currLife = 3 - counter
                    });
                    CurrentGameState = GameState.MainMenu;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    CurrentGameState = GameState.Pause;
                }
                break;

            case GameState.Difficulty:
                if (Button[Buttons.btnBack].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                if (Button[Buttons.btnEasy].isClicked)
                {
                    oLogic.startLevel();
                    CurrentGameState = GameState.Playing;
                }
                if (Button[Buttons.btnMedium].isClicked)
                {
                    Logic.numLevel += 5;
                    oLogic.startLevel();
                    CurrentGameState = GameState.Playing;
                }
                if (Button[Buttons.btnHard].isClicked)
                {
                    Logic.numLevel += 10;
                    oLogic.startLevel();
                    CurrentGameState = GameState.Playing;
                }
                Button[Buttons.btnHard].Update(mouse);
                Button[Buttons.btnMedium].Update(mouse);
                Button[Buttons.btnEasy].Update(mouse);
                Button[Buttons.btnBack].Update(mouse);
                break;

            case GameState.HighScore:
                if (Button[Buttons.btnBack].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                Button[Buttons.btnBack].Update(mouse);
                break;

            case GameState.Help:
                if (Button[Buttons.btnBack].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                Button[Buttons.btnBack].Update(mouse);

                break;

            case GameState.Pause:
                if (Button[Buttons.btnBackPause].isClicked)
                {
                    CurrentGameState = GameState.Playing;
                }
                if (Button[Buttons.btnExitPause].isClicked)
                {
                    LoadGame.SaveGame(new SaveGame {
                        currpoint = oLogic.StartPoints, currlevel = Logic.numLevel, currLife = 3 - counter
                    });
                    CurrentGameState = GameState.MainMenu;
                }
                Button[Buttons.btnExitPause].Update(mouse);
                Button[Buttons.btnBackPause].Update(mouse);
                break;

            case GameState.Load:
                var data2 = LoadGame.LoadGames();
                Logic.numLevel = data2.currlevel;
                oLogic.startLevel(data2.currpoint, 3 - data2.currLife);
                CurrentGameState = GameState.Playing;
                CurrentGameState = GameState.Playing;
                break;

            case GameState.WinGame:
                if (!raz)
                {
                    data = data.SaveHighScore(new Score {
                        name = PlayerName, score = oLogic.Points
                    });
                    raz = true;
                }
                if (Button[Buttons.btnPlayWin].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                if (Button[Buttons.btnExitWin].isClicked)
                {
                    this.Exit();
                }
                Button[Buttons.btnPlayWin].Update(mouse);
                Button[Buttons.btnExitWin].Update(mouse);

                break;

            case GameState.Login:
                loginmenu();
                CurrentGameState = GameState.MainMenu;
                break;

            case GameState.Dead:
                if (Button[Buttons.btnMainmenu].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                if (Button[Buttons.btnRepeat].isClicked)
                {
                    var obl = Logic.numLevel;
                    Logic.numLevel = obl;
                    var obpoint = oLogic.StartPoints;
                    counter++;
                    oLogic.startLevel(obpoint, counter);
                    CurrentGameState = GameState.Playing;
                }

                Button[Buttons.btnMainmenu].Update(mouse);
                Button[Buttons.btnRepeat].Update(mouse);
                break;

            case GameState.Loss:
                if (!raz)
                {
                    data = data.SaveHighScore(new Score {
                        name = PlayerName, score = oLogic.Points
                    });
                    raz = true;
                }
                if (Button[Buttons.btnMainmenu].isClicked)
                {
                    CurrentGameState = GameState.MainMenu;
                }
                if (Button[Buttons.btnExitLose].isClicked)
                {
                    this.Exit();
                }
                Button[Buttons.btnMainmenu].Update(mouse);
                Button[Buttons.btnExitLose].Update(mouse);
                break;
            }

            base.Update(gameTime);
        }