Results 1 to 13 of 13
  1. #1
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Question Game Help.working on it for days,.

    NVM,.thanks for evry1
    Last edited by xSkittlesx; 05-31-2010 at 09:19 AM. Reason: [solved,kinda]

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're much better going through the Swing tutorials and learn to write something like this from scratch. That way you'll learn much more and will understand all parts of your program. Much luck.

  3. #3
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    ok,.ill try,.. cheers

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    thank you,.. guess ill be staying hir in dis forums for a while since i jst started doing computer science as a major. can you atleast tell me what is missing/wrong with the code i posted??

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by xSkittlesx View Post
    thank you,.. guess ill be staying hir in dis forums for a while since i jst started doing computer science as a major. can you atleast tell me what is missing/wrong with the code i posted??
    Perhaps others might, but many here try to help folks with their code only and not with code they've borrowed. My experience has shown that it's just not that rewarding for me for many reasons.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    the game just doesnt initiate
    What does that mean?
    Does the program compile ok?
    How do you execute it after a successful compile? Do you have an html file that goes with it? I don't see any references to an applet class.

  8. #8
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    the code was originnaly an applet. but i need a JPanel so i tried to remodel d code. i execute it, but it's jst showing me a black screen with the score,time and level in d bottom of the panel, and d cross hair pointer. no balls moving around.

  9. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    put your code into code tags please. It is unclear...

  10. #10
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    i updated d code, but i get a nullPointerException!! hir is d code!!

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.applet.*;
    import javax.swing.*;

    public class A3JPanel extends JApplet implements MouseListener, Runnable{

    Thread th; //Thread
    GameTimer mytimer; //Timer object
    private Ball ball; //ball object
    private Color ballcolor; //Ball color object
    Cursor c; //cursor object
    Random rnd = new Random (); //Random generator object
    private Color [] color_array; //Array of colors for balls
    private Ball [] ball_array; //Array to store balls in
    int level=1; //Game level being played
    int maxballs; //Max number of balls
    int maxspeed; //must be at least 2..
    private int x,y =0; //x & y position of ball
    public int ball_width=20; // inital ball width
    public int ball_height = 20; // inital ball height
    public int panelsize_x = 500;// x size of applet drawing area for balls
    public int panelsize_y = 400;// y size of applet drawing area for balls
    int x_speed,y_speed =0; //x & y speed of the balls
    private int count = 0; // used for counting loops
    private int test =0; // used in test for no more balls
    int numcolors = 6; //used to initilize the colors array
    public int timeleft; //Time till end of game
    int colorIndex=0; //used in filling color array
    private int score,hits,miss =0;

    public boolean movetonextlevel= false;
    private boolean gotHit =false;
    public boolean end_of_game = false;
    private boolean alive = true;


    Font small = new Font("TimesRoman", Font.PLAIN, 12);
    Font large = new Font("TimesRoman", Font.PLAIN, 25);
    Font realsmall = new Font("TimesRoman", Font.PLAIN, 10);

    //INITILIZE APPLET
    //**************************
    public void init(){
    level = 1;
    score = 0;

    //Init Game
    //***********
    end_of_game = false;
    setGameLevel(level);
    int timeleft=60; //Set length of game
    //Start game timer
    mytimer = new GameTimer(timeleft);
    c = new Cursor (Cursor.CROSSHAIR_CURSOR); //Change cursor to cross hair
    this.setCursor (c);
    setBackground (Color.black); //Set background color
    color_array = new Color[] { //Initlize ball color array
    Color.blue, Color.yellow, Color.orange,
    Color.white, Color.green,Color.red
    };

    ball_array = new Ball[maxballs]; //Init ball_array to maxballs

    //Initilize Balls Array
    //**********************************
    for (count = 0; count < maxballs; count++){
    if(count < maxballs){
    // Make Ball
    //*********
    x=(int)(Math.random()*panelsize_x);
    if(x < 20){x = 25;}
    y=(int)(Math.random()*panelsize_y);
    if(y < 20){y = 25;}
    x_speed =(int)(Math.random()*maxspeed);
    if(x_speed < 1){x_speed=1;}
    y_speed = (int)(Math.random()*maxspeed);
    if(y_speed < 1){y_speed=1;}
    // rnd get color form color array
    colorIndex=(int)(Math.random()*numcolors);
    if(colorIndex < 0){colorIndex=0;}
    ballcolor= color_array[colorIndex];
    ball = new Ball(x,y,ball_width,ball_height,ballcolor,x_speed, y_speed,
    maxspeed,alive,panelsize_x,panelsize_y);
    ball_array[count] = ball;
    }
    }
    }//end init



    public void start (){
    Thread th = new Thread (this); //Create thread for game
    th.start ();
    }

    public void stop(){

    }

    public void destroy(){
    removeMouseListener(this);
    }

    public void run (){
    addMouseListener(this);

    while (end_of_game == false)
    {
    // Check time remaining
    timeleft = mytimer.getTime();
    if(timeleft == 0){end_of_game = true;}

    // Test for end of game
    //test for all balls shot
    //******************************************
    test=0;
    for(count =0; count < maxballs ; count++){
    if(ball_array[count].alive == false){
    test++;
    // test for all balls hit
    if(test == maxballs){
    if(level<5){
    level++;
    movetonextlevel= true;
    repaint();
    delay(6000);
    movetonextlevel = false; // reset level flag
    setGameLevel(level);
    init();
    }else end_of_game = true;
    }
    }
    }

    // Move balls
    for (count = 0; count < maxballs ; count++){
    if(ball_array[count].alive == true){
    ball_array[count].move();
    }
    }
    repaint();
    delay(20);
    }
    //End of game
    //***********************
    delay(2000);
    repaint();
    destroy();

    }//end run

    public void delay(int time){
    try
    {
    // Stop Threads time ms
    th.sleep (time);
    }
    catch (InterruptedException ex)
    {
    // do nothing
    }

    }

    // Mouse implementintation
    //*************************
    public void mousePressed(MouseEvent e) {

    double x = e.getX();
    double y = e.getY();

    for(count=0; count< maxballs ; count++){
    if(ball_array[count].userHit(x,y)){
    ball_array[count].killBall();
    gotHit = true;

    //CHECK BALLS COLOR
    //red=100, white=50 yellow=10, orange =5 cyan=1000 green = 200
    //************************************************** **********
    if(ball_array[count].color == Color.red){
    score +=5;
    }else if(ball_array[count].color == Color.white){
    score +=10;
    }else if(ball_array[count].color == Color.yellow){
    score +=50;
    } else if(ball_array[count].color == Color.orange){
    score +=100;
    } else if(ball_array[count].color == Color.blue){
    score +=200;
    } else if(ball_array[count].color == Color.green){
    score +=1000;
    }
    } else {gotHit=false;}
    }//end for

    // loose 10 point for miss
    //*******************************
    if(gotHit == false){score+= -10;}
    if(score < 0){score=0;}

    }//end mouse pressed
    public void mouseClicked(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {
    repaint();
    }
    public void mouseExited(MouseEvent e) {
    repaint();
    }

    //Set Level of play
    //*****************************
    public void setGameLevel(int level){
    if(level == 1){
    maxballs = 10;
    maxspeed = 3;
    ball_height=40;
    ball_width=40;
    }
    if(level == 2){
    maxballs = 20;
    maxspeed = 4;
    ball_height=30;
    ball_width=30;
    }
    if(level == 3){
    maxballs = 30;
    maxspeed = 5;
    ball_height=20;
    ball_width=20;
    }
    if(level == 4){
    maxballs = 40;
    maxspeed = 5;
    ball_height=15;
    ball_width=15;
    }
    if(level == 5){
    maxballs = 50;
    maxspeed = 5;
    ball_height=10;
    ball_width=10;
    }
    }

    //PAINT SCREEN
    //*******************************
    public void paint (Graphics g){
    if( movetonextlevel == true){
    g.setColor(Color.black);
    g.fillRect(0,0,panelsize_x,panelsize_y);
    g.setColor(Color.yellow);
    g.setFont(large);
    g.drawString("Moving to Level: "+level,60,150);
    }
    String s = Integer.toString(score);
    String l = Integer.toString(level);
    String t = Integer.toString(timeleft);
    g.setColor(Color.white);
    g.setFont(small);
    g.drawString("SCORE= "+s,10,280);
    g.drawString("SKILL LEVEL= "+l,200,280);
    g.drawString("Time:"+t,120,280);
    for (count = 0; count < maxballs ; count++){
    if(ball_array[count].alive == true){
    ball_array[count].drawBall(g);
    }
    }
    if(end_of_game == true){
    g.setColor(Color.blue);
    g.fillRect(60,117,190,50);
    g.setFont(large);
    g.setColor(Color.yellow);
    g.drawString("END OF GAME",70,150);
    }

    }//end paint

    }//end class

  11. #11
    xSkittlesx is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    sorry,im new to this forums so i dont know how to do this code tags!

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    i dont know how to do this code tags
    Look at the icons above the Message box. Run your cursor over them. One will say "Wrap code tags around ...". Its the #
    Edit your post, select the code and press that icon.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Or you can manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Luck!

Similar Threads

  1. Replies: 8
    Last Post: 01-06-2011, 06:33 PM
  2. Been working on a code for days
    By Link01 in forum Java Applets
    Replies: 5
    Last Post: 05-19-2010, 03:55 PM
  3. Replies: 7
    Last Post: 07-21-2009, 02:39 AM
  4. Gueesing Game Almost done, but not working correctly
    By mbnumba6 in forum New To Java
    Replies: 5
    Last Post: 03-18-2009, 03:01 AM
  5. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:06 AM

Tags for this Thread

Posting Permissions

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