This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kronos
Kronos wrote ...

2017/5/8

Programming A.i. for Pong

1
2
3
danpost danpost

2017/5/15

#
And the PlayerPick class, now.
Kronos Kronos

2017/5/16

#
Here it is.
public static int red;
    public static int blue;
     /**
     * Constructor for objects of class PlayerPick.
     * The screen where the user will decide which paddle they want to use.
     */
    public PlayerPick() 
    {    
        super(1080, 600, 1); // Create a new world with 1100x600 cells with a cell size of 1x1 pixels.
        addObject(new BackToOption(),150,560); //Creates a object of class BackButton
        BlueRedPlayerPick bluepick = new BluePick();
        addObject(bluepick,420,530); //Creates a object of class BluePick
        BlueRedPlayerPick redpick = new RedPick();
        addObject(redpick,675,530); //Creates a object of class RedPick
        Start start2 = new Start2();
        addObject(start2,975,560); //Creates a object of class Start2
    }
danpost danpost

2017/5/16

#
You probably still need something like the following in both the Red and Blue classes (example for Red class):
public Red()
{
    PlayerRedControlled = PlayerPick.red;
}
Kronos Kronos

2017/5/18

#
Line 20 and 32 needed to have '==' not '=' Line 32 was not indented enough, so it was being called as the else statement to line 18
Kronos wrote...
boolean playerBlueControlled;
    /**
     * Act - do whatever the Blue wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKeypress(); // This statement calls the checkKeyPress method.
    }    
    
    /**
     * Check whether a control key on the keyboard has been pressed.
     * If it has, react accordingly.
     */
    public void checkKeypress()
    {
        Actor pongball = getWorld().getObjects(PongBall.class).get(0);
        if(pongball.getX() < 490)
        {
            if(playerBlueControlled = true)
            {
                if (Greenfoot.isKeyDown("w")) // Pressing the w key will move the blue paddle up.
                {       
                    setLocation(getX(),getY() - 10);
                }
                if (Greenfoot.isKeyDown("s")) // Pressing the s key will move the blue paddle down.
                {
                    setLocation(getX(),getY() + 10);
                }
            }
        }
        else if(playerBlueControlled = false)
        {
             if(getY() > pongball.getY())
             {
                 if(Greenfoot.getRandomNumber(5) != 0)
                 {
                     setLocation(getX(),getY() - 10); 
                 }
                 else 
                 {
                     setLocation(getX(),getY() - 5); 
                 }
             }
             else if(getY() < pongball.getY())
             {
                 if(Greenfoot.getRandomNumber(5) != 0)
                 {
                     setLocation(getX(),getY() + 10); 
                 }
                 else 
                 {
                     setLocation(getX(),getY() + 5); 
                 }
             }
        }
        BorderCheck();    // This statement calls the BorderCheck method
    }
danpost danpost

2017/5/18

#
Kronos wrote...
Line 20 and 32 needed to have '==' not '=' Line 32 was not indented enough, so it was being called as the else statement to line 18
I missed all that in the one class (I had expected the corrections in the other class to be made in that one also -- but, they were not).
Kronos Kronos

2017/5/18

#
danpost wrote...
Kronos wrote...
Line 20 and 32 needed to have '==' not '=' Line 32 was not indented enough, so it was being called as the else statement to line 18
I missed all that in the one class (I had expected the corrections in the other class to be made in that one also -- but, they were not).
No problem. I had not been looking for minor errors like that either. Anyway, the entire game now works. Thank you so much for your assistance. It is much appreciated.
You need to login to post a reply.
1
2
3