how to create a restart button on fruit puzzle game ? Anyone help me on this. I would deeply appreciate it if it was helped…
Do you mean how to actually make a “button”? A button that you can click and stuff happens? Or do you mean how do you set the puzzle game at the beginning? or both?
For the button, you could use swing (javax.swing.JButton) or make your own and not use swing.
For the second, isn’t it as simple as clearing the level of all fruit and setting the score to 0?
You’re question is a bit vague so I can’t do any better but answer vaguely :L
If you need more help, please try to be a bit more specific
ok I have decided to show the game source here since unclear question that would be able to understandable in order to figure out with RESTART METHOD ! please follow up with the source below and tell me what this need to do or write a restart method with explanation if possible
BEst regards,
looking forward for reply
D:
ganaschka, instead of making all your code italic font, do this:
- Edit your last post
- Click the # button, just underneath “Change color” in the editor
- You’ll get these tags (code) (/code) (with [ and ] instead of ( and ) )
- Copy all your code, and paste it between those two tags, like this:
(code)
ALL MY CODE
(/code)
which, when using [ and ] instead, will end up looking like this:
ALL MY CODE
This will make it a LOT easier for everyone to read.
Please don’t do that, USE PASTEBIN instead
Short code => do what Ultoman said
Long code => Pastebin
Oh, sorry! Do what _Al3x said! I’m just so used to only posting relevant code This instance, however, requires your full source to know what’s going on.
By restarting method you mean just reset all fields that affect your current state to their initial values.
Yes, rebirth thats exactly I need to do on the game
Store your initials values in a constant, so basically you have two fields for one “thing”. One the constant, one normal variable that you modify on run.
Ultroman, thanks for your advice. could you please edit my last post with sources in follow up with you steps ?
Ultroman is going to fight a monster right now. The only one except mods that can edit your post is yourself.
Rebirth, could give me an example of storing initial values and concepts? that would be awsome
thanks
Wow. This is just… wow.
For humanity’s sake, I hope you’re just trolling us.
Anyways… resetting data is very simple. It mostly varies depending on the way you store your data. For instance, if I want to have a String that holds the user’s name, but if he clicks “reset” it changed the name back to “DEFAULT” then I would do this
private final String DEFAUL_NAME = "DEFAULT";
private String name = DEFAULT_NAME;
public void resetName() {
name = DEFAULT_NAME;
}
Do you understand now?
| Nathan
Stop posting so much code!!
Dude. No one is going to write your code for you. Everyone here is giving you great advice on how to learn about how to fix this issue of yours.
LISTEN TO IT.
Read my previous post again if you need to.
| Nathan
by the way, Yes I understood Nathan great advice for issue of mine
I’ll put it simple:
- separate asset making code from constructor to normal method, said “void init()”. Anything regarded to GUI constructing should stay.
- on the same constructor, call reset() to replace the loose
- now anytime you want to restart, call the reset()
If by any chance you failed this step, without insult please consider to grab some basic tutorials.
ganaschka please don’t get us wrong, we WANT to help you, really! If you have more doubts, try to ask them as detailed as possible, you have learned how to use [.code] and [./code] (remove the dot “.” to make it work) tags for showing short code, like Nathan did. You’ve learned how to use pastebin, or at least that it existed, and that it’s the BEST tool to share LONG code. And you’ve also learned how to use the final keyword to define constants to help you make your reset.
As you can see, we want to help you, so PLEASE don’t hesitate to ask again, we are all your friends here
I need to figure out with following code below. when press a restart button, it goes set default and reinitialize game again. HELP ME…
menuBar = new JMenuBar();
menu = new JMenu("Restart");
menu.setMnemonic(1);
menuBar.add(menu);
menu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource() == menu){
allImages.clear();
for(int i=0; i<images.size(); i++){
allImages.add(images.get(i));
}
for(int i=0; i<images.size(); i++){
allImages.add(images.get(i));
}
for(int i=0; i<iconNames.length*2; i++){
ImageIcon randIcon = randomIcon();
Button b = (Button)tovchVec.get(i);
b.setZurag(randIcon);
b.setEnabled(true);
}
}
}});
ganaschka, please don’t assume that people are going to write your code for you. If you cannot do some debugging yourself, maybe you should learn more about programming before you continue with your game.