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 / Assignment

Author
Message
Eric M
14
Years of Service
User Offline
Joined: 16th Nov 2010
Location:
Posted: 16th Nov 2010 22:11
Hello all,

I'm new hear and i am currently in a class that is an introduction to c++ using dark GDK. My current assignment requires me to create a game where the user tries to guess the center-point of a square and draw a circle in it. its called round peg in a square hole. at the moment i dont have acomputer to actually put the code in to debug it so for the time being im writing down semi-pseudo code and hopefully i can borrow my room mates computer. I'm typing this on an iMac and I cant currently put a windows partition on it so getting the appropriate programs is out of my reach right now, while my laptop is getting repaired. Basically the user tries to guess the center point. If the get it right, they are congratulated and the program ends. If not the screen clears and a new random square is drawn again. I'm not sure if I'm supposed to put a fail message if they guess wrong, but this is what i manage to come up with.

x= dbRandom(479)
y= dbRandom(639)

dbDot (x,y) // random center point for the square

dbLine(x-25,y-25,x+25,y-25) // 50 by 50 square around random center point
dbLine(x+25,y-25,x+25,y+25)
dbLine(x+25,y+25,x-25,y+25)
dbLine(x-25, y+25,x-25,y-25)

A= user input then covert to integer
B= user input then convert to integer

dbCircle(A,B,25)

If A=x and B=y
Then congratulate user and exit program
else tell user they are wrong and clear the program and start again.

I'm pretty sure there is a loop involved. I'm thinking a post test loop with that last if condition as the check. Is this just about write? If I cant borrow a room mates computer then i can at least write down the code and submit it and get some credit on it.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Nov 2010 10:16
It's kind of difficult to write a program without a computer, but it's a good try. A few remarks:

- All command lines should be closed with semicolon.
- The variables should have a type. x, y, A, B should be defined as type int.
- The equality test is DOUBLE equal sign: if (A == x && B == y) ... (&& is "and"). If you use single equal, then A will be made equal to x and B will be made equal to y and the equation will always be true.
- Instead of the four dbLine commands you could use one dbBox, it's shorter: dbBox(left, top, right, bottom)
- The command for random coordinates is dbRND, not dbRandom. Also if you want to make it really random, you should use dbRandomize(dbTimer()) once at the beginning of the program to seed the random number generator.
- For user input, the simplest is probably dbInput("enter a number", A) and the same for B.


- Since you didn't write this with a computer, the program structure is missing. The Dark GDK game template will create a framework for you when you make a new project. It already contains a game loop:


When the user guesses right, you can use a "break" command to get out of the loop and finish the program.

Login to post a reply

Server time is: 2024-11-19 16:45:36
Your offset time is: 2024-11-19 16:45:36