Пример #1
0
 public Rover(string name, Plateau plateau, Position position)
 {
     _plateau = plateau;
     _movements = new List<Position>();
     Name = name;
     Apply(position);
 }
Пример #2
0
 private void Apply(Position position)
 {
     if (!_plateau.Contains(position))
     {
         return;
     }
     _movements.Add(position);
     Position = position;
 }
Пример #3
0
        public Position Left()
        {
            var position = new Position
            {
                X = X,

                Y = Y,

                Direction = Turn(-90)
            };
            return position;
        }
Пример #4
0
        public bool Contains(Position position)
        {
            if (position.X > Width)
            {
                return false;
            }

            if (position.Y > Height)
            {
                return false;
            }

            if (position.X < 0)
            {
                return false;
            }

            if (position.Y < 0)
            {
                return false;
            }

            return true;
        }
Пример #5
0
        public Position Right()
        {
            var position = new Position
                {
                    X = X,

                    Y = Y,

                    Direction = Turn(90)
                };

            return position;
        }
Пример #6
0
        public Position Move()
        {
            var position = new Position
            {
                Direction = Direction,

                Y = new Func<int>(() => {

                    if (Direction == Direction.N)
                    {
                        return Y + 1;
                    }

                    if (Direction == Direction.S)
                    {
                        return Y - 1;
                    }

                    return Y;
                })(),

                X = new Func<int>(() =>
                {
                    if (Direction == Direction.E)
                    {
                        return X + 1;
                    }

                    if (Direction == Direction.W)
                    {
                        return X - 1;
                    }

                    return X;
                })()
            };

            return position;
        }