Beispiel #1
0
        /// <summary>
        /// Updates items depending on state
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="game"></param>
        public void Update(GameTime gameTime, Main game)
        {
            switch (CurrentState)
            {
            case GameState.Intro:
                intro.Update(gameTime);
                if (intro.Exit)
                {
                    CurrentState = GameState.MainMenu;
                }
                break;

            case GameState.MainMenu:
                mainMenu.Update(gameTime, game);
                currentSong = 1;
                if (mainMenu.ButtonClicked("New Game"))
                {
                    noSaveFound = false;
                    player.ResetPlayer();                                   // resets all stats and attributes
                    solarSystem1.ResetSolarSystem(1);
                    solarSystem2.ResetSolarSystem(2);
                    solarSystem3.ResetSolarSystem(3);
                    combat.Reset(this);
                    CurrentState = GameState.Level1;
                }
                else if (mainMenu.ButtonClicked("Load Game"))               // calls Save functionality to load back a saved game state
                {
                    if (thisGame.loadGame())
                    {
                        player = thisGame.Player;
                        SolarSystem[] restore = thisGame.SolarSystems;      // retrieves the array of all 3 solar systems
                        solarSystem1 = restore[0];
                        solarSystem2 = restore[1];
                        solarSystem3 = restore[2];
                        thisGame.updateSaveParams(player, solarSystem1, solarSystem2, solarSystem3);
                        CurrentState = GameState.Level1;
                    }
                    else
                    {
                        noSaveFound = true;
                    }
                }
                else if (mainMenu.ButtonClicked("Help"))
                {
                    noSaveFound   = false;
                    mainMenu.Help = true;
                    if (mainMenu.Help)
                    {
                        controls.BackClicked = false;
                        CurrentState         = GameState.Help;
                    }
                }
                else if (mainMenu.ButtonClicked("Exit"))
                {
                    noSaveFound = false;
                    game.Exit();
                }
                break;

            case GameState.Help:
                controls.Update();
                if (controls.BackClicked)
                {
                    CurrentState = GameState.MainMenu;
                }
                break;

            case GameState.Level1:
                solarSystem1.Update(gameTime, game.Content);
                currentSolarSystem = solarSystem1;
                currentSong        = 1;  // sets this to be the current solar system
                SolarSystemTestModeUpdate(1, smallerFont);
                if (solarSystem1.CombatMode)
                {
                    combat = new Combat(solarSystem1.SelectedPlanet, player, graphics);
                    combat.LoadContent(game.Content);
                    solarSystem1.CombatMode = false;
                    combat.Reset(this);
                    if (solarSystem1.SelectedPlanet.Conquered)
                    {
                        combat.Victory = true;
                    }
                    CurrentState = GameState.Combat;
                }
                break;

            case GameState.Level2:
                solarSystem2.Update(gameTime, game.Content);
                currentSong        = 1;
                currentSolarSystem = solarSystem2;
                SolarSystemTestModeUpdate(2, smallerFont);
                if (solarSystem2.CombatMode)
                {
                    combat = new Combat(solarSystem2.SelectedPlanet, player, graphics);
                    combat.LoadContent(game.Content);
                    solarSystem2.CombatMode = false;
                    combat.Reset(this);
                    if (solarSystem2.SelectedPlanet.Conquered)
                    {
                        combat.Victory = true;
                    }
                    CurrentState = GameState.Combat;
                }
                break;

            case GameState.Level3:
                solarSystem3.Update(gameTime, game.Content);
                currentSong        = 1;
                currentSolarSystem = solarSystem3;
                SolarSystemTestModeUpdate(3, smallerFont);
                if (solarSystem3.CombatMode)
                {
                    combat = new Combat(solarSystem3.SelectedPlanet, player, graphics);
                    combat.LoadContent(game.Content);
                    solarSystem3.CombatMode = false;
                    combat.Reset(this);
                    if (solarSystem3.SelectedPlanet.Conquered)
                    {
                        combat.Victory = true;
                    }
                    CurrentState = GameState.Combat;
                }
                break;

            case GameState.Combat:
                currentSong = 2;
                combat.Update(this, gameTime, game.Content);
                if (quitCombat && combat.Planet.Level == 1)
                {
                    CurrentState = GameState.Level1;
                }
                if (quitCombat && combat.Planet.Level == 2)
                {
                    CurrentState = GameState.Level2;
                }
                if (quitCombat && combat.Planet.Level == 3)
                {
                    CurrentState = GameState.Level3;
                }
                break;

            case GameState.Shop:
                shop.Update(gameTime, game.Content);
                if (shop.backButtonClicked())
                {
                    CurrentState = GameState.Level1;
                }
                else if (shop.EscapePressed())
                {
                    CurrentState = GameState.Shop;
                }
                SolarSystemTestModeUpdate(4, smallerFont);
                break;
            }
        }
Beispiel #2
0
        public bool loadGame()
        {
            const int USER_OFFSET = 3, SOLARSYSTEM_OFFSET = 4;          // constant offsets used for reading; stored for ease of reading

            try
            {
                string loadData = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\savefile.txt");

                int uStart, s1Start, s2Start, s3Start;  // starting indexes of each of the 4 save sections
                uStart  = loadData.IndexOf("u") + 1;    // +1 to account for colon
                s1Start = loadData.IndexOf("s1") + 2;
                s2Start = loadData.IndexOf("s2") + 2;
                s3Start = loadData.IndexOf("s3") + 2;

                string   temp     = loadData.Substring(uStart + 1, ((s1Start - USER_OFFSET) - uStart));
                string[] userData = temp.Split(new Char[] { ',', '.' });     // delimits for commas and terminating full stops
                p.Enfinitum = Convert.ToInt32(userData[0]);
                p.Credits   = Convert.ToInt32(userData[1]);
                int type = Convert.ToInt32(userData[2]);
                if (type == 1)
                {
                    p.Ship.Name = "Fighter";
                }
                else if (type == 2)
                {
                    p.Ship.Name = "Corvette";
                }
                else
                {
                    p.Ship.Name = "Destroyer";
                }
                p.Ship.Attack      = Convert.ToInt32(userData[3]);
                p.Ship.Defense     = Convert.ToInt32(userData[4]);
                p.PlanetsConquered = Convert.ToInt32(userData[5]);

                SolarSystem[] solarArray       = new SolarSystem[] { s1, s2, s3 };
                int[]         solarStartPoints = new int[] { s1Start, s2Start, s3Start, loadData.Length };
                string[]      currentSolarData = new string[] { };
                for (int i = 0; i < solarArray.Length; i++)     // iterates through every planet in all 3 solar systems
                {
                    temp = loadData.Substring(solarStartPoints[i] + 1,
                                              ((solarStartPoints[i + 1] - SOLARSYSTEM_OFFSET) - solarStartPoints[i]));
                    currentSolarData = temp.Split(new Char[] { ',', '.' });
                    for (int j = 1; j < currentSolarData.Length; j++)
                    {
                        if (Convert.ToInt32(currentSolarData[j - 1]) == 0)
                        {
                            solarArray[i].Planets[j].Conquered = true;
                            solarArray[i].Planets[j].Defences  = 0;
                            solarArray[i].Planets[j].Enfinitum = 0;
                            solarArray[i].Planets[j].Credits   = 0;
                            solarArray[i].Planets[j].calculateChance();
                        }
                        else
                        {
                            solarArray[i].Planets[j].Conquered = false;
                        }
                    }
                }
            }
            catch (FileNotFoundException fnf)
            {
                // ERROR
                return(false);
            }
            return(true);
        }