/// <summary> /// Consumes potions, equips weapons, equips keys. /// </summary> /// <param name="item">potion, weapon, or doorkey to be used or equipped.</param> /// <returns>returns previously equipped weapon or doorkey. returns null if no prior items, or when using potions.</returns> public Item applyItem(Item item) { // if potion, heal the hero. if (item.GetType() == typeof(Potion)) { item.Use(this); // heals if potion. return(null); } // if weapon, equip the new weapon and return the previously equipped weapon. else if (item.GetType() == typeof(Weapon)) { // if no weapon was previously equipped, should return null automatically. Weapon previous = EquippedWeapon; EquippedWeapon = (Weapon)item; return(previous); } // if doorkey, equip the new doorkey and return the previously equipped doorkey else if (item.GetType() == typeof(DoorKey)) { DoorKey previous = EquippedKey; _EquippedKey = (DoorKey)item; return(previous); } // if any other type, just return it. else { return(item); } }
/// <summary> /// Equip or Effect hero based on the item /// </summary> public Item applyItem(Item i) { //Add Potion to hero if (i.GetType() == typeof(Potion)) { //Figure out what the spell is if (i.Name == "Small Healing Potion") { //Heal hero _CurrentHitPoints += i.AffectValue; } else if (i.Name == "Large Healing Potion") { //Heal hero _CurrentHitPoints += i.AffectValue; } else if (i.Name == "Mud") { //Freeze Hero _AttackSpeed += i.AffectValue; } else if (i.Name == "Poison") { //Poison Hero _CurrentHitPoints += i.AffectValue; } else if (i.Name == "Agility") { _AttackSpeed += i.AffectValue; } else if (i.Name == "Spinach" && i != null) { } return(null); } if (i.GetType() == typeof(Weapon)) { //Equip weapon Weapon oldWeapon = _Weapon; _Weapon = (Weapon)i; return(oldWeapon); } if (i.GetType() == typeof(DoorKey)) { //equip door key to door key field DoorKey oldKey = _DoorKey; _DoorKey = (DoorKey)i; return(oldKey); } return(i); }
/// <summary> /// Creates a matching door and key, and puts them in empty cells. /// </summary> /// <param name="passcode">code to be used to match door with key. </param> private void createDoorAndKey(string passcode) { // create matching door and key. Door door = new Door("Door", 0, passcode); DoorKey key = new DoorKey("Key", 0, passcode); // put door in random empty cell. putItemInRandomEmptyCell(door); // put key in random empty cell. putItemInRandomEmptyCell(key); }
private void PlaceKey() { Random rnd = new Random(); while (isThereADoorKey == false) { int row = rnd.Next(9); int col = rnd.Next(9); if (Cells[row, col].HasItem == false && Cells[row, col].HasMonster == false && LocationOfAdventurer != Cells[row, col]) { DoorKey dk = new DoorKey("Door Key", 0, "God Be With You"); Cells[row, col].Item = dk; isThereADoorKey = true; //Console.WriteLine("DoorKey"); } } }
public bool isMatch(DoorKey key) { return(key.Code == _Code); }
/// <summary> /// Tells whether a key works to unlock this door, based on the code field. /// </summary> /// <param name="key">the Key to compare against.</param> /// <returns>returns true if the codes match, false if they don't.</returns> public bool compareKey(DoorKey key) { // return true if the key and door have the same code. // return false if the codes are different. return(this._Code == key.Code); }