how will i repeat my whole game program?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: how will i repeat my whole game program?

 
0
  #11
Sep 18th, 2004
psylocke... you should really learn to program more modularly & object-orientated-ly. If you had, making little modifications to your program (and controlling the flow of the program) would be much easier.



But as it looks now... I think you should switch your program to the following structure:
  • a create() method in which you 'create' everything (all the new labels etc.)
  • a reset() method in which you set all values, fields, label names, guesses etc. to their initial (pre-game) values
  • a start() method (same as you already have)

Then get your YES button ActionListener to call only the init() method and then the start() method.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: how will i repeat my whole game program?

 
0
  #12
Sep 18th, 2004
oops, couldn't edit my post.

Ignore the last bit. So, basically.. you get your applet's init() method to call all three above-mentioned methods. And get your YES button ActionListener to call the reset() and start() methods only.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,057
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: how will i repeat my whole game program?

 
0
  #13
Sep 18th, 2004
Since everything here appears to be in one method, I get the impression that psylocke is brand new to Java and hasn't yet learned how to create multiple methods and classes. Am I right?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 153
Reputation: cosi is an unknown quantity at this point 
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: how will i repeat my whole game program?

 
0
  #14
Sep 18th, 2004
psylocke,

Another suggestion: Since you have so many related variables (i.e. Label peglbl1, peglbl2, peglbl3) it may make your code neater if you used arrays.

Instead of multiple Label statements, do this:
  1. Label[] pegLabel = new Label[15];
  2.  
  3. for (int i = 0; i < pegLabel.length; i++) {
  4. pegLabel[i] = new Label("");
  5. pegLabel.setBackground(Color.DARK_GRAY);
  6. add(pegLabel[i])
  7. }
  8.  
  9. // - or if you have a string table 'pegStrings' with all the initial
  10. // strings of the labels, you could do this:
  11. for (int i = 0; i < pegLabel.length; i++)
  12. pegLabel[i] = new Label(pegStrings[i]);

Then instead of what you do in your action listener
  1. if(tri==1)
  2. peglbl1.setBackground(Color.GREEN);
  3. else if(tri==2)
  4. peglbl2.setBackground(Color.GREEN);
  5. else if(tri==3)
  6. peglbl3.setBackground(Color.GREEN);

You can do this:
  1. pegLabel[tri].setBackground(Color.GREEN);

Let us know if this makes sense. I'm not sure what you have learned. Definitely give arrays a try. It should tidy up your code much.


Ed
In a world without walls or fences,
What use are Windows and Gates.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 18
Reputation: psylocke is an unknown quantity at this point 
Solved Threads: 0
psylocke psylocke is offline Offline
Newbie Poster

Re: how will i repeat my whole game program?

 
0
  #15
Sep 19th, 2004
hi cosi, thanks for the big help. i really know that there is a way to make this short using arrays but i dont know how to do that i cant find reference material for this during that time, coz i was in a rush doing this project. your recommendations are all great this exactly what i also wanted to know...THANK U so much cosi. muah
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 18
Reputation: psylocke is an unknown quantity at this point 
Solved Threads: 0
psylocke psylocke is offline Offline
Newbie Poster

Re: how will i repeat my whole game program?

 
0
  #16
Sep 20th, 2004
apcxpc,

thanks for the answers, thanks a lot...thats all i can say right now. thanks for the help really.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 18
Reputation: psylocke is an unknown quantity at this point 
Solved Threads: 0
psylocke psylocke is offline Offline
Newbie Poster

Re: how will i repeat my whole game program?

 
0
  #17
Sep 20th, 2004
Originally Posted by cscgal
Since everything here appears to be in one method, I get the impression that psylocke is brand new to Java and hasn't yet learned how to create multiple methods and classes. Am I right?
yah thats right...but i know i can be good in java in time, it will be because of this group and my eagerness to learn the language.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4821 | Replies: 16
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC