public Item EquipItem(Item item) { if (item.GetType() == typeof(Potion)) { return(null); } if (item.GetType() == typeof(Weapon)) { _Weapon = (Weapon)item; if (Weapon != null) { return(item); } else { return(null); } } if (item.GetType() == typeof(DoorKey)) { _DoorKey = (DoorKey)item; if (DoorKey != null) { return(item); } else { return(null); } } else { return(item); } }
/// <summary> /// Fill the map with empty MapCells /// </summary> public void FillMap() { int rows = Game.GameMap.Cells.GetLength(0); int cols = Game.GameMap.Cells.GetLength(1); Random rand = new Random(); int x = rand.Next(rows); int y = rand.Next(cols); Door door = new Door("Door", 5, "123"); DoorKey doorKey = new DoorKey("Key", 5, "123"); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { int jackpot = rand.Next(0, 6); Game.GameMap.Cells[row, col] = new MapCell(); if (jackpot == 3) { int pickItem = rand.Next(0, 4); if (pickItem == 0) { Game.GameMap.Cells[row, col].Item = ((Potion)_Items[rand.Next(0, 4)]).CreateCopy(); } else if (pickItem == 1) { Game.GameMap.Cells[row, col].Item = ((Weapon)_Items[rand.Next(4, 8)]).CreateCopy(); } else if (pickItem == 2) { Game.GameMap.Cells[row, col].Monster = _Monsters[rand.Next(_Monsters.Count)].CreateCopy(); } } } } for (int j = 0; j < 2; j++) { while (Game.GameMap.Cells[x, y].Item != null || Game.GameMap.Cells[x, y].Monster != null) { x = rand.Next(rows); y = rand.Next(cols); } if (Game.GameMap.Cells[x, y].Item == null && Game.GameMap.Cells[x, y].Monster == null) { if (j == 0) { Game.GameMap.Cells[x, y].Item = door; } else if (j == 1) { Game.GameMap.Cells[x, y].Item = doorKey; } } } }
public bool isMatch(DoorKey key) { return(key.Code == _code); }