Exemplo n.º 1
0
        public Robot(Position position, Direction direction, BattleArena battleArena)
        {
            IsRobotValid(position, direction, battleArena);

            Id          = battleArena.Robots.Count;
            Position    = position;
            Direction   = direction;
            BattleArena = battleArena;

            battleArena.Robots.Add(this);
        }
Exemplo n.º 2
0
        // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
        private void IsRobotValid(Position position, Direction direction, BattleArena battleArena)
        {
            if (!Enum.IsDefined(typeof(Direction), direction))
            {
                throw new ArgumentException("Invalid direction. Can't create the robot.");
            }

            if (battleArena.IsFull())
            {
                throw new ArgumentException("Can't add the robot because the battle arena is full.");
            }

            if (!battleArena.IsPositionInsideBattleArena(position))
            {
                throw new ArgumentException("Invalid starting position. Robot can't start outside the battle arena.");
            }

            if (!battleArena.IsPositionUnoccupied(battleArena.Robots.Count, position))
            {
                throw new ArgumentException("Invalid starting position. Robot can't be in the same place as another robot.");
            }
        }