Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Don't understand how to get this working.

Author
Message
PyPaw
13
Years of Service
User Offline
Joined: 13th Mar 2011
Location:
Posted: 4th Apr 2011 05:18
Hello all.

I'm currently attempting to do a project called "ESP Game" out of the book called "Games & Graphics in C++" on page 556.

It asks:

"Three cards are shown face down. Internally, the program should randomly select values for each card (one triangle, one square, and one circle). The user should be instructed to use the mouse to select which card is a triangle. The selected card should then be revealed.

Repeat this 10 times and then display the number of times the user correctly identifies the triangle card."

My problem is that I am not sure how to display the switch when clicked. When I tryed I ended up with the blank cards and shape cards showing on top of each other. I don't understand how to make a mouse click change the card into a random shape like it asks. Can anyone help me out? My code was trashed because it just didn't work.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 5th Apr 2011 21:48
Quote: "I ended up with the blank cards and shape cards showing on top of each other"


Maybe because you didn't clear the screen before redrawing the cards? The problem could have been as simple as that.

Quote: "My code was trashed because it just didn't work."


I understand you were annoyed but you shouldn't have thrown out the code, because now we will never know why it didn't work.

There are several ways to structure a program, even a simple one like this, and I don't know how you tried to structure yours, so I can give only very general advice. One thing is sure: you need to distinguish the status before and after the card is revealed. One way to do that is to introduce a boolean variable "revealed = true/false", and do the drawing based on its current value. This is a good solution if you use a game loop that continuously updates the screen.

Another way is to make sure that the game phases always strictly follow each other, i.e. you first draw the cards face down, wait for user selection, then clear the screen and draw the cards face up. I don't have that book, but in other examples posted on the forum, I saw that it often prefers a linear program execution instead of a loop, so that's also a possibility.

Try to recreate the code you had. If you post it here, you can receive more specific advice.

Login to post a reply

Server time is: 2024-06-16 02:48:24
Your offset time is: 2024-06-16 02:48:24