We just started learning windows programming in C++. We have to make a program that has 4 die on the screen, and when the user presses ‘SpaceBar’, the die roll, or the number of dots on the die change randomly. Our professor hasent given us a lot of information, so I am kind of just looking for some direction.
Right now, I have 4 squares drawn on the screen, made with the Rectangle() function.
Rectangle(hDC,30,100,130,200);
Rectangle(hDC,180,100,280,200);
Rectangle(hDC,330,100,430,200);
Rectangle(hDC,480,100,580,200);
My question is 1) how would I go about drawing dots on these ‘squares’ and not on the ‘screen’. So if I move the die upwards, the dots move with the square and dont just stay stationed painted on the screen. And 2.) How would I go about making those dots randomly change when spacebar is pressed (simulating that they have been rolled)?
Just looking for some direction, thanks.
1)
You will still have to draw them on the screen, but you can structure your program to realize the dots as part of the square.
2)
You can capture keypresses in your window with the
WM_KEYDOWNandWM_KEYUPmessages, or theWM_CHARmessage. Just start a chain of changing how many dots are supposed to appear on the die when space is pressed (SetTimercould be handy), and letWM_PAINTdo the work of painting the dots (or call something to calculate the positions of the dots, and letWM_PAINTloop through each dot it needs to draw.For drawing dots, use Warren P’s reference link.