コード例 #1
0
        private void LoadDisplay(PictureBox pBox, Bitmap robotBitmap, Robot robot)
        {
            switch(robot.getOrientation())
            {
                case("W"):
                {
                    //  Rotate 90 degrees counter clockwise
                    robotBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    pBox.Image = robotBitmap;
                }
                break;
                case ("S"):
                    {
                        //  Rotate 90 degrees counter clockwise
                        robotBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        pBox.Image = robotBitmap;
                    }
                    break;
                case ("E"):
                    {
                        //  Rotate 90 degrees counter clockwise
                        robotBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        pBox.Image = robotBitmap;
                    }
                    break;
                default:
                    break;
            }

            //  Position the robot's initial position on the arena
            pBox.Location = new Point(X_map(robot.getPositionX()), Y_map(robot.getPositionY()));
        }
コード例 #2
0
ファイル: RobotWarsInit.cs プロジェクト: pascalhow/RobotWars
        private void initialise_btn_Click(object sender, EventArgs e)
        {
            //  Display user input
            Output_initPage_textbox.AppendText("Grid size: " + thisGrid.HorizontalCells.ToString() + " " +
                thisGrid.VerticalCells.ToString() + " " + Environment.NewLine + Environment.NewLine);

            //  A robot needs these parameters to start: x coordinate, y coordinate, orientation, x origin, y origin, gridth width, grid height
            //  Tell robot 1 how big the battlefield is and give it its coordinates
            robot_1 = new Robot(Int32.Parse(robot_1_positionX_cbox.Text), Int32.Parse(robot_1_positionY_cbox.Text), robot_1_orientation_cbox.Text, origin_x, origin_y, thisGrid.HorizontalCells, thisGrid.VerticalCells);
            string R1_currentPosition = robot_1_positionX_cbox.Text + " " + robot_1_positionY_cbox.Text + " " + robot_1_orientation_cbox.Text;
            string R1_newPosition = robot_1.calculatePlannedPosition(robot1_FirstMove_textbox.Text);

            //  Display user input
            Output_initPage_textbox.AppendText("******* Robot 1 *******" + Environment.NewLine +
                "Initial Position: " + R1_currentPosition + Environment.NewLine +
                "First move: " + robot1_FirstMove_textbox.Text + Environment.NewLine +
                "New Position: " + R1_newPosition + Environment.NewLine + Environment.NewLine);

            //  Tell robot 2 how big the battlefield is and give it its coordinates
            robot_2 = new Robot(Int32.Parse(robot_2_positionX_cbox.Text), Int32.Parse(robot_2_positionY_cbox.Text), robot_2_orientation_cbox.Text, origin_x, origin_y, thisGrid.HorizontalCells, thisGrid.VerticalCells);
            string R2_currentPosition = robot_2_positionX_cbox.Text + " " + robot_2_positionY_cbox.Text + " " + robot_2_orientation_cbox.Text;
            string R2_newPosition = robot_2.calculatePlannedPosition(robot2_FirstMove_textbox.Text);

            //  Display user input
            Output_initPage_textbox.AppendText("******* Robot 2 *******" + Environment.NewLine +
                "Initial Position: " + R2_currentPosition + Environment.NewLine +
                "First move: " + robot2_FirstMove_textbox.Text + Environment.NewLine +
                "New Position: " + R2_newPosition + Environment.NewLine + Environment.NewLine);

            Output_initPage_textbox.AppendText("Press Go button to go to the Arena!" + Environment.NewLine);

            Go_btn.Enabled = true;
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: RobotWarConsole.cs プロジェクト: hibri/RobotWars
        public void ParseInput(string line)
        {
            if (InitialPositionRegex.IsMatch(line)) {
                Robot robot = CreateRobot();
                robot.ParsePosition(line);
                _robots.Add(robot);
            }
            else if (MoveRegex.IsMatch(line)) {
                _robot = _robots.Last();
                _robot.ParseMove(line);
                Console.WriteLine(_robot.GetCurrentPosition());

            }
        }
コード例 #6
0
 protected void save_Click(object sender, EventArgs e)
 {
     if (robotFile1.HasFile)
     {
         string file1 = Server.MapPath("~/Files/") + robotFile1.FileName;
         if (System.IO.File.Exists(file1))
             System.IO.File.Delete(file1);
         robotFile1.SaveAs(file1);
         Robot robot = new Robot();
         robot.LoadFromXml(file1);
         if (robot.Rounds != null && robot.Rounds.Count > 0)
         {
             if (robot.VerifyUniqueRobot())
                 robot.SaveInDB();
         }
         System.IO.File.Delete(file1);
     }
 }
コード例 #7
0
ファイル: Game.cs プロジェクト: jasonmitchell/robot-wars
 private static void IssueCommand(Robot robot, string commandInput)
 {
     foreach (var command in commandInput)
     {
         switch (command)
         {
             case 'L':
                 robot.TurnLeft();
                 break;
             case 'R':
                 robot.TurnRight();
                 break;
             case 'M':
                 robot.Move();
                 break;
             default:
                 throw new UnknownCommandException(command);
         }
     }
 }
コード例 #8
0
ファイル: RobotTest.cs プロジェクト: pmarflee/RobotWars
        public void SecondRobotMovementTest()
        {
            //3 3 E
            //MMRMMRMRRM

            _robot = new Robot(new Coordinate(3, 3), Orientation.E, _grid);

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

            Assert.AreEqual(5, _robot.Pos.X);
            Assert.AreEqual(1, _robot.Pos.Y);
            Assert.AreEqual(Orientation.E, _robot.Or);
        }
コード例 #9
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);
        }
コード例 #10
0
        private void RobotWarBattleField_Form_Load(object sender, EventArgs e)
        {
            //  Set the grid size of battlefield based on number of grids in both x and y directions
            gridCellSizeHorizontal = ((battleground_panel.Size.Width - 2 * gridStartLocationX) / gridProperty.HorizontalCells);
            gridCellSizeVertical = ((battleground_panel.Size.Height - 2 * gridStartLocationY) / gridProperty.VerticalCells);

            //  Set the grid parameters
            thisGrid.Origin = new Point(gridStartLocationX, gridStartLocationY);
            thisGrid.GridCellSize = new Size(gridCellSizeHorizontal, gridCellSizeVertical);
            thisGrid.HorizontalCells = gridProperty.HorizontalCells;
            thisGrid.VerticalCells = gridProperty.VerticalCells;

            //  Load robot parameters from previous form
            robot_1 = robot_1_property;
            robot_2 = robot_2_property;

            //  Load and position the robots on the battlefield
            R1_pbox.Image = robot_1_bitmap;
            R1_pbox.SizeMode = PictureBoxSizeMode.StretchImage;
            robot_1.setRobotDimensions(R1_pbox.Size.Width,R1_pbox.Size.Height);
            LoadDisplay(R1_pbox, robot_1_bitmap, robot_1);

            R2_pbox.Image = robot_2_bitmap;
            R2_pbox.SizeMode = PictureBoxSizeMode.StretchImage;
            robot_2.setRobotDimensions(R2_pbox.Size.Width, R2_pbox.Size.Height);
            LoadDisplay(R2_pbox, robot_2_bitmap, robot_2);

            //  Load robots starting position
            R1_newPosition_lbl.Text = "Position: " + robot_1.getPositionX() + " " + robot_1_property.getPositionY() + " " + robot_1.getOrientation();
            R2_newPosition_lbl.Text = "Position: " + robot_2.getPositionX() + " " + robot_2_property.getPositionY() + " " + robot_2.getOrientation();

            if ((robot_1.getPositionX() == robot_2.getPositionX()) && (robot_1.getPositionY() == robot_2.getPositionY()))
            {
                Output_battlePage_textbox.AppendText("First move does not count..." + Environment.NewLine + Environment.NewLine);
            }
        }
コード例 #11
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);
 }
コード例 #12
0
ファイル: UserInterface.cs プロジェクト: pmarflee/RobotWars
 /// <summary>
 ///  Static method creates a new robot at a specified position and orientation
 /// </summary>
 private static void CreateRobot(int x, int y, String orientation)
 {
     var pos = new Coordinate(x, y);
     _robot = new Robot(pos, (Orientation)Enum.Parse(typeof(Orientation), orientation, true), _grid);
 }