Exemple #1
0
        /// <summary>
        /// Gets the item for the Hero depending on item type
        /// </summary>
        public Item EquipItem(Item item)
        {
            if (item.GetType() == typeof(Potion))
            {
                healMe(item.AffectValue);

                return(null);
            }

            if (item.GetType() == typeof(Weapon))
            {
                if (_Weapon == null)
                {
                    _Weapon = (Weapon)item;

                    return(null);
                }

                else if (_Weapon != null)
                {
                    Weapon tempWeapon = _Weapon;

                    _Weapon = (Weapon)item;

                    return(tempWeapon);
                }

                else
                {
                    return(null);
                }
            }

            if (item.GetType() == typeof(DoorKey))
            {
                if (DoorKey == null)
                {
                    _DoorKey = (DoorKey)item;

                    return(null);
                }

                else if (DoorKey != null)
                {
                    _DoorKey = (DoorKey)item;

                    return(item);
                }

                else
                {
                    return(null);
                }
            }

            else
            {
                return(item);
            }
        }
Exemple #2
0
        public bool isMatch(DoorKey key)
        {
            if (key != null)
            {
                return(key.Code == _code);
            }

            else
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// Fill the map with empty MapCells
        /// </summary>
        public void FillMap()
        {
            int rows = Cells.GetLength(0);
            int cols = 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, 5);

                    Cells[row, col] = new MapCell();

                    if (jackpot == 3)
                    {
                        int pickItem = rand.Next(0, 5);

                        if (pickItem == 0 || pickItem == 3)
                        {
                            Cells[row, col].Item = ((Potion)_Items[rand.Next(0, 4)]).CreateCopy();
                        }

                        else if (pickItem == 1)
                        {
                            Cells[row, col].Item = ((Weapon)_Items[rand.Next(4, 8)]).CreateCopy();
                        }

                        else if (pickItem == 2 || pickItem == 4)
                        {
                            Cells[row, col].Monster = _Monsters[rand.Next(_Monsters.Count)].CreateCopy();
                        }
                    }
                }
            }

            for (int j = 0; j < 2; j++)
            {
                while (Cells[x, y].Item != null || Cells[x, y].Monster != null)
                {
                    x = rand.Next(rows);
                    y = rand.Next(cols);
                }

                if (Cells[x, y].Item == null && Cells[x, y].Monster == null)
                {
                    if (j == 0)
                    {
                        Cells[x, y].Item = door;
                    }

                    else if (j == 1)
                    {
                        Cells[x, y].Item = doorKey;
                    }
                }
            }
        }
Exemple #4
0
 public void RemoveKey()
 {
     _DoorKey = null;
 }