예제 #1
0
        public void Init()
        {
            field    = new FieldController();
            player   = new Player();
            ball     = new Ball();
            physics  = new ControllerPhysics();
            computer = new Computer();

            player.score = 0;

            scoreLabel.Text = "Score: " + player.score;

            this.Width  = (FieldController.fieldWidth + 2) * 10;
            this.Height = (FieldController.fieldHeight + 5) * 10;

            updateFieldTimer.Interval = 30;


            player.playerPadX = 0;
            player.playerPadY = (FieldController.fieldHeight - 12) / 2;

            ball.ballLocationX = player.playerPadX + 1;
            ball.ballLocationY = player.playerPadY + (Player.playerPadWidth / 2) - 2;

            computer.computerPadX = FieldController.fieldWidth - 1;
            computer.computerPadY = (FieldController.fieldHeight - 12) / 2;


            field.field[player.playerPadY, player.playerPadX] = Player.playerPadLocation;
            for (int i = 1; i < Player.playerPadWidth; i++)
            {
                field.field[player.playerPadY + i, player.playerPadX] = Player.playerPadBox;
            }
            field.field[computer.computerPadY, computer.computerPadX] = Computer.computerPadLocation;
            for (int i = 1; i < Computer.computerPadWidth; i++)
            {
                field.field[computer.computerPadY + i, computer.computerPadX] = Computer.computerPadBox;
            }

            field.field[ball.ballLocationY, ball.ballLocationX] = Ball.ballLocation;
            ball.ballDirectionX = 1;
            ball.ballDirectionY = -1;

            updateFieldTimer.Start();
        }
예제 #2
0
 public void computerAI(FieldController field, Ball ball)
 {
     field.field[computerPadY, computerPadX] = 0;
     for (int i = 1; i < computerPadWidth - 1; i++)
     {
         field.field[computerPadY + i, computerPadX] = 0;
     }
     if (ball.ballLocationY < computerPadY && computerPadY > 0)
     {
         computerPadY--;
     }
     else if (ball.ballLocationY > computerPadY && computerPadY + computerPadWidth < FieldController.fieldHeight)
     {
         computerPadY++;
     }
     field.field[computerPadY, computerPadX] = computerPadLocation;
     for (int i = 1; i < computerPadWidth - 1; i++)
     {
         field.field[computerPadY + i, computerPadX] = computerPadBox;
     }
 }