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_disconnectBridge() { Bridge bridge = new Bridge("bridge 4"); Node node1 = new Node(); Node node2 = new Node(); Node node3 = new Node(); Node node4 = new Node(); bridge.connectToNodeOfNextZone(node1); bridge.connectToNodeOfNextZone(node2); bridge.connectToNodeOfSameZone(node3); bridge.connectToNodeOfSameZone(node4); Dungeon d = new Dungeon(); Player P = new Player(); P.location = bridge; P.dungeon = d; d.zone = new Dictionary <int, List <Node> >(); d.zone[4] = new List <Node>(); d.zone[4].Add(bridge); d.zone[4].Add(node3); d.zone[4].Add(node4); Item x = new Crystal("cryst1"); P.bag.Add(x); P.use(x); Assert.IsTrue(bridge.GetFromNodes.Count == 2); Assert.IsTrue(bridge.neighbors.Contains(node1)); Assert.IsTrue(bridge.neighbors.Contains(node2)); Assert.IsTrue(!bridge.neighbors.Contains(node3)); Assert.IsTrue(!bridge.neighbors.Contains(node4)); Assert.IsTrue(!node3.neighbors.Contains(bridge)); Assert.IsTrue(!node4.neighbors.Contains(bridge)); }
public void Accelerate() { Crystal c = bag.OfType <Crystal>().First(); c.Use(this); bag.Remove(c); }
public void MStest_create_crystal() { Item crystal = new Crystal("crystID"); //Assert.IsInstanceOfType(crystal.GetType(), typeof(Crystal)); Assert.IsNotNull(crystal); Assert.IsTrue(crystal.id == "crystID"); }
public void MSTest_use_crystal() { Player player = new Player(); Item crystal = new Crystal("crystal"); player.bag.Add(crystal); player.use(crystal); Assert.IsTrue(player.accelerated); }
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 NTest_bagDoesNotContainHealingPotion_returnsFalse() { Player P = new Player(); Crystal crystal1 = new Crystal("crystal1"); Crystal crystal2 = new Crystal("crystal2"); P.bag.Add(crystal1); P.bag.Add(crystal2); Assert.IsFalse(P.containsHealingPotion()); }
public void MStest_invalid_crystal_use() { Dungeon d = new Dungeon(5); Player p = new Player(); p.location = d.zone[1][0]; Crystal crystal = new Crystal("crystID"); p.bag.Add(crystal); p.use(crystal); Assert.IsTrue(p.bag.Count == 1); }
public void NTest_use_crystal() { Dungeon dungeon = new Dungeon(5, 6); Player p = new Player(); Item c = new Crystal("ruby"); p.use(c); Assert.True(p.accelerated); if (p.location is Bridge) { Assert.True(p.location == dungeon.startNode); } }
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 NTest_use_crystal_on_bridge_not_in_combat() { Dungeon a = new Dungeon(10, 1); Player P = new Player(); P.location = a.bridges[0]; a.bridges[0].contested = false; P.dungeon = a; Item x = new Crystal("c1"); P.bag.Add(x); Assert.Throws <ArgumentException>(() => P.use(x)); Assert.True(P.bag.Contains(x)); Assert.True(P.location == a.bridges[0]); }
public void MSTest_player_crystal_attack() { Player player = new Player(); Pack pack = new Pack("Gang", 5); Item crystal = new Crystal("crystal"); player.bag.Add(crystal); player.use(crystal); Monster monster = pack.members[0]; Monster monster2 = pack.members[1]; monster.HP = 6; // Attack Rating Player + 1 monster2.HP = 5; player.Attack(monster); Assert.AreNotEqual(monster.HP, 6); Assert.AreNotEqual(pack.members.Count, 5); }
public void MSTest_become_accelerated() { Player P = new Player(); Pack pa = new Pack("pid", 1); Dungeon d = new Dungeon(5); P.dungeon = d; P.location = d.zone[1][0]; pa.dungeon = d; pa.location = d.zone[1][0]; d.zone[1][0].packs.Add(pa); Item x = new Crystal("cry1"); P.bag.Add(x); P.use(x); Assert.IsFalse(P.bag.Contains(x)); Assert.IsTrue(P.accelerated); }
public void MSTest_use_crystal_disconnectbridge() { Bridge bridge = new Bridge("bridge"); Node start = new Node("start"); Node final = new Node("final"); Dungeon dungeon = new Dungeon(1, 1); Player player = new Player(); Item crystal = new Crystal("crystal"); player.bag.Add(crystal); player.location = bridge; player.dungeon = dungeon; bridge.connectToNodeOfSameZone(start); bridge.connectToNodeOfNextZone(final); player.use(crystal); Assert.IsFalse(dungeon.startNode.neighbors.Contains(start)); Assert.IsTrue(dungeon.startNode.neighbors.Contains(final)); }
public void NTest_use_crystal_on_bridge() { Dungeon a = new Dungeon(10, 1); Player P = new Player(); P.location = a.bridges[0]; a.bridges[0].contested = true; P.dungeon = a; Item x = new Crystal("c1"); P.bag.Add(x); P.use(x); Assert.True(x.used); Assert.False(P.bag.Contains(x)); Assert.True(P.location == a.startNode); }
public void MSTest_fight_use_crystal() { Node node = new Node(); Player player = new Player(); Pack pack = new Pack("Warmachine", 1); pack.location = node; node.packs.Add(pack); player.location = node; Monster monster = pack.members[0]; monster.HP = 1; Item crystal = new Crystal("crystal"); player.bag.Add(crystal); player.AddNextCommand(1, 1, 2); //node.fight(player); Assert.IsFalse(player.bag.Contains(crystal)); }
public void Test_useCrystal() { Crystal crystal1 = new Crystal("0"); Player player = new Player(); Node node = new Node("1"); player.location = node; crystal1.use(player); Assert.AreEqual(crystal1.used, false); Assert.AreEqual(player.accelerated, false); Crystal crystal2 = new Crystal("2"); player.location.contested = true; crystal2.use(player); Assert.AreEqual(crystal2.used, true); Assert.AreEqual(player.accelerated, true); }
public void Crystal_Use_OnBridge() { Node N0 = new Node("N0"); Bridge N1 = new Bridge("N1"); Node N2 = new Node("N2"); Node N3 = new Node("N3"); N1.connectToNodeOfSameZone(N0); N1.connectToNodeOfNextZone(N2); N1.connectToNodeOfNextZone(N3); N3.connect(N2); Predicates utils = new Predicates(); List <Node> mockDungeon = utils.reachableNodes(N1); Assert.IsTrue(mockDungeon.Contains(N0)); player.dungeon = new Dungeon(1, 1); player.location = N1; Crystal crystal = new Crystal("crystal1"); player.bag.Add(crystal); player.use(crystal); mockDungeon = utils.reachableNodes(N1); Assert.IsFalse(player.bag.Contains(crystal)); Assert.IsTrue(player.accelerated); Assert.IsFalse(mockDungeon.Contains(N0)); Assert.IsNull(player.name); Assert.AreEqual(0, player.HP); Assert.AreEqual(5u, player.AttackRating); Assert.AreEqual(100, player.HPbase); Assert.AreEqual(0u, player.KillPoint); foreach (Node node in mockDungeon) { Console.WriteLine(node.id); } }
//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_healingPorion() { Item c = new Crystal("ruby"); Assert.Equals(c.id, "ruby"); }
/* 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); } } }