Ejemplo n.º 1
0
        /// <summary>
        /// Starts a new game, getting rid of the menu, deleting old saves, and opening up the starting room.
        /// </summary>
        private void StartNewGame()
        {
            if (gameMenu != null)
            {
                gameMenu.Dispose();
                gameMenu = null;
            }

            DeleteSave();

            GameResources.RoomSaves = new List<RoomSaveData>();

            StaticBGM.SwitchMusic("Level");

            currentRoom = new Room("StartRoom", -1);
            player = new Player(gameContent, SaveGame, SwitchRooms, DisplayInfoBox);
            player.Spawn(currentRoom.SpawnLocation);
            gameHUD = new HUD(gameContent, player);
            gameHUD.DisplayRoomName(currentRoom.LongName);

            isPaused = false;
            inGame = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the previously saved game
        /// </summary>
        private void LoadGame()
        {
            try
            {
                currentStorageDevice = GetStorageDevice();
                using (StorageContainer container = GetStorageContainer(currentStorageDevice))
                {
                    using (Stream stream = container.OpenFile("SaveGame.txt", FileMode.Open))
                    {
                        using (StreamReader sr = new StreamReader(stream))
                        {
                            string line = GameResources.getNextDataLine(sr, "#");
                            currentRoom = new Room(line, -1);
                            int playerHealth = int.Parse(GameResources.getNextDataLine(sr, "#"));
                            bool[] playerItems = new bool[int.Parse(GameResources.getNextDataLine(sr, "#"))];
                            for (int i = 0; i < playerItems.Length; i++)
                                playerItems[i] = bool.Parse(GameResources.getNextDataLine(sr, "#"));

                            RoomSaveData[] roomSaves = new RoomSaveData[int.Parse(GameResources.getNextDataLine(sr, "#"))];

                            for (int i = 0; i < roomSaves.Length; i ++)
                            {
                                roomSaves[i].roomName = GameResources.getNextDataLine(sr, "#");
                                bool[] objects = new bool[int.Parse(GameResources.getNextDataLine(sr, "#"))];
                                for (int j = 0; j < objects.Length; j++)
                                    objects[j] = bool.Parse(GameResources.getNextDataLine(sr, "#"));
                                roomSaves[i].objectsAreSpawned = objects;
                            }

                            GameResources.RoomSaves = new List<RoomSaveData>();
                            foreach (RoomSaveData save in roomSaves)
                                GameResources.RoomSaves.Add(save);

                            player = new Player(gameContent, SaveGame, SwitchRooms, DisplayInfoBox);
                            player.Spawn(currentRoom.SpawnLocation);
                            player.LoadSave(playerHealth, playerItems);
                            gameHUD = new HUD(gameContent, player);

                            isPaused = false;
                            inGame = true;

                            sr.Close();
                        }
                    }

                    StaticBGM.SwitchMusic(currentRoom.MusicName);

                }
            }
            catch (FileNotFoundException e)
            {
                System.Diagnostics.Debug.WriteLine("The save file could not be found: " + e.Message);
                StartNewGame();
            }
        }