示例#1
0
        /// <exception cref="System.Exception">Throws when specified robot does not exist</exception>
        public void Left(Guid robotId)
        {
            var robot = Robots.FirstOrDefault(r => r.RobotId == robotId);

            if (robot == null)
            {
                throw new Exception("Robot for specified id does not exist");
            }

            robot.Left();
        }
示例#2
0
        /// <summary>place a robot with a given id and direction on the board </summary>
        /// <exception cref="System.Exception">Throws when allowed robot limit is reached </exception>
        /// <exception cref="System.Exception">Throws when x and y position are invalid </exception>
        public void Place(Guid robotId, int x, int y, Direction direction)
        {
            var robot = Robots.FirstOrDefault(r => r.RobotId == robotId);

            if (robot == null)
            {
                if (Robots.Count >= NumberOfRobotsAllowed)
                {
                    throw new Exception("Unable to place any more robots on the board as you have reached the allowed limit");
                }
                robot = new Robot.Robot(direction, robotId);
                Robots.Add(robot);
            }
            else
            {
                robot.Direction = direction;
            }
            _board.Place(robotId, x, y);
        }
示例#3
0
 private void OnDetectedRobotChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     //実装側がそういうシステムなので基本的にAdd/Removeのどちらか片方しか生じない
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         foreach (var robot in e.NewItems.OfType <DetectedRobot>())
         {
             Robots.Add(CreateDetectedRobotViewModel(robot));
         }
     }
     else if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         foreach (var robot in e.NewItems.OfType <DetectedRobot>())
         {
             var target = Robots.FirstOrDefault(r => r.HasRobot(robot));
             if (target != null)
             {
                 Robots.Remove(target);
             }
         }
     }
 }
示例#4
0
        /// <exception cref="System.Exception">Throws when specified robot does not exist</exception>
        /// <exception cref="System.Exception">Throws when moving to invalid location</exception>
        public void Move(Guid robotId)
        {
            var robot = Robots.FirstOrDefault(r => r.RobotId == robotId);

            if (robot == null)
            {
                throw new Exception("Robot for specified id does not exist, place robot on the board again");
            }

            var currentCoords = _board.PlayArea.IndexOf(robotId);

            if (currentCoords == (-1, -1))
            {
                throw new Exception("Cannot find robot on the board, place same robot on the board again");
            }

            var deltaCoords = robot.Move();
            var newX        = currentCoords.x + deltaCoords.x;
            var newY        = currentCoords.y + deltaCoords.y;

            _board.Place(robotId, newX, newY);
        }
示例#5
0
 public Robot GetRobot(string robotId)
 {
     return(Robots.FirstOrDefault(r => r.RobotId == robotId));
 }