Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This code is protected under the Gnu General Public License (Copyleft), 2005 by
- * IBM and the Computer Science Teachers Association. It may be freely
- * modified and redistributed under educational fair use.
- */
- import csta.ibm.pong.Game;
- public class Pong extends Game
- {
- // Add any state variables or object references here
- Ball b = new Ball();
- Paddle p1 = new Paddle();
- Paddle p2 = new Paddle();
- private static int ballSize;
- private static int paddleHeight;
- private static int width;
- private static int x, y;
- /**
- * Fill in this method with code that tells the game what to do
- * before actual play begins
- */
- public void setup()
- {
- ballSize = 10;
- paddleHeight = 10;
- width = 100;
- b.setColor(java.awt.Color.red);
- p1.setColor(java.awt.Color.green);
- p2.setColor(java.awt.Color.green);
- b.setX(185);
- b.setY(150);
- p1.setX(0);
- p1.setY(145);
- p2.setX(375);
- p2.setY(145);
- b.setSize(10, 10);
- p1.setSize(10, 50);
- p2.setSize(10, 50);
- add(b);
- add(p1);
- add(p2);
- setBackground(java.awt.Color.blue);
- getContentPane().repaint();
- }
- /**
- * Fill in this method with code that tells the playing field what to do
- * from one moment to the next
- */
- public void act()
- {
- if(ZKeyPressed())
- {
- p1.moveUp();
- }
- if(XKeyPressed())
- {
- p1.moveDown();
- }
- if(MKeyPressed())
- {
- p2.moveUp();
- }
- if(NKeyPressed())
- {
- p2.moveDown();
- }
- getContentPane().repaint();
- }
- // Add any additional methods here
- /**
- * This code has been provided for you, and should not be modified
- */
- public static void main(String[] args)
- {
- Pong p = new Pong();
- p.setVisible(true);
- p.initComponents();
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- /*
- * This code is protected under the Gnu General Public License (Copyleft), 2005 by
- * IBM and the Computer Science Teachers Association. It may be freely
- * modified and redistributed under educational fair use.
- */
- import csta.ibm.pong.GameObject;
- public class Paddle extends GameObject
- {
- // Add any state variables here
- /**
- * Fill in this method with code that describes the behavior
- * of a paddle from one moment to the next
- */
- public void act()
- {
- }
- // Add any additional methods here
- public void moveUp()
- {
- setY(5);
- }
- public void moveDown()
- {
- setY(-5);
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- /*
- * This code is protected under the Gnu General Public License (Copyleft), 2005 by
- * IBM and the Computer Science Teachers Association. It may be freely
- * modified and redistributed under educational fair use.
- */
- import csta.ibm.pong.GameObject;
- public class Ball extends GameObject
- {
- // Add any state variables here
- private static int xVelocity;
- private static int yVelocity;
- private static int MAXX;
- private static int MAXY;
- int randomNumber;
- /**
- * Fill in this method with code that describes the behavior
- * of a ball from one moment to the next
- */
- public void act()
- {
- }
- // Add any additional methods here
- }
Advertisement
Add Comment
Please, Sign In to add comment