Esempio n. 1
0
        public MoveResultWrapper MovePlayer(Player player, string direction, IEnumerable<Client> clients)
        {
            var newX = player.Coordinates.X;
            var newY = player.Coordinates.Y;
            switch (direction)
            {
                case "UP":
                    newY--;
                    break;
                case "DOWN":
                    newY++;
                    break;
                case "LEFT":
                    newX--;
                    break;
                case "RIGHT":
                    newX++;
                    break;
                default:
                    return new MoveResultWrapper { MoveResult = MoveResult.Fail };
            }
            Player enemy;
            var result = GetTileContent(newX, newY, clients, out enemy);
            switch (result)
            {
                case MoveResult.Fail:
                    return new MoveResultWrapper { MoveResult = MoveResult.Fail };
                case MoveResult.Gold:
                    player.Coordinates.X = newX;
                    player.Coordinates.Y = newY;
                    player.Gold += GameMap[newX, newY].Gold;
                    GameMap[newX, newY].Gold = 0;
                    return new MoveResultWrapper { MoveResult = MoveResult.Gold };
                case MoveResult.Potion:
                    player.Coordinates.X = newX;
                    player.Coordinates.Y = newY;
                    player.Health += GameMap[newX, newY].Health;
                    GameMap[newX, newY].Health = 0;
                    return new MoveResultWrapper { MoveResult = MoveResult.Potion };
                case MoveResult.Success:
                    player.Coordinates.X = newX;
                    player.Coordinates.Y = newY;
                    return new MoveResultWrapper { MoveResult = MoveResult.Success };
                case MoveResult.Player:
                    enemy.Health -= player.Attack;
                    return new MoveResultWrapper { MoveResult = MoveResult.Player, Player = enemy };
                default:
                    return new MoveResultWrapper { MoveResult = MoveResult.Fail };

            }
        }
Esempio n. 2
0
 public bool IsPlayerAdjacentInGivenDirection(Player other, Direction direction)
 {
     switch (direction)
     {
         case Direction.North:
             return Coordinates.X == other.Coordinates.X && Coordinates.Y - 1 == other.Coordinates.Y;
         case Direction.South:
             return Coordinates.X == other.Coordinates.X && Coordinates.Y + 1 == other.Coordinates.Y;
         case Direction.East:
             return Coordinates.X + 1 == other.Coordinates.X && Coordinates.Y == other.Coordinates.Y;
         case Direction.West:
             return Coordinates.X - 1 == other.Coordinates.X && Coordinates.Y == other.Coordinates.Y;
         default:
             return false;
     }
 }
Esempio n. 3
0
        private MoveResult GetTileContent(int x, int y, IEnumerable<Client> clients, out Player enemyPlayer)
        {
            enemyPlayer = null;
            if (x >= GameMap.GetLength(0) || y >= GameMap.GetLength(1) || GameMap[x, y].IsCaveWall)
                return MoveResult.Fail;
            if (GameMap[x, y].HasGold)
                return MoveResult.Gold;
            if (GameMap[x, y].HasHealth)
                return MoveResult.Potion;
            foreach (var client in clients)
            {
                var player = client.Player;
                if (player.Coordinates.X == x && player.Coordinates.Y == y)
                {
                    enemyPlayer = player;
                    return MoveResult.Player;
                }
            }

            return MoveResult.Success;
        }