public void Heal() { HealingPotion p = bag.OfType <HealingPotion>().First(); p.Use(this); bag.Remove(p); }
//spawn pitems and public void SpawnPI(uint difficultylevel) { Random r = RandomGenerator.rnd; r.Next(); //spawn crystals for (int i = 0; i < r.Next(0, (int)difficultylevel) + 1; i++) { dungeon.graph[r.Next(1, dungeon.graph.Count - 1)].items.Add(new Crystal(i.ToString())); Console.WriteLine("CRYSTAL SPAWNED ON NODE {0}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", dungeon.graph[i].id); //To do: comment out above line. } //spawn health potions uint potionHP = 0; int monsterHP = dungeon.MonsterHP(); while (potionHP < monsterHP + 50) { HealingPotion potion = new HealingPotion(dungeon.totalPotions.Count().ToString()); dungeon.totalPotions.Add(potion); dungeon.graph[r.Next(0, dungeon.graph.Count() - 1)].items.Add(potion); potionHP += dungeon.totalPotions.Last().HPvalue; } }
public void DistributePotions(Player P, uint monsterHP, Dungeon D) { this.potionHP = (uint)P.HP; HealingPotion pot; List <HealingPotion> pots = new List <HealingPotion>(); int index; List <Node> zone; while (this.potionHP <= 0.8f * monsterHP) { pot = new HealingPotion("Minor Healing Potion of Major Healing" + pots.Count); if (this.potionHP + pot.HPvalue <= 0.8f * monsterHP) { pots.Add(pot); this.potionHP += pot.HPvalue; pot.id += '(' + pot.HPvalue + ')'; } else { break; } } foreach (HealingPotion p in pots) { zone = dungeon.zone[r.Next(dungeon.zone.Count) + 1]; index = r.Next(0, zone.Count); zone[index].items.Add(p); } }
public List <Item> additems(int totalMonsterHP, int nodeMax, int playerHP) { // add items to the dungeon List <Item> items = new List <Item>(); // calculate the hp limit int HPlimit = (int)(totalMonsterHP * 0.8); int itemAndPlayerHP = playerHP; int item_id = -1; int count = 0; List <int> allNodesInRandomOrder = Enumerable.Range(1, nodeMax - 1).OrderBy(x => randomnum.Next()).ToList(); while ((itemAndPlayerHP + 11) < HPlimit && count < allNodesInRandomOrder.Count) { // add healingpotions until the limit is reached HealingPotion item = new HealingPotion(item_id++.ToString()); item.location = dungeon.nodeList[allNodesInRandomOrder[count]]; dungeon.nodeList[allNodesInRandomOrder[count++]].items.Add(item); itemAndPlayerHP += item.HPvalue; items.Add(item); } while (count < allNodesInRandomOrder.Count - 1) { // for now we decided every node has a 1 in 20 chance to contain a Crystal if (randomnum.Next(1, 21) == 5) { Crystal item = new Crystal(item_id++.ToString()); item.location = item.location = dungeon.nodeList[allNodesInRandomOrder[count]]; items.Add(item); } count++; } return(items); }
public void MStest_create_hppotion() { Item potion = new HealingPotion("potID"); //Assert.IsInstanceOfType(potion.GetType(), HealingPotion); Assert.IsNotNull(potion); Assert.IsTrue(potion.id == "potID"); }
public void NTest_use_item() { Player P = new Player(); Item x = new HealingPotion("pot1"); P.use(x); Assert.True(x.used); }
public void XTest_use_item_in_bag() { Player P = new Player(); Item x = new HealingPotion("pot1"); P.bag.Add(x); P.use(x); Assert.False(P.bag.Contains(x)); }
public void HealingPotion_Constructor() { HealingPotion potion = new HealingPotion("HealingPotion1"); Assert.IsTrue(potion.HPvalue >= 1 && potion.HPvalue <= 10); Assert.AreEqual("HealingPotion1", potion.id); Assert.IsFalse(potion.used); }
public void Test_usePotion() { HealingPotion potion = new HealingPotion("0"); Player player = new Player(); potion.use(player); Assert.AreEqual(potion.used, true); }
public void NTest_getHPValueOfBag_returnsValid() { Player P = new Player(); HealingPotion healingPotion = new HealingPotion("hp"); int originalHPValue = (int)healingPotion.HPvalue; P.bag.Add(healingPotion); Assert.AreEqual(originalHPValue, P.getHPValueOfBag()); }
public void NTest_use_healingPotionWithHalfHP() { Player p = new Player(); Item h = new HealingPotion("pot1"); p.HP = 50; p.use(h); Assert.True(p.HP > 50); Assert.False(p.HP < 51); }
public void NTest_bagDoesNotContainMagicCrystal_returnsFalse() { Player P = new Player(); HealingPotion healingPotion1 = new HealingPotion("healing1"); HealingPotion healingPotion2 = new HealingPotion("healing2"); P.bag.Add(healingPotion1); P.bag.Add(healingPotion2); Assert.IsFalse(P.containsMagicCrystal()); }
public void NTest_bagContainsHealingPotion_returnsTrue() { Player P = new Player(); HealingPotion healingPotion = new HealingPotion("healing"); Crystal crystal = new Crystal("crystal"); P.bag.Add(healingPotion); P.bag.Add(crystal); Assert.IsTrue(P.containsHealingPotion()); }
public void MStest_excessive_healing() { Player P = new Player(); Item x = new HealingPotion("pot1"); P.HP = P.HPbase - 1; P.bag.Add(x); P.use(x); Assert.IsTrue(P.HP == P.HPbase); }
public void MStest_healing() { Player P = new Player(); HealingPotion x = new HealingPotion("pot1"); P.HP = 1; P.bag.Add(x); P.use(x); Assert.IsTrue(P.HP == 1 + x.HPvalue); //Can't call x.HPvalue }
public void MSTest_use_potion() { Player player = new Player(); Item potion = new HealingPotion("potion"); player.bag.Add(potion); player.HP = 50; player.use(potion); Assert.AreNotEqual(player.HP, 50); }
public void MSTest_using_used_item() { Player P = new Player(); P.HP = 50; Item x = new HealingPotion("pot1"); P.bag.Add(x); x.used = true; P.use(x); }
public void NTest_use_used_item() { Player P = new Player(); Item x = new HealingPotion("pot1"); P.bag.Add(x); P.use(x); Assert.True(x.used); Assert.False(P.bag.Contains(x)); P.bag.Add(x); //P.use(x); Assert.Throws <ArgumentException>(() => P.use(x)); }
public void NTest_item_use() { Dungeon a = new Dungeon(10, 1); Player P = new Player(); P.dungeon = a; P.location = a.startNode; a.startNode.contested = true; Item x = new HealingPotion("p1"); x.use(P); Assert.Throws <ArgumentException>(() => x.use(P)); }
public void NTest_collectItems_ReturnsValid() { Player P = new Player(); Node testNode = new Node("1", 1); HealingPotion healingPotion = new HealingPotion("hp"); Crystal crystal = new Crystal("cr"); testNode.items.Add(healingPotion); testNode.items.Add(crystal); List <Item> testList = testNode.items.ToList <Item>(); P.location = testNode; P.collectItems(); CollectionAssert.AreEquivalent(testList, P.bag.ToList <Item>()); }
public void HealingPotion_Use() { HealingPotion potion = new HealingPotion("HealingPotion1"); int expectedHealingValue = (int)potion.HPvalue; player.bag.Add(potion); player.use(potion); Assert.IsTrue(potion.used); Assert.AreEqual(player.HP, expectedHealingValue); Assert.IsNull(player.name); Assert.IsNull(player.location); Assert.IsNull(player.dungeon); Assert.AreEqual(100, player.HPbase); Assert.IsFalse(player.accelerated); Assert.AreEqual(0u, player.KillPoint); }
public void MSTest_ItemCommand() { Node node = new Node(); Item item = new HealingPotion("hpPotion"); Command itemCom = new ItemCommand(0, ""); uint healingpower = (item as HealingPotion).HPvalue; Assert.IsTrue(itemCom.ToString() == "use item " + 0 + " in player bag"); Player player = new Player(); player.location = node; player.bag.Add(item); player.HP -= 20; int pHP = player.HP; itemCom.ExecuteCommand(player); Assert.IsTrue(player.HP == pHP + healingpower); }
public void HealingPotion_Use_Overhealing() { HealingPotion potion = new HealingPotion("Healingpotion1"); player.HP = player.HPbase - 1; player.bag.Add(potion); player.use(potion); Assert.AreEqual(player.HP, player.HPbase); Assert.IsNull(player.name); Assert.AreEqual(player.HPbase, player.HP); Assert.AreEqual(5u, player.AttackRating); Assert.IsNull(player.location); Assert.IsNull(player.dungeon); Assert.AreEqual(100, player.HPbase); Assert.IsFalse(player.accelerated); Assert.AreEqual(0u, player.KillPoint); }
public void MSTest_fight_use_potion() { Node node = new Node(); Player player = new Player(); Pack pack = new Pack("Ironman", 1); pack.location = node; node.packs.Add(pack); player.location = node; Monster monster = pack.members[0]; monster.HP = 1; Item potion = new HealingPotion("potion"); player.bag.Add(potion); player.AddNextCommand(1, 0, 2); //node.fight(player); Assert.IsFalse(player.bag.Contains(potion)); }
public void CheckIfItemBalancingHolds() { Game game = new Game(10, 5, 50); int PlayerAndItemHP = game.player.HPbase; int MonsterHP = 0; for (int i = 0; i < game.items.Count; i++) { if (game.items[i] is HealingPotion) { HealingPotion potion = (HealingPotion)game.items[i]; PlayerAndItemHP += potion.HPvalue; } } foreach (Pack p in game.packs) { foreach (Monster m in p.members) { MonsterHP += m.GetHP(); } } MonsterHP = (int)(MonsterHP * 0.8); Assert.True(PlayerAndItemHP <= MonsterHP); }
//public int state; /* This creates a player and a random dungeon of the given difficulty level and node-capacity * The player is positioned at the dungeon's starting-node. * The constructor also randomly seeds monster-packs and items into the dungeon. The total * number of monsters are as specified. Monster-packs should be seeded as such that * the nodes' capacity are not violated. Furthermore the seeding of the monsters * and items should meet the balance requirements stated in the Project Document. */ public Game(uint difficultyLevel, uint nodeCapacityMultiplier, uint numberOfMonsters) { try{ Logger.log("Creating a game of difficulty level " + difficultyLevel + ", node capacity multiplier " + nodeCapacityMultiplier + ", and " + numberOfMonsters + " monsters."); dungeon = new Dungeon(difficultyLevel, nodeCapacityMultiplier, random); //call dungeon constructor player = new Player(); player.location = dungeon.startNode; int numberOfMonstersToPut = (int)numberOfMonsters; //a temporary variable to keep track of number of monsters to put in the dungeon int min = 1, max = 1; //used in while loop to define number of monsters in a pack int packId = 0; uint numberOfNodesInZone = 0; //a temporary variable to store number of nodes in a zone (in foreach loop) //Randomly seeds monsters into the dungeon //Currently puts all monsters in the dungeon at the creation Logger.log("Number of monsters to put in total : " + numberOfMonsters); while (numberOfMonstersToPut > 0) //while there are monsters to put in the dungeon { foreach (Zone z in dungeon.zones) //Seeds monsters zone by zone { int monstersInZone = -1; // -1 is just for control does not have any meaning if (z.id == difficultyLevel) { //if it is the last zone monstersInZone = numberOfMonstersToPut; //put remainder monsters } else //else every zone gets proportioned number of monsters { monstersInZone = getProportion(numberOfMonsters, z.id, difficultyLevel); //gets number of monsters to put in this zone } Logger.log("Will put " + monstersInZone + " monsters to the zone " + z.id); numberOfNodesInZone = (uint)z.nodesInZone.Count; //get number of nodes (N) while (monstersInZone > 0) //while there are monsters to put in the zone { int nodeNumber = random.Next(0, (int)numberOfNodesInZone); //randomly pick which node to locate Node nodeToLocate = z.nodesInZone.ElementAt <Node>(nodeNumber); //get this node instance int nodeCapacity = (int)z.capacity - (nodeToLocate.currentNumberOfMonsters()); //number of monsters that can locate in that node //check the capacity nodeCapacity, if less than 1 try another node, else create a monster pack of size min=1 max=nodeCapacity Logger.log("Node to locate: " + nodeToLocate.id + " with capacity " + nodeCapacity); if (nodeCapacity > 1) { //the upper limit for max is either the node's capacity or remaining number of monsters that should be located in this zone if (nodeCapacity < monstersInZone) { max = nodeCapacity; //if node capacity is less than remaining monsters to put, update max limit } else { max = monstersInZone; } int monstersToLocate = random.Next(min, max + 1); //decide how many monsters will be in this monster-pack between this number limit Pack newPack = new Pack("" + packId, (uint)monstersToLocate, this.dungeon); //Create a pack Logger.log("Putting " + monstersToLocate + " monsters in pack" + packId + " locating in " + nodeToLocate.id); newPack.location = z.nodesInZone.ElementAt <Node>(nodeNumber); //Assign this pack's location packId++; //increase pack ID z.nodesInZone.ElementAt <Node>(nodeNumber).packs.Add(newPack); //add pack to the node monstersInZone -= monstersToLocate; //decrease number of monsters to be located in the zone numberOfMonstersToPut -= monstersToLocate; //decrease number of monsters to be located in the dungeon Logger.log("monsters to locate in zone: " + monstersInZone + " in dungeon: " + numberOfMonstersToPut); } } } } itemsToSeed = new List <Item>(); //stores the list of items to be seeded in the dungeon int itemTotal = 0; //There is a constraint for HP value of the player & HP values of items that player has in the bag //and HP values of items exist in the dungeon Logger.log("Upper limit " + (0.8 * getHPM())); while (getItemsHP() <= (0.8 * getHPM())) //while this constraint is satisfied, it creates items { int decide = random.Next(0, 2); //0 or 1, 0 means create healing potion, 1 means create magic crystal if (decide == 0) { //create healing potion HealingPotion healingPotion = new HealingPotion("" + itemTotal); //create it with id itemTotal++; itemsToSeed.Add(healingPotion); //add it into the list Logger.log("Created healing potion " + healingPotion.id); } else if (decide == 1) { //create crystal Crystal crystal = new Crystal("" + itemTotal); itemTotal++; itemsToSeed.Add(crystal); //add it into the list Logger.log("Created crystal " + crystal.id); } else { Logger.log("Something went wrong"); } Logger.log("Current itemsToSeedHP " + getItemsHP()); } //since it leaves the while loop just after this constraint is passed //remove last created item for property to hold itemsToSeed.RemoveAt(itemsToSeed.Count - 1); Logger.log("Current getITemsHP " + getItemsHP()); //Randomly seed items in the itemsToSeed list //Currently puts all items in the dungeon at the creation int numberOfItemsToPut = itemsToSeed.Count; //number of items to seed is the length of the list Logger.log("Number of items to put in total : " + numberOfItemsToPut); int itemsInZone = (int)(numberOfItemsToPut / (int)difficultyLevel); //Equally partition the number of items, except the last zone int normalItemsInZone = itemsInZone; //used for indexing the items in itemsToSeed for the last level //because itemsInZone for the last level changes, indexing changes int itemsIndex = 0; //index of the item in the itemsToSeed list while (numberOfItemsToPut > 0) //while there are items to put in the dungeon { foreach (Zone z in dungeon.zones) //for each zone { if (z.id == difficultyLevel) { //if it is the last zone itemsInZone = numberOfItemsToPut; //put remainder items } Logger.log("Will put " + itemsInZone + " items to the zone " + z.id); numberOfNodesInZone = (uint)z.nodesInZone.Count; //get number of nodes (N) for (int i = 0; i < itemsInZone; i++) { //for each item to put in this zone int nodeNumber = random.Next(0, (int)numberOfNodesInZone); //randomly pick which node to locate Node nodeToLocate = z.nodesInZone.ElementAt <Node>(nodeNumber); //get this node Item itemToAdd = itemsToSeed.ElementAt <Item>((int)(itemsIndex * normalItemsInZone + i)); //starts from 0 for level 1, 0+number of items put in each zone for level 2 //increases by number of items put in zone for every level Logger.log("Putting item positioned " + (itemsIndex * normalItemsInZone + i) + " to " + nodeToLocate.id); nodeToLocate.items.Add(itemToAdd); //add the item to this node numberOfItemsToPut--; //Decrease number of items to put } itemsIndex++; //increase items index } } }catch { throw new GameCreationException("Could not create the game"); } }
public void drawUI(Dungeon d, Player p) { Logger.log("Name: " + p.name + " -- Player HP: " + p.HP + " -- ATK: " + p.AttackRating + " -- Accelerated: " + p.accelerated); Logger.log("Current Zone: " + p.zone + " -- Current Node: " + p.location.id + " -- KillPoints: " + p.KillPoint); int totalPackHP = 0; foreach (Node node in p.dungeon.zone[p.zone]) { foreach (Pack pack in node.packs) { packsAlerted = pack.rAlert; totalPackHP += pack.CurrentHP(); } } Logger.log("Packs in Zone: " + p.location.packs.Count + " -- Total HP: " + totalPackHP + " -- Alerted: " + packsAlerted); Console.Write("** Items: "); int counter = 0; if (p.bag.Count == 0) { Console.Write("Empty"); } foreach (Item i in p.bag) { if (counter == 2) { Console.Write("\n"); counter = 0; } if (i is HealingPotion) { HealingPotion I = (HealingPotion)i; Console.Write(i.id + "(" + I.HPvalue + "), "); } if (i is Crystal) { Crystal I = (Crystal)i; Console.Write(i.id + ", "); } counter++; } Console.WriteLine(); safe = true; if (p.location.contested(p)) { safe = false; Logger.log("YOU ARE IN COMBAT! DEFEAT OR ROUT THE MONSTERS!"); Logger.log("Enemies: "); foreach (Pack pack in p.location.packs) { foreach (Monster m in pack.members) { Logger.log(m.name + " (" + m.id + "), HP: " + m.HP); } } } else { foreach (Node nb in p.location.neighbors) { if (nb.contested(p)) { Logger.log("This room seems to be safe, but you feel an evil presence in a nearby room..."); safe = false; break; } } } if (safe) { Logger.log("This room seems to be safe..."); } foreach (Item i in p.bag) { if (!checkBag.Contains(i)) { Logger.log("You have picked up an item: " + i.id); } } foreach (Item j in checkBag) { if (!p.bag.Contains(j)) { Logger.log("You have used an item: " + j.id); } } Logger.log("Choose your action: "); checkBag = p.bag; }
public void NTest_create_crystal() { Item h = new HealingPotion("pot1"); Assert.Equals(h.id, "pot1"); }
/* This creates a player and a random dungeon of the given difficulty level and node-capacity * The player is positioned at the dungeon's starting-node. * The constructor also randomly seeds monster-packs and items into the dungeon. The total * number of monsters are as specified. Monster-packs should be seeded as such that * the nodes' capacity are not violated. Furthermore the seeding of the monsters * and items should meet the balance requirements stated in the Project Document. */ public Game(uint difficultyLevel, uint nodeCapcityMultiplier, uint numberOfMonsters) { player = new Player(); dungeon = new Dungeon(difficultyLevel, nodeCapcityMultiplier); packs = new List <Pack>(); items = new List <Item>(); // Game should have at least one monster. if (numberOfMonsters < 2) { throw new GameCreationException("Not enough monsters. numberOfMonsters should be >= 2"); } // Check if node multiplier is bigger then 1, else dungeon cannot have any monsters. if (nodeCapcityMultiplier <= 0) { throw new GameCreationException("Invalid nodeCapcityMultiplier must be > 0"); } // Check if dungeon is big enough to hold all the monsters. uint maxCapacity = 0; dungeon.allNodes.ForEach(node => maxCapacity += nodeCapcityMultiplier * (dungeon.level(node) + 1)); if (numberOfMonsters > maxCapacity) { throw new GameCreationException("The number of monsters (" + numberOfMonsters + ") exceed dungeon capacity (" + maxCapacity + ")"); } Logger.log("Creating a game of difficulty level " + difficultyLevel + ", node capacity multiplier " + nodeCapcityMultiplier + ", and " + numberOfMonsters + " monsters."); player.dungeon = dungeon; // Player should start at the starting node. player.location = dungeon.startNode; // Get all dungeon bridges. List <Node> bridges = new List <Node>(dungeon.bridges); // Pretend the start and exit node are also a bridge. bridges.Insert(0, dungeon.startNode); bridges.Add(dungeon.exitNode); // The total hp off all monsters, will later be used to determine the amount of healing potions that can be spawned. int totalMonsterHp = 0; // Number of packs created. int packCount = 0; // Number of monsters created. int monsterCount = 0; // Helper function for pack creation. Func <uint, Node, Pack> createPack = new Func <uint, Node, Pack>((numberOfMonstersToCreate, node) => { // Create a pack with the number of monsters. Pack pack = new Pack("Pack" + packCount++, numberOfMonstersToCreate); pack.dungeon = dungeon; pack.location = node; pack.zoneNumber = pack.location.zoneNumber; node.packs.Add(pack); monsterCount += (int)numberOfMonstersToCreate; pack.members.ForEach(member => { member.pack = pack; totalMonsterHp += member.HP; }); packs.Add(pack); return(pack); }); // Distribute packs/monsters in dungeon. for (int level = 0; level <= difficultyLevel; level++) { // The amount of monster allowed in this zone. int monsterPerZone = (int)Math.Floor((2.0 * (level + 1) * numberOfMonsters) / ((difficultyLevel + 2) * (difficultyLevel + 1))); // The last level (zone) does not have to follow the formula above and can get the remaining monsters. if (level == difficultyLevel) { monsterPerZone += ((int)numberOfMonsters - monsterCount) - monsterPerZone; } // All the nodes in the in this zone. (without the start or exit node). List <Node> nodes = Util.getAllNodesBetween(bridges[level], bridges[level + 1]).FindAll(node => node != dungeon.startNode && node != dungeon.exitNode); // For each node in level. for (int i = 0; i < nodes.Count && monsterPerZone > 0; i++) { // The max number of monster that can be on this node. uint nodeCapacityLimit = nodeCapcityMultiplier * (dungeon.level(nodes[i]) + 1); // Subtract the monsters that are already on this node. nodes[i].packs.ForEach(pack => nodeCapacityLimit -= (uint)pack.members.Count); // Take a random number of monster to create for this pack on this node. // But do not exceed the node capacity. uint numberOfMonstersToCreate = (uint)RandomGenerator.rnd.Next((int)(Math.Min(nodeCapacityLimit, monsterPerZone) + 1)); // Check if we can still create a pack, we do not wish to create a pack of zero monsters. if (numberOfMonstersToCreate > 0) { // Subtract the amount of monster spawned from the total monster pool. // This pool should reach zero by the end of the zone. monsterPerZone -= (int)numberOfMonstersToCreate; // Put the pack on then node. createPack(numberOfMonstersToCreate, nodes[i]); } } // Not necessarily all monster should have been created, due to the randomness. // So we just distribute the rest of the monster accordingly. for (int i = 0; i < nodes.Count && monsterPerZone > 0; i++) { // The number of monsters this node can still hold. uint remainingNodeCapacity = nodeCapcityMultiplier * (dungeon.level(nodes[i]) + 1); nodes[i].packs.ForEach(pack => remainingNodeCapacity -= (uint)pack.members.Count); uint numberOfMonstersToCreate = (uint)Math.Min(monsterPerZone, remainingNodeCapacity); // Check if we can still create a pack, we do not wish to create a pack of zero monsters. if (numberOfMonstersToCreate > 0) { monsterPerZone -= (int)numberOfMonstersToCreate; createPack(numberOfMonstersToCreate, nodes[i]); } } // Monsters for this zone should be exactly zero. // If not the zone was to small and the dungeon is invalid. if (monsterPerZone != 0) { throw new GameCreationException("To many monsters to fit in zone!"); } } // Player HP player.HP = Math.Min(player.HPbase, (int)(0.8 * totalMonsterHp)); // All nodes in dungeon without the start and exit node. List <Node> allNodes = dungeon.allNodes.FindAll(node => node != dungeon.startNode && node != dungeon.exitNode); // HP left to spend is the difference between 80% of the total monster HP and the player HP including all possible potions. int hpLeftToSpend = (int)Math.Floor(totalMonsterHp * 0.8) - player.HP; // Minus the HP of possible healing potion already in player bag. //hpLeftToSpend -= (int)player.bag.OfType<HealingPotion>().Sum(item => item.HPvalue); // Generate healing potions. for (int i = 0; ; i++) { HealingPotion potion = new HealingPotion("HP_" + i); // Check if the healing potion will not exceed the maximum amount of HP. if (hpLeftToSpend - potion.HPvalue >= 0) { // Decrease the maximum amount of HP that can still be allocated to healing potions. hpLeftToSpend -= (int)potion.HPvalue; items.Add(potion); // Add potion to random node in dungeon. allNodes[RandomGenerator.rnd.Next(allNodes.Count)].items.Add(potion); } else { break; } } // Generate crystals. for (int i = 0; i < allNodes.Count; i++) { // Each node has 10% chance to spawn a crystal. if (RandomGenerator.rnd.Next(10) == 0) { Crystal crystal = new Crystal("Cry_" + i); items.Add(crystal); // Add crystal to node. allNodes[i].items.Add(crystal); } } }