Results 1 to 3 of 3
  1. #1
    Sean_J is offline Member
    Join Date
    Feb 2010
    Posts
    16
    Rep Power
    0

    Default Game assistance.

    I cant figure out how to solve the error in this code. The errors are different font colors.

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.applet.*;
    import java.net.*;
    
    
        public class boing extends Applet implements Runnable,MouseMotionListener {
        public static Color bgColor=Color.black,ballColor=Color.blue;
        public static Color paddleColor=Color.red,brickColor=Color.yellow;
        public static Color fgColor=Color.white;
        public AudioClip sound,booing,pop,win;
        public static AudioClip spring,endgame,loose,bgClip;
        public Thread t;
    
    
            public void init () {
    
    
                try {
                URL u = getCodeBase();
                booing = getAudioClip(new URL(u,"spring.au"));
                pop = getAudioClip(new URL(u,"pop.au"));
                spring = getAudioClip(new URL(u,"boing.au"));
                endgame = getAudioClip(new URL(u,"Fart.au"));
                win = getAudioClip(new URL(u,"win.au"));
                loose = getAudioClip(new URL(u,"Lose.au"));
                bgClip = getAudioClip(new URL(u,"Stamp.au"));
                /*
                booing = getAudioClip(new URL("file:///d:/boing/spring.au"));
                pop = getAudioClip(new URL("file:///d:/boing/pop.au"));
                spring = getAudioClip(new URL("file:///d:/boing/boing.au"));
                endgame = getAudioClip(new URL("file:///d:/boing/Fart.au"));
                win = getAudioClip(new URL("file:///d:/boing/win.au"));
                loose = getAudioClip(new URL("file:///d:/boing/Lose.au"));
                bgClip = getAudioClip(new URL("file:///d:/boing/Stamp.au"));
                booing = getAudioClip(new URL("http://www.geocities.com/ali_ezad/spring.au"));
                pop = getAudioClip(new URL("http://www.geocities.com/ali_ezad/pop.au"));
                spring = getAudioClip(new URL("http://www.geocities.com/ali_ezad/boing.au"));
                endgame = getAudioClip(new URL("http://www.geocities.com/ali_ezad/Fart.au"));
                */
            } catch (Exception e) {}
    
            sound = null;
            bgClip.loop();
        }
    
    
    
            public void start () {
    
    
                if (t == null) {
                t = new Thread(this);
                t.start();
    
    
                } else {
    
               [B][COLOR="Red"] t.resume();[/COLOR][/B]
            }
    
        }
    
    
    
            public void stop () {
    
    
                if (t != null) {
                [B][COLOR="Red"]t.suspend();[/COLOR][/B]
            }
    
        }
    
    
    
            public void destroy () {
    
    
                if (t != null) {
                [B][COLOR="Red"]t.stop();[/COLOR][/B]
                t = null;
            }
    
        }
    
        public Vector targets;
        public Ball myBall;
        public Paddle myPaddle;
        public int counter;
        public int declutter,paddleStateMonitor;
        public Label info;
        public boolean paddleHit;
    
    
            public boing () {
            setBackground(bgColor);
            setForeground(fgColor);
            setLayout(null);
            declutter = 0;
            paddleStateMonitor = 0;
            paddleHit = false;
            info = new Label("BOING by Ali Ezad Abbas");
            targets = new Vector();
    
    
                for (int i=0;i<15;i++) {
    
    
                    for (int j=0;j<10;j++) {
                    [B][COLOR="Red"]targets.addElement(new Brick(i*20,30+(j*6),19,5,brickColor));[/COLOR][/B]
                }
    
            }
    
            counter = targets.size();
            int x = Math.abs(new Random().nextInt()%250);
            myPaddle = new Paddle (x);
           [B][COLOR="Red"] targets.addElement(myPaddle);[/COLOR][/B]
            //myBall = new Ball(150,424);
            myBall = new Ball(x,274);
            addMouseMotionListener(this);
            add(info);
            info.setBounds(70,5,140,20);
        }
    
    
    
            public void update (Graphics g) {
    
    
                if (declutter >= 100) {
                g.setColor(bgColor);
                //g.fillRect(0,0,300,450);
                g.fillRect(0,0,300,300);
                declutter = 0;
            }
    
            paint(g);
        }
    
    
    
            public void paint (Graphics g) {
    
    
                for (int i=0;i<targets.size();i++) {
                ((Target)(targets.elementAt(i))).draw(g);
            }
    
            myBall.draw(g);
        }
    
    
    
            public void run () {
            myBall.startMoving();
    
    
                while (myBall.isNotOut()&&counter!=0) {
                myBall.move();
                updateGameStatus();
                declutter++;
                repaint();
    
    
                    try {
                    Thread.sleep(5);
                } catch (Exception e) {}
    
            }
    
    
    
                if (counter == 0) {
                bgClip.stop();
                win.play();
            }
    
        }
    
    
    
            public void updateGameStatus () {
    
    
                if (paddleStateMonitor > 50 && paddleHit) {
                paddleHit = false;
    
    
                    for (int i=0;i<targets.size();i++) {
                    Target t = (Target)(targets.elementAt(i));
    
    
                        if (t.isThePaddle()) {
                        t.notifyIt();
                    }
    
                }
    
            }
    
    
    
                for (int i=0;i<targets.size();i++) {
                Target t = (Target)(targets.elementAt(i));
                Rectangle targetArea = t.getArea();
                Rectangle ballArea = myBall.r;
    
    
                    if (ballArea.intersects(targetArea)&&t.getActive()) {
                    myBall.rebound();
                    t.hasBeenHit();
                    sound = booing;
    
    
                        if (t.isABrick()) {
                        counter--;
                        sound = pop;
                    }
    
    
    
                        if (t.isThePaddle()) {
                        t.notifyIt();
                        paddleStateMonitor = 0;
                        paddleHit = true;
                        repaint();
                        //t.notifyIt();
                    }
    
                    sound.play();
                }
    
            }
    
            paddleStateMonitor++;
        }
    
    
    
            public void mouseMoved (MouseEvent e) {
            myPaddle.setX(e.getX()-25);
            repaint();
        }
    
        public void mouseDragged (MouseEvent e) {}
        public void mousePressed (MouseEvent e) {}
    }
    
    
    
        interface Target {
        abstract void hasBeenHit ();
        abstract void draw (Graphics g);
        abstract Rectangle getArea ();
        abstract boolean getActive ();
        abstract boolean isABrick ();
        abstract boolean isThePaddle ();
        abstract void notifyIt ();
    }
    
    
    
        class Brick implements Target {
        public static Color bgc = boing.bgColor;
        public Rectangle r;
        public Color color;
        public boolean active;
    
    
            public Brick (int a,int b, int c, int d, Color e) {
            r = new Rectangle(a,b,c,d);
            color = e;
            active = true;
        }
    
    
    
            public boolean isABrick () {
            return true;
        }
    
    
    
            public boolean isThePaddle () {
            return false;
        }
    
    
    
            public Rectangle getArea () {
            return r;
        }
    
    
    
            public void delete () {
            color = bgc;
        }
    
    
    
            public void draw (Graphics g) {
            g.setColor(color);
            g.fillRect(r.x,r.y,r.width,r.height);
        }
    
    
    
            public void hasBeenHit () {
            delete();
            active = false;
        }
    
    
    
            public boolean getActive () {
            return active;
        }
    
        public void notifyIt () {}
    }
    
    
    
        class Paddle implements Target {
        public Rectangle r;
        public int previousX;
        public boolean notified;
    
    
            public Paddle (int a) {
            //r = new Rectangle(a,439,50,10);
            r = new Rectangle(a,289,50,10);
            previousX = 0;
            notified = false;
        }
    
    
    
            public boolean isABrick () {
            return false;
        }
    
    
    
            public boolean isThePaddle () {
            return true;
        }
    
    
    
            public Rectangle getArea () {
            return r;
        }
    
    
    
            public void setX (int a) {
            previousX = r.x;
            r.x = a;
        }
    
    
    
            public void draw (Graphics g) {
            g.setColor(boing.bgColor);
            g.fillRect(previousX,r.y,r.width,r.height);
            g.drawLine(previousX+(r.width/3),r.y-r.height,previousX+2*(r.width/3),r.y-r.height);
            g.drawLine(previousX+(r.width/3),r.y,previousX+2*(r.width/3),r.y-r.height);
            g.drawLine(previousX+(r.width/3),r.y-r.height,previousX+2*(r.width/3),r.y);
            g.setColor(boing.paddleColor);
            g.fillRect(r.x,r.y,r.width,r.height);
    
    
                if (notified) {
                g.setColor(Color.green);
                g.drawLine(r.x+(r.width/3),r.y-r.height,r.x+2*(r.width/3),r.y-r.height);
                g.drawLine(r.x+(r.width/3),r.y,r.x+2*(r.width/3),r.y-r.height);
                g.drawLine(r.x+(r.width/3),r.y-r.height,r.x+2*(r.width/3),r.y);
            }
    
        }
    
        public void hasBeenHit () {}
    
    
            public boolean getActive () {
            return true;
        }
    
    
    
            public void notifyIt () {
            notified = !notified;
        }
    
    }
    
    
    
        class Ball {
        public static Color bgc = boing.bgColor, bc = boing.ballColor;
        public Rectangle r;
        public int previousX, previousY, dx, dy;
        public Color color;
        public boolean ballIsOut;
    
    
            public Ball (int a, int b) {
            r = new Rectangle (a,b,15,15);
            color = bc;
            previousX = a;
            previousY = b;
            dx = dy = 0;
            ballIsOut = false;
        }
    
    
    
            public void startMoving () {
            dx = dy = 1;
        }
    
    
    
            public void move () {
            previousX = r.x;
            previousY = r.y;
            r.x += dx;
            r.y += dy;
            checkBounds();
        }
    
    
    
            public void checkBounds () {
    
    
                if (r.x<0||r.x+15>300) {
                dx = -1 * dx;
                boing.spring.play();
            }
    
    
    
                if (r.y<10) {
                dy = -1 * dy;
                boing.spring.play();
            }
    
            //if (r.y+15>450) { -150 from everyth
            //     ing
    
    
                if (r.y+15>300) {
                ballIsOut = true;
                boing.bgClip.stop();
                boing.endgame.play();
                boing.loose.play();
            }
    
        }
    
    
    
            public boolean isNotOut () {
            return !ballIsOut;
        }
    
    
    
            public void rebound () {
            dy = -1 * dy;
        }
    
    
    
            public void draw (Graphics g) {
            g.setColor(bgc);
            g.fillOval(previousX,previousY,r.width,r.height);
            g.setColor(bc);
            g.fillOval(r.x,r.y,r.width,r.height);
        }
    
    }
    5 warnings found:
    File: F:\boing.java [line: 61]
    Warning: F:\boing.java:61: warning: [deprecation] resume() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 72]
    Warning: F:\boing.java:72: warning: [deprecation] suspend() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 83]
    Warning: F:\boing.java:83: warning: [deprecation] stop() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 113]
    Warning: F:\boing.java:113: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
    File: F:\boing.java [line: 121]
    Warning: F:\boing.java:121: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Sean_J View Post
    5 warnings found:
    File: F:\boing.java [line: 61]
    Warning: F:\boing.java:61: warning: [deprecation] resume() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 72]
    Warning: F:\boing.java:72: warning: [deprecation] suspend() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 83]
    Warning: F:\boing.java:83: warning: [deprecation] stop() in java.lang.Thread has been deprecated
    File: F:\boing.java [line: 113]
    Warning: F:\boing.java:113: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
    File: F:\boing.java [line: 121]
    Warning: F:\boing.java:121: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
    As you could've read in the API documentation for the Thread class those methods are indeed deprecated because (as the documentation reads) they are inherently unsafe; don't use them. The last two warnings mention the fact that you could (and should) have used generic containers here.

    kind regards,

    Jos

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    here Java Platform SE 6 you can find how to avoid the first four warning using other code.

Similar Threads

  1. Error assistance
    By bobbychiken in forum New To Java
    Replies: 2
    Last Post: 11-21-2009, 10:54 PM
  2. Looking for assistance
    By s_dawg101 in forum New To Java
    Replies: 32
    Last Post: 11-04-2009, 02:49 AM
  3. New to the forum + assistance :)
    By quemadissimo in forum New To Java
    Replies: 4
    Last Post: 10-31-2009, 06:41 AM
  4. In need of some assistance
    By Boer84 in forum New To Java
    Replies: 2
    Last Post: 07-08-2008, 04:14 PM
  5. X-Tremely new to this...Need assistance...
    By Johnny562 in forum New To Java
    Replies: 5
    Last Post: 07-01-2008, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •