コード例 #1
0
        // Move the player, and return a new level if applicable
        public LevelTransition MovePlayer(Player player, Constants.DIRECTION dir)
        {
            LevelTransition  newLevel  = null;
            Tuple <int, int> playerLoc = player.GetCoords();
            char             entity    = Map[playerLoc.Item1, playerLoc.Item2];
            int xToCheck = playerLoc.Item1;
            int yToCheck = playerLoc.Item2;

            switch (dir)
            {
            case Constants.DIRECTION.NORTH:
                xToCheck--;
                break;

            case Constants.DIRECTION.EAST:
                yToCheck++;
                break;

            case Constants.DIRECTION.SOUTH:
                xToCheck++;
                break;

            case Constants.DIRECTION.WEST:
                yToCheck--;
                break;
            }

            if (Map[xToCheck, yToCheck] == (char)Constants.MAP_CHARS.EMPTY)
            {
                Map[xToCheck, yToCheck] = entity;
                Map[playerLoc.Item1, playerLoc.Item2] = (char)Constants.MAP_CHARS.EMPTY;
                player.SetCoords(Tuple.Create(xToCheck, yToCheck));
                MoveEnemies(player);
                RunModifiers(player);
            }
            else if (Map[xToCheck, yToCheck] == (char)Constants.MAP_CHARS.EXIT)
            {
                newLevel = Exits.Where(x => x.ExitLocation.Item1 == xToCheck && x.ExitLocation.Item2 == yToCheck).FirstOrDefault();
                ResetCell(player.GetCoords());
            }
            else if (Map[xToCheck, yToCheck] == (char)Constants.MAP_CHARS.ITEMBOX)
            {
                ItemBox item = ItemBoxs.Where(x => x.XCoord == xToCheck && x.YCoord == yToCheck).First();

                if (item != null)
                {
                    player.ConsumeItemBox(item);
                    ItemBoxs.Remove(item);
                    Map[playerLoc.Item1, playerLoc.Item2] = (char)Constants.MAP_CHARS.EMPTY;
                    Map[xToCheck, yToCheck] = (char)Constants.MAP_CHARS.CHARACTER;
                    player.SetCoords(Tuple.Create(xToCheck, yToCheck));
                    MoveEnemies(player);
                    RunModifiers(player);
                }
            }

            return(newLevel);
        }
コード例 #2
0
        public Enemy(int health = 10, int attack = 5, int defense = 10, int x = 0, int y = 0)
        {
            Health  = health;
            Attack  = attack;
            Defense = defense;
            XCoord  = x;
            YCoord  = y;
            Reward  = null;

            if (Health > 1)
            {
                Alive = true;
            }
            else
            {
                Alive = false;
            }
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: TheFirstLairron/HackSlash
 // Process the contents of an item box
 public void ConsumeItemBox(ItemBox box)
 {
     if (box.Reward is UsableItem)
     {
         Inventory.AddItem(box.Reward as UsableItem);
         Game.CurrentMessage = $"You found {box.Reward.Name}";
     }
     else if (box.Reward is KeyItem)
     {
         Inventory.AddKeyItem(box.Reward as KeyItem);
         Game.CurrentMessage = $"You found {box.Reward.Name}";
     }
     else if (box.Reward is Weapon)
     {
         Inventory.AddWeapon(box.Reward as Weapon);
         Game.CurrentMessage = $"You found {box.Reward.Name}";
     }
 }