public static void SaveGame() { FromSaveGameState = FromSaveGame.NEWGAME; #region Save Game Data // simplfying data HeroAttribute tempHeroAttribute = mHero.HeroAttribute; FriendlyAttribute tempWolfAttribute = FriendlyPool[0].FriendlyAttribute; FriendlyAttribute tempBerserkerAttribute = FriendlyPool[1].FriendlyAttribute; FriendlyAttribute tempArcaneMageAttribute = FriendlyPool[2].FriendlyAttribute; FriendlyAttribute tempAxeThrowerAttribute = FriendlyPool[3].FriendlyAttribute; FriendlyAttribute tempClericAttribute = FriendlyPool[4].FriendlyAttribute; FriendlyAttribute tempNecromancerAttribute = FriendlyPool[5].FriendlyAttribute; FriendlyAttribute tempFireMageAttribute = FriendlyPool[6].FriendlyAttribute; FriendlyAttribute tempDragonAttribute = FriendlyPool[7].FriendlyAttribute; saveGameData = new SaveGameData() { mWaveNumber = WaveController.WaveNumber, // HeroAttribute data mExperience = tempHeroAttribute.Experience, mGold = tempHeroAttribute.Gold, mLevel = tempHeroAttribute.Level, mHeroMaxMana = tempHeroAttribute.Mana, mDefaultSpeed = tempHeroAttribute.DefaultSpeed, mSpellLevel = tempHeroAttribute.SpellLevel, mHeroAttackUpgradeLevel = tempHeroAttribute.AttackUpgradeLevel, mHeroDefenseUpgradeLevel = tempHeroAttribute.DefenseUpgradeLevel, mOwnedDragonCaves = tempHeroAttribute.OwnedDragonCaves, mOwnedWolfPens = tempHeroAttribute.OwnedWolfPens, mOwnedBarracks = tempHeroAttribute.OwnedBarracks, mOwnedArmories = tempHeroAttribute.OwnedArmories, mOwnedLibraries = tempHeroAttribute.OwnedLibraries, mOwnedBonePit = tempHeroAttribute.OwnedBonePit, mOwnedAbbey = tempHeroAttribute.OwnedAbbey, mOwnedFireTemple = tempHeroAttribute.OwnedFireTemple, // Hero's Attribute data mHeroMaxHealthPoints = tempHeroAttribute.MaxHealthPoints, mHeroBaseMinimumDamage = tempHeroAttribute.BaseMinimumDamage, mHeroBaseMaximumDamage = tempHeroAttribute.BaseMaximumDamage, mHeroCurrentArmor = tempHeroAttribute.CurrentArmor, // Wolf's data mWolfAttackSpeed = tempWolfAttribute.AttackSpeed, mWolfAttackUpgradeLevel = tempWolfAttribute.AttackUpgradeLevel, mWolfDefenseUpgradeLevel = tempWolfAttribute.DefenseUpgradeLevel, // Wolf's Attribute data mWolfMaxHealthPoints = tempWolfAttribute.MaxHealthPoints, mWolfBaseMinimumDamage = tempWolfAttribute.BaseMinimumDamage, mWolfBaseMaximumDamage = tempWolfAttribute.BaseMaximumDamage, mWolfCurrentArmor = tempWolfAttribute.CurrentArmor, // Berserker's data mBerserkerAttackSpeed = tempBerserkerAttribute.AttackSpeed, mBerserkerAttackUpgradeLevel = tempBerserkerAttribute.AttackUpgradeLevel, mBerserkerDefenseUpgradeLevel = tempBerserkerAttribute.DefenseUpgradeLevel, // Berserker's Attribute data mBerserkerMaxHealthPoints = tempBerserkerAttribute.MaxHealthPoints, mBerserkerBaseMinimumDamage = tempBerserkerAttribute.BaseMinimumDamage, mBerserkerBaseMaximumDamage = tempBerserkerAttribute.BaseMaximumDamage, mBerserkerCurrentArmor = tempBerserkerAttribute.CurrentArmor, // Axe Thrower's data mAxeThrowerAttackSpeed = tempAxeThrowerAttribute.AttackSpeed, mAxeThrowerAttackUpgradeLevel = tempArcaneMageAttribute.AttackUpgradeLevel, mAxeThrowerDefenseUpgradeLevel = tempArcaneMageAttribute.DefenseUpgradeLevel, // Axe Thrower's Attribute data mAxeThrowerMaxHealthPoints = tempArcaneMageAttribute.MaxHealthPoints, mAxeThrowerBaseMinimumDamage = tempArcaneMageAttribute.BaseMinimumDamage, mAxeThrowerBaseMaximumDamage = tempArcaneMageAttribute.BaseMaximumDamage, mAxeThrowerCurrentArmor = tempArcaneMageAttribute.CurrentArmor, // Arcane Mage's data mArcaneMageAttackSpeed = tempArcaneMageAttribute.AttackSpeed, mArcaneMageAttackUpgradeLevel = tempAxeThrowerAttribute.AttackUpgradeLevel, mArcaneMageDefenseUpgradeLevel = tempAxeThrowerAttribute.DefenseUpgradeLevel, // Arcane Mage's Attribute data mArcaneMageMaxHealthPoints = tempAxeThrowerAttribute.MaxHealthPoints, mArcaneMageBaseMinimumDamage = tempAxeThrowerAttribute.BaseMinimumDamage, mArcaneMageBaseMaximumDamage = tempAxeThrowerAttribute.BaseMaximumDamage, mArcaneMageCurrentArmor = tempAxeThrowerAttribute.CurrentArmor, // Cleric's data mClericAttackSpeed = tempClericAttribute.AttackSpeed, mClericAttackUpgradeLevel = tempClericAttribute.AttackUpgradeLevel, mClericDefenseUpgradeLevel = tempClericAttribute.DefenseUpgradeLevel, // Cleric's Attribute data mClericBaseMinimumDamage = tempClericAttribute.CurrentMinimumDamage, mClericBaseMaximumDamage = tempClericAttribute.CurrentMaximumDamage, mClericCurrentArmor = tempClericAttribute.CurrentArmor, // Necromancer's data mNecromancerAttackSpeed = tempNecromancerAttribute.AttackSpeed, mNecromancerAttackUpgradeLevel = tempNecromancerAttribute.AttackUpgradeLevel, mNecromancerDefenseUpgradeLevel = tempNecromancerAttribute.DefenseUpgradeLevel, // Necromancer's Attribute data mNecromancerMaxHealthPoints = tempNecromancerAttribute.MaxHealthPoints, mNecromancerBaseMinimumDamage = tempNecromancerAttribute.BaseMinimumDamage, mNecromancerBaseMaximumDamage = tempNecromancerAttribute.BaseMaximumDamage, mNecromancerCurrentArmor = tempNecromancerAttribute.CurrentArmor, // Fire Mage's data mFireMageAttackSpeed = tempFireMageAttribute.AttackSpeed, mFireMageAttackUpgradeLevel = tempFireMageAttribute.AttackUpgradeLevel, mFireMageDefenseUpgradeLevel = tempFireMageAttribute.DefenseUpgradeLevel, // Fire Mage's Attribute data mFireMageMaxHealthPoints = tempFireMageAttribute.MaxHealthPoints, mFireMageBaseMinimumDamage = tempFireMageAttribute.BaseMinimumDamage, mFireMageBaseMaximumDamage = tempFireMageAttribute.BaseMaximumDamage, mFireMageCurrentArmor = tempFireMageAttribute.CurrentArmor, // Dragon's data mDragonAttackSpeed = tempDragonAttribute.AttackSpeed, mDragonAttackUpgradeLevel = tempDragonAttribute.AttackUpgradeLevel, mDragonDefenseUpgradeLevel = tempDragonAttribute.DefenseUpgradeLevel, // Fire Mage's Attribute data mDragonMaxHealthPoints = tempDragonAttribute.MaxHealthPoints, mDragonBaseMinimumDamage = tempDragonAttribute.BaseMinimumDamage, mDragonBaseMaximumDamage = tempDragonAttribute.BaseMaximumDamage, mDragonCurrentArmor = tempDragonAttribute.CurrentArmor }; #endregion using (Stream stream = storageContainer.CreateFile(filename)) { XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); serializer.Serialize(stream, saveGameData); } }
public static void LoadSaveGame() { if (!storageContainer.FileExists(filename)) { FromSaveGameState = FromSaveGame.NEWGAME; #region Default Save Game Data saveGameData = new SaveGameData() { mWaveNumber = 1, // HeroAttribute data mExperience = 0, mGold = 1000, mLevel = 1, mDefaultSpeed = 4, mSpellLevel = 1, mHeroAttackUpgradeLevel = 1, mHeroDefenseUpgradeLevel = 1, mOwnedDragonCaves = 0, mOwnedWolfPens = 0, mOwnedBarracks = 0, mOwnedArmories = 0, mOwnedLibraries = 0, mOwnedBonePit = 0, mOwnedAbbey = 0, mOwnedFireTemple = 0, // Hero's Attribute data mHeroMaxHealthPoints = 150, mHeroMaxMana = 40, mHeroBaseMinimumDamage = 55, mHeroBaseMaximumDamage = 86, mHeroCurrentArmor = 4, // Wolf's data mWolfAttackUpgradeLevel = 1, mWolfDefenseUpgradeLevel = 1, mWolfAttackSpeed = 1000, // Wolf's Attribute data mWolfMaxHealthPoints = 60, mWolfBaseMinimumDamage = 10, mWolfBaseMaximumDamage = 15, mWolfBaseDamageModifier = (10 + 15) / 2.0f, mWolfCurrentArmor = 1, // Berserker's data mBerserkerAttackUpgradeLevel = 1, mBerserkerDefenseUpgradeLevel = 1, mBerserkerAttackSpeed = 1100, // Berserker's Attribute data mBerserkerMaxHealthPoints = 120, mBerserkerBaseMinimumDamage = 30, mBerserkerBaseMaximumDamage = 55, mBerserkerBaseDamageModifier = (33 + 55) / 2.0f, mBerserkerCurrentArmor = 1, // Axe Thrower's data mAxeThrowerAttackUpgradeLevel = 1, mAxeThrowerDefenseUpgradeLevel = 1, mAxeThrowerAttackSpeed = 1200, // Axe Thrower's Attribute data mAxeThrowerMaxHealthPoints = 230, mAxeThrowerBaseMinimumDamage = 3, mAxeThrowerBaseMaximumDamage = 10, mAxeThrowerBaseDamageModifier = (13 / 2.0f), mAxeThrowerCurrentArmor = 1, // Arcane Mage's data mArcaneMageAttackUpgradeLevel = 1, mArcaneMageDefenseUpgradeLevel = 1, mArcaneMageAttackSpeed = 2300, // Arcane Mage's Attribute data mArcaneMageMaxHealthPoints = 180, mArcaneMageBaseMinimumDamage = 60, mArcaneMageBaseMaximumDamage = 80, mArcaneMageBaseDamageModifier = 140 / 2.0f, mArcaneMageCurrentArmor = 1, // Cleric's data mClericAttackUpgradeLevel = 1, mClericDefenseUpgradeLevel = 1, mClericAttackSpeed = 4000, // Cleric's Attribute data mClericMaxHealthPoints = 300, mClericBaseMinimumDamage = 10, mClericBaseMaximumDamage = 30, mClericBaseDamageModifier = 40 / 2.0f, mClericCurrentArmor = 1, // Necromancer's data mNecromancerAttackUpgradeLevel = 1, mNecromancerDefenseUpgradeLevel = 1, mNecromancerAttackSpeed = 2800, // Necromancer's Attribute data mNecromancerMaxHealthPoints = 300, mNecromancerBaseMinimumDamage = 15, mNecromancerBaseMaximumDamage = 35, mNecromancerBaseDamageModifier = 50 / 2.0f, mNecromancerCurrentArmor = 1, // Fire Mage's data mFireMageAttackUpgradeLevel = 1, mFireMageDefenseUpgradeLevel = 1, mFireMageAttackSpeed = 2300, // Fire Mage's Attribute data mFireMageMaxHealthPoints = 180, mFireMageBaseMinimumDamage = 60, mFireMageBaseMaximumDamage = 80, mFireMageBaseDamageModifier = 140 / 2.0f, mFireMageCurrentArmor = 1, // Dragon's data mDragonAttackUpgradeLevel = 1, mDragonDefenseUpgradeLevel = 1, mDragonAttackSpeed = 40000, // Fire Mage's Attribute data mDragonMaxHealthPoints = 700, mDragonBaseMinimumDamage = 275, mDragonBaseMaximumDamage = 300, mDragonBaseDamageModifier = (275 + 300) / 2.0f, mDragonCurrentArmor = 1 }; #endregion } else { Stream stream = storageContainer.OpenFile(filename, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); saveGameData = (SaveGameData)serializer.Deserialize(stream); stream.Close(); storageContainer.Dispose(); storageContainer = null; FromSaveGameState = FromSaveGame.SAVEGAME; #region Load Save Game Data // simplfying data HeroAttribute tempHeroAttribute = mHero.HeroAttribute; FriendlyAttribute tempWolfAttribute = FriendlyPool[0].FriendlyAttribute; FriendlyAttribute tempBerserkerAttribute = FriendlyPool[1].FriendlyAttribute; FriendlyAttribute tempArcaneMageAttribute = FriendlyPool[2].FriendlyAttribute; FriendlyAttribute tempAxeThrowerAttribute = FriendlyPool[3].FriendlyAttribute; FriendlyAttribute tempClericAttribute = FriendlyPool[4].FriendlyAttribute; FriendlyAttribute tempNecromancerAttribute = FriendlyPool[5].FriendlyAttribute; FriendlyAttribute tempFireMageAttribute = FriendlyPool[6].FriendlyAttribute; FriendlyAttribute tempDragonAttribute = FriendlyPool[7].FriendlyAttribute; WaveController.WaveNumber = saveGameData.mWaveNumber; // HeroAttribute data tempHeroAttribute.Experience = saveGameData.mExperience; tempHeroAttribute.Gold = saveGameData.mGold; tempHeroAttribute.Level = saveGameData.mLevel; tempHeroAttribute.MaxMana = saveGameData.mHeroMaxMana; tempHeroAttribute.DefaultSpeed = saveGameData.mDefaultSpeed; tempHeroAttribute.SpellLevel = saveGameData.mSpellLevel; tempHeroAttribute.AttackUpgradeLevel = saveGameData.mHeroAttackUpgradeLevel; tempHeroAttribute.DefenseUpgradeLevel = saveGameData.mHeroDefenseUpgradeLevel; tempHeroAttribute.OwnedDragonCaves = saveGameData.mOwnedDragonCaves; tempHeroAttribute.OwnedWolfPens = saveGameData.mOwnedWolfPens; tempHeroAttribute.OwnedBarracks = saveGameData.mOwnedBarracks; tempHeroAttribute.OwnedArmories = saveGameData.mOwnedArmories; tempHeroAttribute.OwnedLibraries = saveGameData.mOwnedLibraries; tempHeroAttribute.OwnedBonePit = saveGameData.mOwnedBonePit; tempHeroAttribute.OwnedAbbey = saveGameData.mOwnedAbbey; tempHeroAttribute.OwnedFireTemple = saveGameData.mOwnedFireTemple; // Hero's Attribute data tempHeroAttribute.MaxHealthPoints = saveGameData.mHeroMaxHealthPoints; tempHeroAttribute.BaseMinimumDamage = saveGameData.mHeroBaseMinimumDamage; tempHeroAttribute.BaseMaximumDamage = saveGameData.mHeroBaseMaximumDamage; tempHeroAttribute.CurrentArmor = saveGameData.mHeroCurrentArmor; // Wolf's data tempWolfAttribute.AttackSpeed = saveGameData.mWolfAttackSpeed; tempWolfAttribute.AttackUpgradeLevel = saveGameData.mWolfAttackUpgradeLevel; tempWolfAttribute.DefenseUpgradeLevel = saveGameData.mWolfDefenseUpgradeLevel; // Wolf's Attribute data tempWolfAttribute.MaxHealthPoints = saveGameData.mWolfMaxHealthPoints; tempWolfAttribute.BaseMinimumDamage = saveGameData.mWolfBaseMinimumDamage; tempWolfAttribute.BaseMaximumDamage = saveGameData.mWolfBaseMaximumDamage; tempWolfAttribute.CurrentArmor = saveGameData.mWolfCurrentArmor; //Berserker's data tempBerserkerAttribute.AttackSpeed = saveGameData.mBerserkerAttackSpeed; tempBerserkerAttribute.AttackUpgradeLevel = saveGameData.mBerserkerAttackUpgradeLevel; tempBerserkerAttribute.DefenseUpgradeLevel = saveGameData.mBerserkerDefenseUpgradeLevel; //Berserker's Attribute data tempBerserkerAttribute.MaxHealthPoints = saveGameData.mBerserkerMaxHealthPoints; tempBerserkerAttribute.BaseMinimumDamage = saveGameData.mBerserkerBaseMinimumDamage; tempBerserkerAttribute.BaseMaximumDamage = saveGameData.mBerserkerBaseMaximumDamage; tempBerserkerAttribute.CurrentArmor = saveGameData.mBerserkerCurrentArmor; //Axe Thrower's Data tempAxeThrowerAttribute.AttackSpeed = saveGameData.mAxeThrowerAttackSpeed; tempAxeThrowerAttribute.AttackUpgradeLevel = saveGameData.mAxeThrowerAttackUpgradeLevel; tempAxeThrowerAttribute.DefenseUpgradeLevel = saveGameData.mAxeThrowerDefenseUpgradeLevel; //Axe Thrower's Attribute data tempAxeThrowerAttribute.MaxHealthPoints = saveGameData.mAxeThrowerMaxHealthPoints; tempAxeThrowerAttribute.BaseMinimumDamage = saveGameData.mAxeThrowerBaseMinimumDamage; tempAxeThrowerAttribute.BaseMaximumDamage = saveGameData.mAxeThrowerBaseMaximumDamage; tempAxeThrowerAttribute.CurrentArmor = saveGameData.mAxeThrowerCurrentArmor; //Arcane Mage's data tempArcaneMageAttribute.AttackSpeed = saveGameData.mArcaneMageAttackSpeed; tempArcaneMageAttribute.AttackUpgradeLevel = saveGameData.mArcaneMageAttackUpgradeLevel; tempArcaneMageAttribute.DefenseUpgradeLevel = saveGameData.mArcaneMageDefenseUpgradeLevel; //Arcane Mage's Attribute data tempArcaneMageAttribute.MaxHealthPoints = saveGameData.mArcaneMageMaxHealthPoints; tempArcaneMageAttribute.BaseMinimumDamage = saveGameData.mArcaneMageBaseMinimumDamage; tempArcaneMageAttribute.BaseMaximumDamage = saveGameData.mArcaneMageBaseMaximumDamage; tempArcaneMageAttribute.CurrentArmor = saveGameData.mArcaneMageCurrentArmor; //Cleric's data tempClericAttribute.AttackSpeed = saveGameData.mClericAttackSpeed; tempClericAttribute.AttackUpgradeLevel = saveGameData.mClericAttackUpgradeLevel; tempClericAttribute.DefenseUpgradeLevel = saveGameData.mClericDefenseUpgradeLevel; //Cleric's Attributes data tempClericAttribute.MaxHealthPoints = saveGameData.mClericMaxHealthPoints; tempClericAttribute.BaseMinimumDamage = saveGameData.mClericBaseMinimumDamage; tempClericAttribute.BaseMaximumDamage = saveGameData.mClericBaseMaximumDamage; tempClericAttribute.CurrentArmor = saveGameData.mClericCurrentArmor; //Necromancer's data tempNecromancerAttribute.AttackSpeed = saveGameData.mNecromancerAttackSpeed; tempNecromancerAttribute.AttackUpgradeLevel = saveGameData.mNecromancerAttackUpgradeLevel; tempNecromancerAttribute.DefenseUpgradeLevel = saveGameData.mNecromancerDefenseUpgradeLevel; //Necromancer's Attribute data tempNecromancerAttribute.MaxHealthPoints = saveGameData.mNecromancerMaxHealthPoints; tempNecromancerAttribute.BaseMinimumDamage = saveGameData.mNecromancerBaseMinimumDamage; tempNecromancerAttribute.BaseMaximumDamage = saveGameData.mNecromancerBaseMaximumDamage; tempNecromancerAttribute.CurrentArmor = saveGameData.mNecromancerCurrentArmor; //Fire Mage's data tempFireMageAttribute.AttackSpeed = saveGameData.mFireMageAttackSpeed; tempFireMageAttribute.AttackUpgradeLevel = saveGameData.mFireMageAttackUpgradeLevel; tempFireMageAttribute.DefenseUpgradeLevel = saveGameData.mFireMageDefenseUpgradeLevel; //Fire Mage's Attribute data tempFireMageAttribute.MaxHealthPoints = saveGameData.mFireMageMaxHealthPoints; tempFireMageAttribute.BaseMinimumDamage = saveGameData.mFireMageBaseMinimumDamage; tempFireMageAttribute.BaseMaximumDamage = saveGameData.mFireMageBaseMaximumDamage; tempFireMageAttribute.CurrentArmor = saveGameData.mFireMageCurrentArmor; //Dragon's data tempDragonAttribute.AttackSpeed = saveGameData.mDragonAttackSpeed; tempDragonAttribute.AttackUpgradeLevel = saveGameData.mDragonAttackUpgradeLevel; tempDragonAttribute.DefenseUpgradeLevel = saveGameData.mDragonDefenseUpgradeLevel; //Dragon's Attribute data tempDragonAttribute.MaxHealthPoints = saveGameData.mDragonMaxHealthPoints; tempDragonAttribute.BaseMinimumDamage = saveGameData.mDragonBaseMinimumDamage; tempDragonAttribute.BaseMaximumDamage = saveGameData.mDragonBaseMaximumDamage; tempDragonAttribute.CurrentArmor = saveGameData.mDragonCurrentArmor; #endregion } }