To dumb creating Memory

i have a memory game applet. all works fine except of one thing.

imagine you have uncoverd two cards. now my game checks, wheter they are the same (and keep uncoverd) or not. if the two cards dismatch, i want that they keep uncovered for a few seconds so that the user can keep them in mind.

for that situation i need a counter (my counter counts frames)
if the counter is different to zero, the cards are locked and the uncovered ones keep open for this time.

now i have a problem. my only method, which is permanently calles, is an update() method, from my gamemanager class. it coordinates the painting-processes of all cards and is called by paint-method of the applet-class.
therfore im forced to check or decrease the counter in this method.

so i have the following code snippet (pseudo code):

if(wait_frames == 0)
{
       tile1.hide();
       tile2.hide();
       tiles_locked = false;
}

paintAllTiles() ...

im not satisfied with this solution. not only, that in the “paint()” method i need to check every time, there are some traps in calling tileX.hide() every time again and again (btw.: tile1 and tile2 keep references to the uncovered cards);

is there any elegant way to solve my problem ?

let wait_frames run down to -1, then you won’t have to keep calling hide() on your cards.

Kev

hmm, i didnt got the clue. where is the advantage to check for -1 ? where is the difference to zero ?

Ycheck for 0 but you let the count role down to -1. Then your check for 0 will only get hit once and hence your hide() calls only once.

Possibly easier still would be to have a flag inside the tile saying whether its hidden or not. Then at the start of your hide method just return if its already hidden.

Kev

ok, now i got it.

but my tiles have a flag for being hidden or nor. but the difference is to know, wheter they are not hidden and shall stay so (two matching cards stay uncovered) or if they are not hidden bur shall cover in a few frames

Since I’m all about pushing patterns, use a Mediator. A reference can be found at:

http://www.site.uottawa.ca/~nkana059/mediator/index_files/frame.htm

Unless of course you sleep with the GoF book under your pillow like me.

BTW: what I just told you did nothing to actually help you with your problem. I simply put a name to it.

ok, patterns are always a good idea. i have to read it fully, but btw. the page is catastrophical. it looks, as if someone converted a power point presentation to bad html …