コード例 #1
0
ファイル: LoadGame.cs プロジェクト: jumpingjak0/Gladius
        private static void LoadInventory(List <string> inventoryItemDetails, List <InventoryItem> tempInventory)
        {
            try
            {
                foreach (string iiDetails in inventoryItemDetails)
                {
                    string[] iiComponents = iiDetails.Split('|');
                    switch (iiComponents[0])
                    {
                    case "Armour":
                    {
                        tempInventory.Add(new InventoryItem(World.ArmourByID(Int32.Parse(iiComponents[1])), Int32.Parse(iiComponents[2])));
                        break;
                    }

                    case "Weapon":
                    {
                        tempInventory.Add(new InventoryItem(World.WeaponByID(Int32.Parse(iiComponents[1])), Int32.Parse(iiComponents[2])));
                        break;
                    }
                    }
                }
                return;
            }
            catch
            {
                loadSuccessfull = false;
                return;
            }
        }
コード例 #2
0
 public Gladiator(string name, string description)
 {
     Name           = name;
     Nickname       = null;
     InPlayersTeam  = false;
     Description    = description;
     EXP            = 0;
     BaseDamage     = 3;
     BaseHP         = 10;
     WeaponEquipped = World.WeaponByID(World.WEAPON_ID_DAGGER);
     ArmourEquipped = World.ArmourByID(World.ARMOUR_ID_RAGS);
     MovementRange  = 3;
     AttackRange    = 1;
     LevelUpGladiator();
 }
コード例 #3
0
 public Gladiator(string name, string nickname, string description, int exp, int weaponID, int ArmourID, int movementRange, int attackRange)
 {
     Name           = name;
     Nickname       = nickname;
     InPlayersTeam  = true;
     Description    = description;
     EXP            = exp;
     BaseDamage     = 3;
     BaseHP         = 10;
     WeaponEquipped = World.WeaponByID(weaponID);
     ArmourEquipped = World.ArmourByID(ArmourID);
     MovementRange  = movementRange;
     AttackRange    = attackRange;
     LevelUpGladiator();
 }
コード例 #4
0
ファイル: Load.cs プロジェクト: Deltaghost55/CSC-153-0001
        public static Player CreatePlayerFromXmlString(string PLAYER_DATA_FILE_NAME)
        {
            try
            {
                XmlDocument playerData = new XmlDocument();

                playerData.LoadXml(PLAYER_DATA_FILE_NAME);
                string playerName = playerData.SelectSingleNode("/Player/Stats/Name").InnerText;
                // Console.WriteLine("Got name: " + playerName);
                string PC = playerData.SelectSingleNode("/Player/Stats/Class").InnerText;
                // Console.WriteLine("Got class: " + PC);
                string PR = playerData.SelectSingleNode("/Player/Stats/Race").InnerText;
                //Console.WriteLine("Got race: " + PR);
                int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
                // Console.WriteLine("Got current hit points: " + currentHitPoints.ToString());
                int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
                // Console.WriteLine("Got max hit points: " + maximumHitPoints.ToString());
                int gold = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
                // Console.WriteLine("Got gold: " + gold.ToString());
                int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
                //Console.WriteLine("Got experience: " + experiencePoints.ToString());
                Factions factionString = (Factions)Enum.Parse(typeof(Factions), (playerData.SelectSingleNode("/Player/Stats/Faction").InnerText), true);
                //Console.WriteLine("Got Faction: " + factionString.ToString());
                int alignment = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Alignment").InnerText);
                //Console.WriteLine("Got Alignment: " + alignment.ToString());
                int     equiptString = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                IWeapon equipt       = World.WeaponByID(equiptString);
                // Console.WriteLine("Got equipt weapon: " + equipt.Name.ToString());

                Player player = new Player(playerName, PC, PR, gold, currentHitPoints, maximumHitPoints, (Weapon)equipt, false, true, factionString, alignment);

                int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
                Player.CurrentLocation = World.LocationByID(currentLocationID);

                if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
                {
                    int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
                    player.Equipt = (Weapon)World.WeaponByID(currentWeaponID);
                }

                foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
                {
                    int id       = Convert.ToInt32(node.Attributes["ID"].Value);
                    int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);

                    if (id > 100 && id <= 200)
                    {
                        for (int i = 0; i < quantity; i++)
                        {
                            player.AddItemToInventory((Weapon)World.WeaponByID(id));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < quantity; i++)
                        {
                            player.AddItemToInventory(World.ItemByID(id));
                        }
                    }
                }

                return(player);
            }
            catch (Exception ex)
            {
                // If there was an error with the XML data, return a default player object
                Console.WriteLine(ex.ToString());
                //return CreateDefaultPlayer();
                return(null);
            }
        }
コード例 #5
0
        public static void CreatePlayerInst()
        {
            string   name;
            string   className    = "";
            string   raceName     = "";
            Factions faction      = Factions.Admin;
            int      alignment    = 0;
            int      gold         = 0;
            int      hp           = 0;
            bool     validRace    = false;
            bool     validClass   = false;
            bool     validFaction = false;


            Console.WriteLine("Give me your name.");
            Console.Write("> ");
            name = CapWord.FirstCharToUpper(Console.ReadLine());

            while (validClass == false)
            {
                Console.WriteLine("What class would you like to be?");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Warrior, Mage, Thief > ");
                className = Console.ReadLine().ToLower();
                Console.ForegroundColor = ConsoleColor.White;

                if (className == "warrior")
                {
                    gold       = 100;
                    validClass = true;
                }
                else if (className == "mage")
                {
                    gold       = 150;
                    validClass = true;
                }
                else if (className == "thief")
                {
                    gold       = 200;
                    validClass = true;
                }
                else
                {
                    Console.WriteLine("Not a valid class");
                }
            }

            while (validRace == false)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("What race would you like?");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Human, Elf, Dwarf > ");
                raceName = Console.ReadLine().ToLower();

                if (raceName == "human")
                {
                    validRace = true;
                    hp        = 100;
                }
                else if (raceName == "elf")
                {
                    validRace = true;
                    hp        = 80;
                }
                else if (raceName == "dwarf")
                {
                    validRace = true;
                    hp        = 120;
                }
                else
                {
                    Console.WriteLine("Not a Valid entry.");
                }
            }

            while (validFaction == false)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("To what faction do you belong?");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Hero, Villion > ");
                string strFaction = CapWord.FirstCharToUpper(Console.ReadLine());

                if (strFaction == Factions.Hero.ToString() || strFaction == Factions.Villain.ToString() || strFaction == Factions.Admin.ToString())
                {
                    faction      = (Factions)Enum.Parse(typeof(Factions), strFaction, true);
                    validFaction = true;
                }
            }

            Console.ForegroundColor = ConsoleColor.White;
            Player._player          = new Player(name, CapWord.FirstCharToUpper(className), CapWord.FirstCharToUpper(raceName), gold, hp, hp, (Weapon)World.WeaponByID(103), false, true, faction, alignment);
            Console.WriteLine("Creating character data, please wait!");
            SaveData.SaveGameData(Player._player);
        }