Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 EARTH QUAKE PONG
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ify




PostPosted: Sun Jun 20, 2004 5:56 pm   Post subject: EARTH QUAKE PONG

i know that you all were amazed by my programming skills in my pong game and in my drunk walking in snow simulator but i have made a new game EARTHQUAKE PONG!!! (note i used "ready to program" to make it and if u had trouble with my pong game working then this one wont work sory Sad , if u wanna realy know it just makes the paddles shakey and the ball is wacky its the same a pong only shakey.)








code:

// The "EARTHQUAKEPONG" class.
import java.awt.*;
import javax.swing.*;

public class EARTHQUAKEPONG extends Frame
{

    // declaiations of variables
    int ballX = 200;
    int ballY = 330;
    int xTwenty = 20;
    int yFive = 7;
    int playerY = 200;
    int computerY = 200;
    int playerScore = 0;
    int computerScore = 0;
    int x2 = 0;
    int y2 = 0;

    Image offScreenImage;
    Graphics offScreenBuffer;



    MenuItem newOption, exitOption, helpOption, aboutOption;



    public EARTHQUAKEPONG ()
    {
        super ("EARTHQUAKE PONG");  // Set the frame's name
        setResizable (false);
        setSize (600, 400);     // Set the frame's size
        setLocation (360, 25);

        setBackground (Color.black);

        newOption = new MenuItem ("New");
        exitOption = new MenuItem ("Exit");
        helpOption = new MenuItem ("Help");
        aboutOption = new MenuItem ("Info");

        Menu gameMenu = new Menu ("Game");
        Menu gameMenuTwo = new Menu ("Help");

        gameMenu.add (newOption);
        gameMenu.addSeparator ();
        gameMenu.add (exitOption);

        gameMenuTwo.add (helpOption);
        gameMenuTwo.addSeparator ();
        gameMenuTwo.add (aboutOption);

        // Set up the Game Menu


        MenuBar mainMenu = new MenuBar ();
        mainMenu.add (gameMenu);
        mainMenu.add (gameMenuTwo);
        // Set the menu bar for this frame to mainMenu
        setMenuBar (mainMenu);

        show ();                // Show the frame
        // Constructor
    }


    public void newGame ()
    {
        ballX = 200;
        ballY = 330;
        playerScore = 0;
        computerScore = 0;

        repaint ();
    }


    public boolean action (Event evt, Object arg)
    {
        if (evt.target == newOption)
        {

            newGame ();
        }
        else if (evt.target == exitOption)
        {
            hide ();
            System.exit (0);
        }
        else if (evt.target == helpOption)
        {
            JOptionPane.showMessageDialog (null, "electronic tennis earthquake stylz to the max", "Help window", JOptionPane.INFORMATION_MESSAGE);
        }
        else if (evt.target == aboutOption)
        {
            JOptionPane.showMessageDialog (null, "programed by: IFY", "About", JOptionPane.INFORMATION_MESSAGE);
        }
        else
            return false;
        return true;
    }


    // handles imput from the mouse
    public boolean mouseMove (Event event, int x, int y)
    {
        if (y >= 30 || y <= 350)
        {
            playerY = y;
            repaint ();

            return true;
        }
        else
            return false;
    }


    // Handles the close button on the window
    public boolean handleEvent (Event evt)
    {
        if (evt.id == Event.WINDOW_DESTROY)
        {
            hide ();
            System.exit (0);
            return true;
        }


        // If not handled, pass the event along
        return super.handleEvent (evt);
    }


    //draws the images on the screen however were using a offscreen buffer so the images are drawn
    //off screne and then brought on screen
    public void paint (Graphics g)
    {

        if (computerY < ballY)
        {
            computerY += 20;
        }
        else
        {
            computerY -= 20;
        }








        if (offScreenBuffer == null)
        {
            offScreenImage = createImage (size ().width, size ().height);
            offScreenBuffer = offScreenImage.getGraphics ();
        }

        offScreenBuffer.clearRect (0, 0, size ().width, size ().height);

        //places a delay in the code so the ball doesnt move super fast
        try
        {
            Thread.sleep (5);
        }
        catch (Exception e)
        {
        }



        int pat = (int) (Math.random () * 3) + 1;
        int com = (int) (Math.random () * 3) + 1;


        //switches the dy to nevitive if the ball hits a wall so the ball will go the opposite way
        if (ballY < 55 || ballY > 350)
        {
            yFive = -yFive;

        }

        //this is incase the ball hits a corner and doesnt get stuck in the wall or if the ball hits the pattle





        else if (ballX <= 60 && ballX >= 50 && ballY >= playerY & ballY <= playerY + 100)
        {

            x2 = 0;
        }

        else if (ballX <= 540 && ballX >= 520 && ballY >= computerY & ballY <= computerY + 100)
        {

            x2 = 1;
        }



        if (ballY > 350)
        {
            y2 = 1;

        }
        else if (ballY < 55)
        {
            y2 = 0;
        }


        if (y2 == 0)
        {
            yFive = (int) (Math.random () * 10) + 1;

        }
        else if (y2 == 1)
        {
            yFive = (int) (Math.random () * -10) + 1;

        }

        if (x2 == 0)
        {
            xTwenty = (int) (Math.random () * 10) + 1;
        }
        else if (x2 == 1)
        {
            xTwenty = (int) (Math.random () * -10) + 1;
        }







        if (ballX <= 0)
        {
            ballX = 200;
            ballY = 330;
            computerScore++;
            JOptionPane.showMessageDialog (null, playerScore + " / " + computerScore, "Score", JOptionPane.INFORMATION_MESSAGE);
        }
        else if (ballX >= 600)
        {
            ballX = 200;
            ballY = 330;
            playerScore++;
            JOptionPane.showMessageDialog (null, playerScore + " / " + computerScore, "Score", JOptionPane.INFORMATION_MESSAGE);
        }
        // drawing the ball
        ballX = ballX + xTwenty;
        ballY = ballY + yFive;
        offScreenBuffer.setColor (Color.white);
        offScreenBuffer.fillRect (ballX, ballY, 10, 10);


        //draws the pattle which is the player&and the computer pattle
        if (pat == 1)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (53, playerY + 2, 10, 100);
        }
        else if (pat == 2)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (45, playerY + 4, 10, 100);
        }
        else if (pat == 3)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (50, playerY, 10, 100);
        }

        if (pat == 1)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (534, computerY - 5, 10, 100);
        }
        else if (pat == 2)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (527, computerY + 2, 10, 100);
        }
        else if (pat == 3)
        {
            offScreenBuffer.setColor (Color.LIGHT_GRAY);
            offScreenBuffer.fillRect (530, computerY, 10, 100);
        }
        //repaints the screen so we dont have old images on the screen
        repaint ();

        // Transfer the offScreenBuffer to the screen
        g.drawImage (offScreenImage, 0, 0, this);


        // Place the drawing code here
    } // paint method



    public void update (Graphics g)
    {
        paint (g);
    }


    public void destroy ()
    {
        offScreenBuffer.dispose ();
    }




    public static void main (String[] args)
    {
        new EARTHQUAKEPONG ();     // Create a EARTHQUAKEPONG frame
    } // main method
} // EARTHQUAKEPONG class

Sponsor
Sponsor
Sponsor
sponsor
Jekate




PostPosted: Sat Oct 16, 2004 1:20 pm   Post subject: (No subject)

As I said in my other post, I use ready to program as well. This program does not work either. I'm not sure why.
Dan




PostPosted: Sat Oct 16, 2004 1:29 pm   Post subject: (No subject)

Why are you replying to posts that are so out of date? Also the code is fine (if you consider that RTP code could be fine). I am beting you ethere do not have RTP set up right, an out of date verson or you are naming the file wrong....
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Kenster102.5




PostPosted: Wed Jan 14, 2009 7:24 pm   Post subject: Re:earth Quake Pong

The reason why it doesn't work is because he didn't put
code:
import hsa.Console;
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: