• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

running a class a particular number of times

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

Kaydell
 
reply
    Bookmark Topic Watch Topic
  • New Topic