コード例 #1
0
ファイル: RobotTest.cs プロジェクト: pmarflee/RobotWars
        public void RobotMovesOffGrid()
        {
            _grid = new Grid(30, 30);
            _coord = new Coordinate(0, 0);
            _robot = new Robot(_coord, Orientation.S, _grid);

            _robot.Move(Instruction.M, _grid);
        }
コード例 #2
0
ファイル: RobotTest.cs プロジェクト: pmarflee/RobotWars
        public void CreateRobot()
        {
            _grid = new Grid(30, 30);
            _coord = new Coordinate(10, 11);
            _robot = new Robot(_coord, Orientation.N, _grid);

            Assert.AreEqual(_coord.X, _robot.Pos.X);
            Assert.AreEqual(_coord.Y, _robot.Pos.Y);
            Assert.AreEqual(Orientation.N, _robot.Or);
        }
コード例 #3
0
ファイル: Robot.cs プロジェクト: pmarflee/RobotWars
        public Robot(Coordinate pos, Orientation or, Grid grid)
        {
            if (!grid.IsValid(pos))
            {
                throw new Exception("Robot placed outside of grid");
            }

            _pos = pos;
            _or = or;
        }
コード例 #4
0
ファイル: Robot.cs プロジェクト: pmarflee/RobotWars
 public void Move(Instruction inst, Grid grid)
 {
     switch (inst)
     {
         //Modulus used to cycle orientations. Limited definition of modulus with reference to negative
         //numbers result in initial incrementation by setsize to guarantee  positive result
         case Instruction.R:
             _or = (Orientation)Enum.ToObject(typeof(Orientation),
                 (((int)_or + NumOrientations + 1) % NumOrientations));
             break;
         case Instruction.L:
             _or = (Orientation)Enum.ToObject(typeof(Orientation),
                 (((int)_or + NumOrientations - 1) % NumOrientations));
             break;
         case Instruction.M:
             Coordinate newPos;
             switch (_or)
             {
                 case Orientation.N:
                     newPos = new Coordinate(_pos.X, _pos.Y + 1);
                     break;
                 case Orientation.E:
                     newPos = new Coordinate(_pos.X + 1, _pos.Y);
                     break;
                 case Orientation.S:
                     newPos = new Coordinate(_pos.X, _pos.Y - 1);
                     break;
                 case Orientation.W:
                     newPos = new Coordinate(_pos.X - 1, _pos.Y);
                     break;
                 default:
                     newPos = new Coordinate(-1, -1);
                     break;
             }
             if (grid.IsValid(newPos))
             {
                 _pos = newPos;
             }
             else
             {
                 throw new InvalidOperationException();
             }
         break;
     }
 }
コード例 #5
0
ファイル: RobotTest.cs プロジェクト: pmarflee/RobotWars
        public void FirstRobotMovementTest()
        {
            //1 2 N
            //LMLMLMLMM

            _grid = new Grid(5, 5);
            _robot = new Robot(new Coordinate(1, 2), Orientation.N, _grid);

            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.M, _grid);

            Assert.AreEqual(1, _robot.Pos.X);
            Assert.AreEqual(3, _robot.Pos.Y);
            Assert.AreEqual(Orientation.N, _robot.Or);
        }
コード例 #6
0
ファイル: GridTest.cs プロジェクト: pmarflee/RobotWars
 public void TestIsValidTrue()
 {
     var grid = new Grid(30,30);
     Assert.IsTrue(grid.IsValid(new Coordinate(30,1)));
 }
コード例 #7
0
ファイル: GridTest.cs プロジェクト: pmarflee/RobotWars
 public void TestIsValidFalseTooHigh()
 {
     var grid = new Grid(30,30);
     Assert.IsFalse(grid.IsValid(new Coordinate(31,3)));
 }
コード例 #8
0
ファイル: GridTest.cs プロジェクト: pmarflee/RobotWars
 public void TestIsValidFalseNeg()
 {
     var grid = new Grid(30,30);
     Assert.IsFalse(grid.IsValid(new Coordinate(20,-1)));
 }
コード例 #9
0
ファイル: RobotTest.cs プロジェクト: pmarflee/RobotWars
 public void CreateRobotInvalidPosition()
 {
     _grid = new Grid(30, 30);
     _coord = new Coordinate(1, -1);
     _robot = new Robot(_coord, Orientation.N, _grid);
 }
コード例 #10
0
ファイル: UserInterface.cs プロジェクト: pmarflee/RobotWars
 /// <summary>
 ///  Static method creates singleton grid of specified width and height
 /// </summary>
 private static void CreateGrid(int width, int height)
 {
     _grid = new Grid(width, height);
 }