Пример #1
0
        private static Coords NewCoords(Coords coords, Direction.Facing facing)
        {
            Coords newCoords = new Coords(coords.GetRow(), coords.GetCol());

            switch (facing)
            {
            case Direction.Facing.NORTH:
                newCoords.SetRow(newCoords.GetRow() + 1);
                break;

            case Direction.Facing.EAST:
                newCoords.SetCol(newCoords.GetCol() + 1);
                break;

            case Direction.Facing.SOUTH:
                newCoords.SetRow(newCoords.GetRow() - 1);
                break;

            case Direction.Facing.WEST:
                newCoords.SetCol(newCoords.GetCol() - 1);
                break;

            default:
                break;
            }
            return(newCoords);
        }
Пример #2
0
        public void CanRotateLeft()
        {
            facing = Direction.Facing.EAST;
            var result = Direction.Left(facing);

            Assert.Equal(Direction.Facing.NORTH, result);
        }
Пример #3
0
        public void CanRotateRight()
        {
            facing = Direction.Facing.EAST;
            var result = Direction.Right(facing);

            Assert.Equal(Direction.Facing.SOUTH, result);
        }
Пример #4
0
        public void CanLoopRight()
        {
            facing = Direction.Facing.EAST;
            var result = facing;

            for (int i = 0; i < 9; i++)
            {
                result = Direction.Right(result);
            }
            Assert.Equal(Direction.Facing.SOUTH, result);
        }
Пример #5
0
        public static Coords Move(Table table, Coords coords, Direction.Facing facing)
        {
            Coords newCoords = NewCoords(coords, facing);

            if (table.IsOnBoard(newCoords))
            {
                return(newCoords);
            }
            else
            {
                return(coords);
            }
        }
Пример #6
0
        public void Place(int row, int column, Direction.Facing facing)
        {
            Coords coords = new Coords(row, column);

            if (table.IsOnBoard(coords))
            {
                this.coords = coords;
                this.facing = facing;
            }
            else
            {
                Console.WriteLine("Invalid Place Command - coordinates must be on the table");
            }
        }
Пример #7
0
        public void ExecuteCommand(string command)
        {
            string function = command.Split(' ')[0].ToUpper();

            //Console.WriteLine(function);
            try
            {
                switch (function)
                {
                case "PLACE":
                    string[]         placementData = command.Split(' ')[1].ToUpper().Split(',');
                    int              row           = Int32.Parse(placementData[0]);
                    int              col           = Int32.Parse(placementData[1]);
                    Direction.Facing facing        = Direction.GetFacing(command.Split(' ')[1].ToUpper().Split(',')[2]);
                    Place(row, col, facing);
                    break;

                case "RIGHT":
                    Right();
                    break;

                case "LEFT":
                    Left();
                    break;

                case "MOVE":
                    Move();
                    break;

                case "REPORT":
                    Report();
                    break;

                default:
                    break;
                }
            }
            catch
            {
                Console.WriteLine("INVALID COMMAND");
            }
        }
Пример #8
0
 public void Right()
 {
     facing = Direction.Right(facing);
 }
Пример #9
0
 public void Left()
 {
     facing = Direction.Left(facing);
 }