コード例 #1
0
        public void WhenIMove(ActionSide side, Location from, Location to)
        {
            Assert.NotNull(_context.BoardState, "Board State has not been initialized.");
            var action = new GameMoveAction {
                Location = from, Side = side, Target = to
            };

            TryApplyAction(action, from, to);
        }
コード例 #2
0
        public void WhenIMovePointsDirection(ActionSide side, Location from, string distance, string direction)
        {
            Assert.NotNull(_context.BoardState, "Board State has not been initialized.");

            var distanceInt = CommonSteps.ParseWordNumber(distance);

            Movement.Mover directionFunc;
            switch (direction.ToLower().Trim())
            {
            case "north":
                directionFunc = Movement.North;
                break;

            case "south":
                directionFunc = Movement.South;
                break;

            case "northeast":
            case "north-east":
            case "north east":
                directionFunc = Movement.NorthEast;
                break;

            case "northwest":
            case "north-west":
            case "north west":
                directionFunc = Movement.NorthWest;
                break;

            case "southeast":
            case "south-east":
            case "south east":
                directionFunc = Movement.SouthEast;
                break;

            case "southwest":
            case "south-west":
            case "south west":
                directionFunc = Movement.SouthWest;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction,
                                                      "Was not a recognizable movement direction.");
            }

            var canPassRedWall  = side == ActionSide.Blue ? Movement.Red.CanWrap : Movement.Red.CannotWrap;
            var canPassBlueWall = side == ActionSide.Red ? Movement.Blue.CanWrap : Movement.Blue.CannotWrap;

            var to = from;

            for (var i = 0; i < distanceInt; i++)
            {
                var next = directionFunc(to, canPassBlueWall, canPassRedWall, Movement.UnmarkedEdges.CannotWrap);
                if (!Movement.IsValidLocation(next))
                {
                    _context.LastMessage = $"Unable to reach point {i + 1} {direction} from {to} (starting from {from})";
                    Console.WriteLine(_context.LastMessage);
                    return;
                }
                to = next;
            }

            var action = new GameMoveAction {
                Location = from, Side = side, Target = to
            };

            TryApplyAction(action, from, to);
        }