Ejemplo n.º 1
0
        private double GetAngle(MapPosition pos1, MapPosition pos2)
        {
            float deltaX = pos2.X - pos1.X;
            float deltaY = pos2.Y - pos1.Y;

            return(Math.Atan2(deltaY, deltaX) * 180.0 / Math.PI);
        }
Ejemplo n.º 2
0
        private PlayerInstance GetClosestEnemy()
        {
            var allEnemyPosition = new List <MapPosition>();

            // traverse ViewRadius
            for (var i = 1; i <= _player.ViewRadius; i++)
            {
                for (var j = 1; j <= _player.ViewRadius; j++)
                {
                    var x = _player.Position.X - _player.ViewRadius + i;
                    var y = _player.Position.Y - _player.ViewRadius + j;
                    var inspectedPosition = new MapPosition(x, y);
                    if (!MapPosition.IsOutOfBounds(inspectedPosition))
                    {
                        var field = Map.GetField(x, y);
                        if (MapPosition.IsOccupied(field))
                        {
                            allEnemyPosition.Add(field);
                        }
                    }
                }
            }

            if (allEnemyPosition.Count > 0)
            {
                allEnemyPosition.Sort((origin, position) =>
                                      (int)(Vector2.Distance(position.DistanceAsVector(), origin.DistanceAsVector()) * 100));
                return(allEnemyPosition[0].Occupant);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private Direction GetCenterDirection()
        {
            var centerFields = MapCenter();
            var freeField    = centerFields.First(t => MapPosition.IsOccupied(t) == false);
            var angle        = GetAngle(_player.Position, freeField);

            return(AdvanceDirection(angle));
        }
Ejemplo n.º 4
0
 public void Attack(MapPosition targetPosition)
 {
     if (MapPosition.IsOccupied(targetPosition) && _player.ActionPoints > 0)
     {
         var target = targetPosition.Occupant;
         target.Hitpoints     -= 1;
         _player.ActionPoints -= 1;
     }
 }
Ejemplo n.º 5
0
 public PlayerInstance(int playerId, string name, Character character, int hitpoints, MapPosition position, int viewRadius)
 {
     PlayerId     = playerId;
     Name         = name;
     Character    = character;
     Hitpoints    = hitpoints;
     Position     = position;
     _playerAi    = new PlayerAI(this, null);
     ActionPoints = 1; // to make testing easier
     ViewRadius   = viewRadius;
 }
Ejemplo n.º 6
0
        public void Move(Direction direction)
        {
            var newPosition = _player.Position;

            switch (direction)
            {
            case Direction.Up:
                newPosition.Y -= 1;
                break;

            case Direction.Down:
                newPosition.Y += 1;
                break;

            case Direction.Left:
                newPosition.X -= 1;
                break;

            case Direction.Right:
                newPosition.X += 1;
                break;

            case Direction.None:
                goto default;

            default:
                break;
            }

            if (newPosition.MovementOutOfBounds(direction) && !MapPosition.IsOccupied(newPosition) &&
                _player.ActionPoints > 0)
            {
                _player.Position      = newPosition;
                _player.ActionPoints -= 1;
            }
        }
Ejemplo n.º 7
0
 public static bool IsOccupied(MapPosition position)
 {
     return(position.Occupant != null);
 }
Ejemplo n.º 8
0
 public static bool IsOutOfBounds(MapPosition position)
 {
     return(position.Y < 0 || position.Y > ArenaMap.ARENA_SIZE ||
            position.X < 0 || position.X > ArenaMap.ARENA_SIZE);
 }