public void TestPickUpItem() { // prepare map block with one item, player and pick up action MapBlock mapBlock = new MapBlock(0, 0); AbstractInventoryItem item = new BasicItem("Test item", mapBlock, 10); mapBlock.Item = item; AbstractPlayer testPlayer = new EmptyAIPlayer("Test player", mapBlock); PickUp pickUpAction = new PickUp() { Actor = testPlayer }; // check that inventory is empty Assert.AreEqual(0, testPlayer.Inventory.Count, "Inventory should be empty!"); Assert.IsNotNull(mapBlock.Item, "Item should be placed in map block!"); // perform pick up action pickUpAction.Execute(); // check that item was picked up Assert.AreEqual(1, testPlayer.Inventory.Count, "There should be one item in inventory!"); Assert.IsNull(mapBlock.Item, "There should be no item in the map block!"); Assert.AreEqual(item, testPlayer.GetItemFromInventory(0), "Wrong item picked up!"); }
public void TestPickUpNoItem() { // prepare map block, player and pick up action MapBlock mapBlock = new MapBlock(0, 0); AbstractPlayer testPlayer = new EmptyAIPlayer("Test player", mapBlock); PickUp pickUpAction = new PickUp() { Actor = testPlayer }; // perform pick up action pickUpAction.Execute(); }
/// <summary> /// Read creature from byte stream. /// </summary> /// <param name="byteStream">Byte stream to read creature from.</param> /// <param name="map">Map to write data to.</param> /// <returns>Creature.</returns> private AbstractCreature ReadCreature(Stream byteStream, Map map) { AbstractCreature creature; int uid = ReadInt(byteStream); string name = ReadName(byteStream); int x = ReadInt(byteStream); int y = ReadInt(byteStream); int hp = ReadInt(byteStream); int dmg = ReadInt(byteStream); int def = ReadInt(byteStream); byte type = ReadByte(byteStream); switch (type) { case 0: creature = new Monster(name, map.Grid[x, y], hp, dmg, def) { UniqueId = uid, BaseHitPoints = hp, BaseAttack = dmg, BaseDeffense = def }; break; case 1: creature = new HumanPlayer(name, map.Grid[x, y]) { UniqueId = uid, BaseHitPoints = hp, BaseAttack = dmg, BaseDeffense = def }; break; case 2: creature = new EmptyAIPlayer(name, map.Grid[x, y]) { UniqueId = uid, BaseHitPoints = hp, BaseAttack = dmg, BaseDeffense = def }; break; case 3: creature = new SimpleAIPlayer(name, map.Grid[x, y]) { UniqueId = uid, BaseHitPoints = hp, BaseAttack = dmg, BaseDeffense = def }; break; default: throw new Exception($"Neznámý typ bytosti: {type}!"); } map.AddCreature(creature); return(creature); }
public void TestPickUpArmor() { // prepare map block with one item, player and pick up action MapBlock mapBlock = new MapBlock(0, 0); AbstractItem armor = new LeatherArmor(mapBlock); mapBlock.Item = armor; AbstractPlayer testPlayer = new EmptyAIPlayer("Test player", mapBlock); PickUp pickUpAction = new PickUp() { Actor = testPlayer }; // check that player has no armor Assert.IsNull(testPlayer.Armor, "No armor should be equipped!"); // perform pick up action pickUpAction.Execute(); // check that armor was equipped Assert.IsNotNull(testPlayer.Armor, "Armor should be equipped!"); Assert.AreEqual(armor, testPlayer.Armor, "Wrong armor picked up"); Assert.IsNull(mapBlock.Item, "Item was not picked up from map block"); // add new sword to the map block and check that swapping works AbstractItem armor2 = new LeatherArmor(mapBlock); mapBlock.Item = armor2; pickUpAction.Execute(); // check swap Assert.IsNotNull(testPlayer.Armor, "Amor should be equipped!"); Assert.AreEqual(armor2, testPlayer.Armor, "Wrong armor picked up!"); Assert.IsNotNull(mapBlock.Item, "First armor should be placed back to map block!"); Assert.AreEqual(armor, mapBlock.Item, "Wrong armor placed in map block!"); }
public void TestPickUpWeapon() { // prepare map block with one item, player and pick up action MapBlock mapBlock = new MapBlock(0, 0); AbstractItem sword = new Axe(mapBlock); mapBlock.Item = sword; AbstractPlayer testPlayer = new EmptyAIPlayer("Test player", mapBlock); PickUp pickUpAction = new PickUp() { Actor = testPlayer }; // check that player has no weapon Assert.IsNull(testPlayer.Weapon, "No weapon should be equipped!"); // perform pick up action pickUpAction.Execute(); // check that weapon was equipped Assert.IsNotNull(testPlayer.Weapon, "Weapon should be equipped!"); Assert.AreEqual(sword, testPlayer.Weapon, "Wrong weapon picked up"); Assert.IsNull(mapBlock.Item, "Item was not picked up from map block"); // add new sword to the map block and check that swapping works AbstractItem sword2 = new Axe(mapBlock); mapBlock.Item = sword2; pickUpAction.Execute(); // check swap Assert.IsNotNull(testPlayer.Weapon, "Weapon should be equipped!"); Assert.AreEqual(sword2, testPlayer.Weapon, "Wrong weapon picked up!"); Assert.IsNotNull(mapBlock.Item, "First sword should be placed back to map block!"); Assert.AreEqual(sword, mapBlock.Item, "Wrong sword placed in map block!"); }