Пример #1
0
        private List <IBattlefieldPlace> GetNearestPlaces()
        {
            var nearestPlaces = new List <IBattlefieldPlace>();
            // west
            var x = Position.X - 1;
            var y = Position.Y;

            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // east
            x = Position.X + 1;
            y = Position.Y;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // south
            x = Position.X;
            y = Position.Y - 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // north
            x = Position.X;
            y = Position.Y + 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // north-east
            x = Position.X + 1;
            y = Position.Y + 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // north-west
            x = Position.X - 1;
            y = Position.Y + 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // south-east
            x = Position.X + 1;
            y = Position.Y - 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }
            // south-west
            x = Position.X - 1;
            y = Position.Y - 1;
            if (!Battlefield.IsOutOfRange(x, y) && Battlefield[x, y].IsEmpty)
            {
                nearestPlaces.Add(Battlefield[x, y]);
            }

            nearestPlaces.Add(Position);
            return(nearestPlaces);
        }
Пример #2
0
        private string ExecuteTurnAction(Move move)
        {
            if (move.EnergyCost > EP)
            {
                return($"{Name} does not have enough energy to move.");
            }

            int newX = Position.X;
            int newY = Position.Y;

            switch (move.Direction)
            {
            case Direction.East:
                newX = Position.X + 1;
                break;

            case Direction.West:
                newX = Position.X - 1;
                break;

            case Direction.South:
                newY = Position.Y - 1;
                break;

            case Direction.North:
                newY = Position.Y + 1;
                break;

            case Direction.NorthEast:
                newY = Position.Y + 1;
                newX = Position.X + 1;
                break;

            case Direction.NorthWest:
                newY = Position.Y + 1;
                newX = Position.X - 1;
                break;

            case Direction.SouthEast:
                newY = Position.Y - 1;
                newX = Position.X + 1;
                break;

            case Direction.SouthWest:
                newY = Position.Y - 1;
                newX = Position.X - 1;
                break;
            }

            if (Battlefield.IsOutOfRange(newX, newY))
            {
                Destroy("force field");
                return($"{Name} moved into force field and exploded.");
            }

            if (Battlefield[newX, newY].IsEmpty == false)
            {
                return($"{Name} cannot move {move.Direction}, place is occupied.");
            }

            DrainEnergy(move.EnergyCost);
            PositionTo(newX, newY);
            return($"{Name} moves {move.Direction}.");
        }