示例#1
0
        public MoveResult TryMove(HexUtils.eMoveDirection direction, Robot robot)
        {
            MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");

            Hexagon targethex = GetAdjacentHexagon(robot.CurrentHexagon, direction);

            if (targethex != null)
            {
                result = HexUtils.isMoveAllowed(robot.CurrentHexagon, targethex, robot.UpJump, robot.DownJump);

                if (result.MoveResultStatus == MoveResult.eMoveResult.Success)
                {
                    robot.SetCurrentHexagon(targethex);
                    if (targethex.NE.Y == toprowy)
                    {
                        result.MoveResultStatus = MoveResult.eMoveResult.Complete;
                        result.ResultMessage = string.Format("The robot {0} made it across!", robot.SerialNumber.ToString());
                    }
                }
            }
            return result;
        }
示例#2
0
 public MoveResult TryMove(HexUtils.eMoveDirection direction, int index)
 {
     MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");
     result = TryMove(direction, this.Robots[index]);
     return result;
 }
示例#3
0
        private Hexagon GetAdjacentHexagon(Hexagon hex, HexUtils.eMoveDirection direction)
        {
            Hexagon result = new Hexagon();
            switch (direction)
            {
                case HexUtils.eMoveDirection.N:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.NE:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NESide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.SE:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SESide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.S:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.SW:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SWSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;

                case HexUtils.eMoveDirection.NW:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NWSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                default:
                    result = null;
                    break;
            }
            return result;
        }