示例#1
0
        public void SaveTheLevel()
        {
            List <SaveableBlock> saveableBlocks = new List <SaveableBlock>();

            foreach (Block block in PlayerInventory.Items)
            {
                SaveableBlock sb = new SaveableBlock
                {
                    BlockType = block.BlockType,
                    Stack     = block.Stack,
                    SellValue = block.SellValue
                };
                saveableBlocks.Add(sb);
            }
            SerializationData sData = new SerializationData
            {
                DrillLevel    = PlayerStats.DrillLevel,
                MaxDrillLevel = PlayerStats.MaxDrillLevel,
                Gold          = PlayerStats.Gold,
                AmountOfBombs = PlayerStats.AmountOfBombs,
                Fuel          = PlayerStats.Fuel,
                MaxFuel       = PlayerStats.MaxFuel,
                Health        = PlayerStats.Health,
                MaxHealth     = PlayerStats.MaxHealth,

                TopLevel    = _bigLevelGenerator.TopLevel,
                MidLevel    = _bigLevelGenerator.MidLevel,
                BottomLevel = _bigLevelGenerator.BottomLevel,

                InventoryBlocks = saveableBlocks
            };

            Serializer.Save(InlineStrings.SAVEFILENAME, sData);
        }
示例#2
0
        /// <summary>
        /// Loads the level if a savefile exists. If it doesn't exist start a new game.
        /// </summary>
        private void LoadTheLevel()
        {
            SerializationData sData = Serializer.Load <SerializationData>(InlineStrings.SAVEFILENAME);

            if (sData != null)
            {
                PlayerStats.DrillLevel    = sData.DrillLevel;
                PlayerStats.MaxDrillLevel = sData.DrillLevel;
                PlayerStats.Gold          = sData.Gold;
                PlayerStats.AmountOfBombs = sData.AmountOfBombs;
                PlayerStats.Fuel          = sData.Fuel;
                PlayerStats.MaxFuel       = sData.MaxFuel;
                PlayerStats.Health        = sData.Health;
                PlayerStats.MaxHealth     = sData.MaxHealth;

                _bigLevelGenerator.TopLevel    = sData.TopLevel;
                _bigLevelGenerator.MidLevel    = sData.MidLevel;
                _bigLevelGenerator.BottomLevel = sData.BottomLevel;

                List <Block> inventoryBlocks = new List <Block>();
                foreach (SaveableBlock sb in sData.InventoryBlocks)
                {
                    Block block = new Block
                    {
                        BlockType = sb.BlockType,
                        Stack     = sb.Stack,
                        SellValue = sb.SellValue
                    };
                    inventoryBlocks.Add(block);
                }

                PlayerInventory.Items = inventoryBlocks;

                SaveFileExists = true;
            }
            else
            {
                SaveFileExists            = false;
                PlayerStats.DrillLevel    = _drillLevel;
                PlayerStats.MaxDrillLevel = _drillLevel;
                PlayerStats.Gold          = _gold;
                PlayerStats.AmountOfBombs = _amountOfBombs;
                PlayerStats.MaxFuel       = _fuel;
                PlayerStats.Fuel          = _fuel;
                PlayerStats.Health        = _health;
                PlayerStats.MaxHealth     = _health;
            }

            _drillLevelScript.ChangeDrillLevelIndication();
        }