Ejemplo n.º 1
0
        public void UsePotion(HealingPotion potion)
        {
            CurrentHitPoints += potion.AmountToHeal;

            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            // remove from inventory
            RemoveItemFromInventory(potion);
            RaiseMessage("You drink a " + potion.Name);

            // Monster does damage
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer.ToString() +
                         " points of damage.");
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                // Is player dead?
                RaiseMessage("The " + _currentMonster.Name + " killed you!!");
                MoveHome();
            }
        }
Ejemplo n.º 2
0
        public void UsePotion(HealingPotion potion)
        {
            //Add healing amount to player's hp
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);

            //HP can't exceed maxhp
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            //Remoce the potion from inventory
            RemoveItemFromInventory(potion, 1);

            RaiseMessage("You drink a " + potion.Name);

            //Moster attacks

            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer + " points of damage");

            //Subtact damage from player
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                RaiseMessage("The " + _currentMonster.Name + " killed you");

                MoveHome();
            }
        }
Ejemplo n.º 3
0
        public void UsePotion(HealingPotion potion)
        {
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);

            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            RemoveItemFromInventory(potion, 1);

            RaiseMessage("You drink a " + potion.Name);

            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer + " points of damage.");

            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                RaiseMessage("The " + _currentMonster.Name + " killed you.");

                MoveHome();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add 'quantity' of 'itemToAdd' to inventory, or increase existing quantity
        /// </summary>
        /// <param name="itemToAdd">Item to be added to inventory (can already be in inventory)</param>
        /// <param name="quantity">Amount of item to be added (Default = 1)</param>
        public void AddItemToInventory(Item itemToAdd, int quantity = 1)
        {
            InventoryItem item = Inventory.SingleOrDefault(
                ii => ii.Details.ID == itemToAdd.ID);

            if (item == null)
            {
                // They didn't have the item, so add it to their inventory

                // If there are none of this type of item, and it has a "CurrentItem"
                // property, then set this to it, so indexing will work right
                // NOTE: The UI code will follow-thru with the updates, based on
                // RaiseInventoryChangedEvent and Player.PropertyChanged event
                if (itemToAdd is Weapon && !Weapons.Any())
                {
                    CurrentWeapon = (Weapon)itemToAdd;
                }

                if (itemToAdd is HealingPotion && !Potions.Any())
                {
                    CurrentPotion = (HealingPotion)itemToAdd;
                }

                Inventory.Add(new InventoryItem(itemToAdd, quantity));
            }
            else
            {
                // They already have the item in inventory, so just increase quantity
                item.Quantity += quantity;
            }

            // An inventory quantity was changed, raise an event
            RaiseInventoryChangedEvent(itemToAdd);
        }
Ejemplo n.º 5
0
        public void UsePotion(HealingPotion potion)
        {
            RaiseMessage("You drink a " + potion.Name);

            HealPlayer(potion.AmountToHeal);

            RemoveItemFromInventory(potion, 1);
        }
Ejemplo n.º 6
0
 public void usePotion(HealingPotion hp)
 {
     currentHitPoints += hp.amountToHeal;
     if (currentHitPoints > maxHitPoints)
     {
         currentHitPoints = maxHitPoints;
     }
     removeItemFromInventory(hp, 1);
     RaiseMessage("you drink a " + hp.name);
 }
Ejemplo n.º 7
0
        public void UsePotion(HealingPotion potion)
        {
            RaiseMessage("You drink a " + potion.Name);

            HealPlayer(potion.AmountToHeal);

            RemoveItemFromInventory(potion);

            // The player used their turn to drink the potion, so let the monster attack now
            LetTheMonsterAttack();
        }
Ejemplo n.º 8
0
        public void UsePotion(HealingPotion potion, TTS tts)
        {
            RaiseMessage("Tu bebes a " + potion.Name + ".");
            text = "Bebeste a poção";


            HealPlayer(potion.AmountToHeal);

            RemoveItemFromInventory(potion);

            // The player used their turn to drink the potion, so let the monster attack now
            LetTheMonsterAttack(tts);
        }
Ejemplo n.º 9
0
        public void UsePotion(HealingPotion potion)
        {
            // Add healing amount to the player's current hit points
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);

            // CurrentHitPoints cannot exceed player's MaximumHitPoints
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            // Remove the potion from the player's inventory
            RemoveItemFromInventory(potion, 1);

            // Display message
            if (CurrentHitPoints < MaximumHitPoints)
            {
                RaiseMessage("");
                RaiseMessage("You drink a " + potion.Name);
                RaiseMessage("You are healed for 5 HP!");
                RaiseMessage("");
            }
            else
            {
                RaiseMessage("");
                RaiseMessage("You drink a " + potion.Name);
                RaiseMessage("You are healed to full HP!");
                RaiseMessage("");
            }

            // Monster gets their turn to attack

            // Determine the amount of damage the monster does to the player
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            // Display message
            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer + " points of damage.");
            RaiseMessage("");

            // Subtract damage from player
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                // Display message
                RaiseMessage("The " + _currentMonster.Name + " killed you.");

                // Move player to "Home"
                MoveHome();
            }
        }
        public void UsePotion(HealingPotion potion)
        {
            // Display message
            RaiseMessage("You drink a " + potion.Name, false);

            // Add healing amount to the player's current hit points
            Heal(potion.AmountToHeal);

            // Remove the potion from the player's inventory
            RemoveItemFromInventory(potion, 1);

            // Monster gets their turn to attack
            MonsterAttacksThePlayer();
        }
Ejemplo n.º 11
0
        public void UsePotion(HealingPotion potion)
        {
            // 3.2) Увеличи currentHP на играча
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);

            // 3.2.1) currentHP НЕ трябва да надвишава maxHP
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            // 3.3) Премахни използвания potion от Inventory
            RemoveItemFromInventory(potion, 1);

            // 3.4) Изведи съобщение
            RaiseMessage("You drink a " + potion.Name);

            // 3.5) Противникът получава ход да атакува

            // 3.5.1) Определи damage, който ще нанесе противникът на играча
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, currentEnemy.MaximumDamage);

            // 3.5.2) Изведи съобщение за damage-a
            RaiseMessage("The " + currentEnemy.Name + " did " + damageToPlayer + " points of damage.");

            // 3.5.3) Извади damage-a от currentHP на играча
            CurrentHitPoints -= damageToPlayer;

            // 3.5.4) Ако играчът е мъртъв
            if (CurrentHitPoints <= 0)
            {
                // 3.5.4.1) Съобщение
                RaiseMessage("The " + currentEnemy.Name + " killed you.");

                // 3.5.4.2) Смени локацията на player на Home/Graveyard (само Home има; TODO: да направя Гробище за напред)
                MoveToHome();
            }

            // 3.6) Обнови потребителския интерфейс
            //lblHitPoints.Text = player.CurrentHitPoints.ToString();
            //UpdateInventoryListInUI();
            //UpdatePotionListInUI();
        }
Ejemplo n.º 12
0
        public void HealPlayer(HealingPotion potion, Player player)
        {
            player.CurrenthitPoints = player.CurrenthitPoints + potion.AmountToHeal;

            if (player.CurrenthitPoints > player.MaximumHitPoints)
            {
                player.CurrenthitPoints = player.MaximumHitPoints;
            }

            // Remove the potion from the player's inventory
            foreach (InventoryItem ii in player.Inventory)
            {
                if (ii.Details.ID == potion.ID)
                {
                    ii.Quantity--;
                    break;
                }
            }
        }
Ejemplo n.º 13
0
        public void UsePotion(HealingPotion potion)
        {
            //Add healing amount to player's hit points
            CurrentHitPoints += (CurrentHitPoints + potion.AmountToHeal);

            //Current Hit Points cannot exceed MaximumHitPoints
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            //Remove potion from inventory
            RemoveItemFromInventory(potion, 1);

            RaiseMessage($"You drink a {potion.Name}");

            //Monster gets their turn to attack
            currentMonster.EnemyAttack(this);
        }
Ejemplo n.º 14
0
        public void RemovePotion(HealingPotion potion)
        {
            List <int> markItemForDeletion = new List <int>();

            for (int i = 0; i < Inventory.Count; i++)
            {
                if (Inventory[i].Details.ID == potion.ID)
                {
                    Inventory[i].Quantity -= 1;
                    if (Inventory[i].Quantity == 0)
                    {
                        markItemForDeletion.Add(i);
                    }
                }
            }
            for (int i = markItemForDeletion.Count - 1; i >= 0; i--)
            {
                Inventory.RemoveAt(markItemForDeletion[i]);
            }
        }
Ejemplo n.º 15
0
        public void UsePotion(HealingPotion potion)
        {
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);
            if (CurrentHitPoints > MaxHitPoints)
            {
                CurrentHitPoints = MaxHitPoints;
            }
            RemoveItemFromInventory(potion, 1);
            RaiseMessage("你使用了" + potion.Name);
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaxDamage);

            RaiseMessage(_currentMonster.Name + "對你造成了" + damageToPlayer + "點傷害");
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                RaiseMessage(_currentMonster.Name + "擊殺你");

                MoveHome();
            }
        }
Ejemplo n.º 16
0
        private void UsePotionInBattle(HealingPotion potion)
        {
            // Add healing amount to the player's current hit points
            CurrentHitPoints += potion.AmountToHeal;

            // CurrentHitPoints cannot exceed player's MaximumHitPoints
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            // Remove the potion from the player's Inventory
            RemoveItemFromInventory(potion, 1);

            // Display message
            RaiseMessage("You drink a " + potion.Name);

            // Monster gets their turn to attack

            // Determine the amount of damage the monster does to the player
            int damageToPlayer = RandomNumberGenerator.NumberBetween(
                0, _currentMonster.MaximumDamage);

            // Display message about the damage to player
            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer +
                         " points of damage.");

            // Subtract damage from player
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0) // Player died!!
            {
                // Display message about player's untimely demise
                RaiseMessage("The " + _currentMonster.Name + " killed you.");

                // Move player to "Home"
                MoveHome();
            }
        }
Ejemplo n.º 17
0
        public void UsePotion(HealingPotion potion)
        {
            //add healing amount to player's currentHP
            CurrentHP += potion.AmountToHeal;

            //current hp cannot exceed maxHP
            if (CurrentHP > MaxHP)
            {
                CurrentHP = MaxHP;
            }

            //remove potion from inventory
            RemoveItemFromInventory(potion, 1);

            //display message
            RaiseMessage("You drink a " + potion.Name + ".");

            //enemy attacks
            //determine enemy damage to player
            int damageToPlayer = RNG.NumberBetween(0, _currentEnemy.MaxDamage);

            //display message
            RaiseMessage("The " + _currentEnemy.Name + " did " + damageToPlayer + " damage to you.");

            //subtract damage from player
            CurrentHP -= damageToPlayer;

            if (CurrentHP <= 0)
            {
                //display message
                RaiseMessage("The " + _currentEnemy + " defeated you.");

                //Move player to home
                MoveHome();
            }
        }
Ejemplo n.º 18
0
        public string ToXmlString()
        {
            XmlDocument worldData = new XmlDocument();

            // Create the top-level XML node
            XmlNode nodeWorld = worldData.CreateElement("World");

            worldData.AppendChild(nodeWorld);

            #region Create Node Items

            // Create the "items" child node
            XmlNode nodeItems = worldData.CreateElement("items");

            foreach (Item item in _items)
            {
                XmlNode nodeItem;
                if (item is Weapon)
                {
                    Weapon weapon = item as Weapon;
                    nodeItem = worldData.CreateElement("weapon");
                    CreateNewChildXmlNode(worldData, nodeItem, "MinimumDamage", weapon.MinimumDamage);
                    CreateNewChildXmlNode(worldData, nodeItem, "MaximumDamage", weapon.MaximumDamage);
                }
                else if (item is HealingPotion)
                {
                    HealingPotion healingPotion = item as HealingPotion;
                    nodeItem = worldData.CreateElement("healingPotion");
                    CreateNewChildXmlNode(worldData, nodeItem, "AmountToHeal", healingPotion.AmountToHeal);
                }
                else
                {
                    nodeItem = worldData.CreateElement("item");
                }

                CreateNewChildXmlNode(worldData, nodeItem, "Id", item.ID);
                CreateNewChildXmlNode(worldData, nodeItem, "Name", item.Name);
                CreateNewChildXmlNode(worldData, nodeItem, "NamePlural", item.NamePlural);
                CreateNewChildXmlNode(worldData, nodeItem, "Price", item.Price);

                nodeItems.AppendChild(nodeItem);
            }

            nodeWorld.AppendChild(nodeItems);

            #endregion

            #region Create Node Monsters

            // Create the "Monsters" child node
            XmlNode nodeMonsters = worldData.CreateElement("Monsters");

            foreach (Monster monster in _monsters)
            {
                XmlNode nodeMonster = worldData.CreateElement("Monster");

                CreateNewChildXmlNode(worldData, nodeMonster, "Id", monster.ID);
                CreateNewChildXmlNode(worldData, nodeMonster, "Name", monster.Name);
                CreateNewChildXmlNode(worldData, nodeMonster, "MaximumDamage", monster.MaximumDamage);
                CreateNewChildXmlNode(worldData, nodeMonster, "RewardExperiencePoints", monster.RewardExperiencePoints);
                CreateNewChildXmlNode(worldData, nodeMonster, "RewardGold", monster.RewardGold);
                CreateNewChildXmlNode(worldData, nodeMonster, "CurrentHitPoints", monster.CurrentHitPoints);
                CreateNewChildXmlNode(worldData, nodeMonster, "MaximumHitPoints", monster.MaximumHitPoints);

                if (monster.LootTable.Count > 0)
                {
                    XmlNode nodeLootTable = worldData.CreateElement("LootTable");

                    foreach (LootItem lootItem in monster.LootTable)
                    {
                        CreateNewChildXmlNode(worldData, nodeLootTable, "IdItem", lootItem.Details.ID);
                        CreateNewChildXmlNode(worldData, nodeLootTable, "DropPercentage", lootItem.DropPercentage);
                        CreateNewChildXmlNode(worldData, nodeLootTable, "IsDefaultItem", lootItem.IsDefaultItem);
                    }

                    nodeMonster.AppendChild(nodeLootTable);
                }

                nodeMonsters.AppendChild(nodeMonster);
            }

            nodeWorld.AppendChild(nodeMonsters);

            #endregion

            #region Create Node Quests

            XmlNode nodeQuests = worldData.CreateElement("Quests");

            foreach (Quest quest in _quests)
            {
                XmlNode nodeQuest = worldData.CreateElement("Quest");

                CreateNewChildXmlNode(worldData, nodeQuest, "Id", quest.ID);
                CreateNewChildXmlNode(worldData, nodeQuest, "Name", quest.Name);
                CreateNewChildXmlNode(worldData, nodeQuest, "Description", quest.Description);
                CreateNewChildXmlNode(worldData, nodeQuest, "RewardExperiencePoints", quest.RewardExperiencePoints);
                CreateNewChildXmlNode(worldData, nodeQuest, "RewardGold", quest.RewardGold);

                if (quest.QuestCompletionItems.Count > 0)
                {
                    XmlNode nodeQuestCompletionItems = worldData.CreateElement("QuestCompletionItems");

                    foreach (QuestCompletionItem questCompletionItem in quest.QuestCompletionItems)
                    {
                        XmlNode nodeQuestCompletionItem = worldData.CreateElement("QuestCompletionItem");

                        CreateNewChildXmlNode(worldData, nodeQuestCompletionItem, "IdItem", questCompletionItem.Details.ID);
                        CreateNewChildXmlNode(worldData, nodeQuestCompletionItem, "Quantity", questCompletionItem.Quantity);

                        nodeQuestCompletionItems.AppendChild(nodeQuestCompletionItem);
                    }

                    nodeQuest.AppendChild(nodeQuestCompletionItems);
                }

                if (quest.RewardItem != null)
                {
                    XmlNode modeRewardItem = worldData.CreateElement("RewardItem");

                    CreateNewChildXmlNode(worldData, modeRewardItem, "IdItem", quest.RewardItem.ID);

                    nodeQuest.AppendChild(modeRewardItem);
                }

                nodeQuests.AppendChild(nodeQuest);
            }

            nodeWorld.AppendChild(nodeQuests);

            #endregion

            #region Create Node Vendors

            XmlNode nodeVendors = worldData.CreateElement("Vendors");

            foreach (Vendor vendor in _vendors)
            {
                XmlNode nodeVendor = worldData.CreateElement("Vendor");

                CreateNewChildXmlNode(worldData, nodeVendor, "Id", vendor.ID);
                CreateNewChildXmlNode(worldData, nodeVendor, "Name", vendor.Name);

                if (vendor.Inventory.Count > 0)
                {
                    foreach (InventoryItem inventoryItem in vendor.Inventory)
                    {
                        XmlNode nodeInventoryItem = worldData.CreateElement("Vendor");

                        CreateNewChildXmlNode(worldData, nodeVendor, "IdItem", inventoryItem.Details.ID);
                        CreateNewChildXmlNode(worldData, nodeVendor, "Quantity", inventoryItem.Quantity);

                        nodeVendor.AppendChild(nodeInventoryItem);
                    }
                }

                nodeVendors.AppendChild(nodeVendor);
            }

            nodeWorld.AppendChild(nodeVendors);


            #endregion

            #region Create Node Locations

            XmlNode nodeLocations = worldData.CreateElement("Locations");

            foreach (Location location in _locations)
            {
                XmlNode nodeLocation = worldData.CreateElement("Location");

                CreateNewChildXmlNode(worldData, nodeLocation, "Id", location.ID);
                CreateNewChildXmlNode(worldData, nodeLocation, "Name", location.Name);
                CreateNewChildXmlNode(worldData, nodeLocation, "Description", location.Description);

                if (!string.IsNullOrEmpty(location.Picture))
                {
                    CreateNewChildXmlNode(worldData, nodeLocation, "Picture", location.Picture);
                }

                if (location.ItemRequiredToEnter != null)
                {
                    CreateNewChildXmlNode(worldData, nodeLocation, "ItemRequiredToEnter", location.ItemRequiredToEnter.ID);
                }

                if (location.QuestAvailableHere != null)
                {
                    CreateNewChildXmlNode(worldData, nodeLocation, "QuestAvailableHere", location.QuestAvailableHere.ID);
                }

                if (location.VendorWorkingHere != null)
                {
                    CreateNewChildXmlNode(worldData, nodeLocation, "VendorWorkingHere", location.VendorWorkingHere.ID);
                }

                if (location.Monsters.Count > 0)
                {
                    XmlNode nodeMonstersAtLocation = worldData.CreateElement("Monsters");

                    foreach (KeyValuePair <int, int> mosterAtLocation in location.Monsters)
                    {
                        XmlNode nodeMonsterAtLocation = worldData.CreateElement("Monster");

                        CreateNewChildXmlNode(worldData, nodeMonsterAtLocation, "IdMonster", mosterAtLocation.Key);
                        CreateNewChildXmlNode(worldData, nodeMonsterAtLocation, "PercentageOfAppearance", mosterAtLocation.Value);

                        nodeLocation.AppendChild(nodeMonsterAtLocation);
                    }

                    nodeLocation.AppendChild(nodeMonstersAtLocation);
                }

                nodeLocations.AppendChild(nodeLocation);
            }

            nodeWorld.AppendChild(nodeLocations);

            #endregion

            #region Create Node Neighborhood

            XmlNode nodeNeighborhood = worldData.CreateElement("Neighborhood");

            foreach (Location location in _locations)
            {
                XmlNode nodeNeighbor = worldData.CreateElement("Neighbor");

                CreateNewChildXmlNode(worldData, nodeNeighbor, "IdLocation", location.ID);

                if (location.LocationToNorth != null)
                {
                    CreateNewChildXmlNode(worldData, nodeNeighbor, "North", location.LocationToNorth.ID);
                }

                if (location.LocationToSouth != null)
                {
                    CreateNewChildXmlNode(worldData, nodeNeighbor, "South", location.LocationToSouth.ID);
                }

                if (location.LocationToEast != null)
                {
                    CreateNewChildXmlNode(worldData, nodeNeighbor, "East", location.LocationToEast.ID);
                }

                if (location.LocationToWest != null)
                {
                    CreateNewChildXmlNode(worldData, nodeNeighbor, "West", location.LocationToWest.ID);
                }

                nodeNeighborhood.AppendChild(nodeNeighbor);
            }

            nodeWorld.AppendChild(nodeNeighborhood);

            #endregion

            return(worldData.InnerXml); // The XML document, as a string, so we can save the data to disk
        }
Ejemplo n.º 19
0
        public void UsePotion(HealingPotion potion)
        {
            // Add healing amount to the player's current hit points
            CurrentHitPoints = (CurrentHitPoints + potion.AmountToHeal);

            // CurrentHitPoints cannot exceed player's MaximumHitPoints
            if (CurrentHitPoints > MaximumHitPoints)
            {
                CurrentHitPoints = MaximumHitPoints;
            }

            // Remove the potion from the player's inventory
            RemoveItemFromInventory(potion, 1);

            // Display message
            RaiseMessage("You drink a " + potion.Name);

            // Monster gets their turn to attack

            // Determine the amount of damage the monster does to the player
            int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

            // Display message
            RaiseMessage("The " + _currentMonster.Name + " did " + damageToPlayer + " points of damage.");

            // Subtract damage from player
            CurrentHitPoints -= damageToPlayer;

            if (CurrentHitPoints <= 0)
            {
                // Display message
                RaiseMessage("The " + _currentMonster.Name + " killed you.");

                // Move player to "Home"
                MoveHome();
            }
        }