File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes running a class a particular number of times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "running a class a particular number of times" Watch "running a class a particular number of times" New topic
Author

running a class a particular number of times

antony fran
Greenhorn

Joined: Jun 08, 2007
Posts: 2
hey
can some please tell me how to run this class a specific number of times. maybe by using a for loop?.
i am making a game called memory game where you match the cards which are the same. i want to make this a multiplayer game rather than a single player game. Thus in order to do this i need to be able to run the class (shown below) a specific number of times.

i have an array called "players" which is a length of 5. and if the user enter the names into all five elements or there are 5 players then i need the program to run 5 times. else if the user only entered a name in two elements then i need the class "MemoryMatch" to run twice .

i know how to determine whether the user entered 5 names or a single by using if statements. but i dont know how to make the class "MemoryGame" run a specific number of times.

.. .and for the game i calculate the score of the user by finding the amount of time it takes the user to finish the game and then subtract the time they took from a base value of 500 points. i then put the time difference into an array called "timez" i also want the class to add the time to array "timez" at the end after the one of the players has finished the game or the class is run.

below i have the whole code for my program



thanks alot!
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

Here are some suggestions (but probably not the whole answer)..

1. Either extend JFrame or have one in your object, but not both.
2. You will need a doubly-nested loop. The outer loop to loop through the players and the inner loop until a single game is completed. I'm assuming that each player completes an entire game and then it is the next player's turn.
3. To create a new game, create a new instance of your game object: new MemoryMatch();
4. You may have to remove some of the static qualifiers to your variables and make them instance variable instead of class variables. static variables would remember things from the last game and you want a fresh start for most things. Only declare variables in your class as static if they are to be remembered for all games.

I was not able to get the getResource() method to work. Is this working for you? If so, were do I need to put my .gif files so that they are found?

Kaydell
antony fran
Greenhorn

Joined: Jun 08, 2007
Posts: 2
hey
in order to get the pictures you need to have the program i put and the pictures in a folder. also the names of the images should be the same. if you want you could run the program with just 6 buttons or three pairs. that might be easier but if you do this also change the first line of the program to



and the code in the myButton class right at the end where we tell the person if they won



this way you will be able to run the program with a few cards insted of 32. could you also please help me finish this by tuesday?
thanks
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688



I think that now I understand your code better. It seems to basically work for me with the three changes above.

Kaydell
 
jQuery in Action, 2nd edition
 
subject: running a class a particular number of times
 
Similar Threads
Display an image for a set time
I can't load a file with getResource
mmm.. music
help me create Go! game please
help~!!!