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.
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?
posted 12 years ago
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