Esempio n. 1
0
        public bool CheckGameData(int slot, List <String> levelData, List <ItemBox> weapon1Box, List <ItemBox> weapon2Box, List <ItemBox> shield1Box, List <ItemBox> charm1Box)
        {
            StreamReader inputFile;
            bool         checkSuccessful = true;

            try
            {
                inputFile = File.OpenText("SaveGame" + slot.ToString());

                //Put the get items methods in their own class with the weapon factories
                levelData.RemoveAt(slot);
                levelData.Insert(slot, "Level " + inputFile.ReadLine() + "    " + inputFile.ReadLine() + " hitpoints.");
                weapon1Box.ElementAt(slot).ReplaceItem(ItemFactoryContainer.GetWeaponFromID(int.Parse(inputFile.ReadLine())));
                weapon2Box.ElementAt(slot).ReplaceItem(ItemFactoryContainer.GetWeaponFromID(int.Parse(inputFile.ReadLine())));
                shield1Box.ElementAt(slot).ReplaceItem(ItemFactoryContainer.GetShieldFromID(int.Parse(inputFile.ReadLine())));
                charm1Box.ElementAt(slot).ReplaceItem(ItemFactoryContainer.GetCharmFromID(int.Parse(inputFile.ReadLine())));

                inputFile.Close();
            }
            catch
            {
                checkSuccessful = false;
            }
            return(checkSuccessful);
        }
Esempio n. 2
0
        private bool LoadGame(int slot)
        {
            TradeContents = new TradeScreenContents();
            StreamReader inputFile;
            bool         loadSuccessful = true;

            try
            {
                inputFile = File.OpenText("SaveGame" + slot.ToString());

                //TODO: Clean up this code
                //TODO: Saving and loading functions don't match

                TradeContents.Level  = int.Parse(inputFile.ReadLine());
                TradeContents.Health = int.Parse(inputFile.ReadLine());
                //oldHealth = Health;
                //player1.HitPoints = Health;
                TradeContents.Weapon1 = ItemFactoryContainer.GetWeaponFromID(int.Parse(inputFile.ReadLine()));
                //oldWeapon1 = weapon1;
                //player1.Weapon1 = weapon1;
                TradeContents.Weapon2 = ItemFactoryContainer.GetWeaponFromID(int.Parse(inputFile.ReadLine()));
                //oldWeapon2 = weapon2;
                //player1.Weapon2 = weapon2;
                TradeContents.Shield1 = ItemFactoryContainer.GetShieldFromID(int.Parse(inputFile.ReadLine()));
                //oldShield1 = shield1;
                //player1.Shield1 = shield1;
                TradeContents.Charm1 = ItemFactoryContainer.GetCharmFromID(int.Parse(inputFile.ReadLine()));
                //oldCharm1 = charm1;
                //player1.Charm1 = charm1;
                List <Item> items = new List <Item>();
                for (int i = 0; i < 3; i++)
                {
                    switch (int.Parse(inputFile.ReadLine()))
                    {
                    case -1:
                        items.Add(null);
                        inputFile.ReadLine();
                        break;

                    case 0:
                        items.Add(ItemFactoryContainer.GetWeaponFromID(int.Parse(inputFile.ReadLine())));
                        break;

                    case 1:
                        items.Add(ItemFactoryContainer.GetShieldFromID(int.Parse(inputFile.ReadLine())));
                        break;

                    case 2:
                        items.Add(ItemFactoryContainer.GetCharmFromID(int.Parse(inputFile.ReadLine())));
                        break;
                    }
                }

                TradeContents.Item1 = items.ElementAt(0);
                TradeContents.Item2 = items.ElementAt(1);
                TradeContents.Item3 = items.ElementAt(2);

                inputFile.Close();
            }
            catch
            {
                loadSuccessful = false;
            }

            return(loadSuccessful);
        }