コード例 #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
        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);
            }
        }