1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// include the Dark GDK header file (http://forum.thegamecreators.com/?m=forum_read&i=22)
#include "DarkGDK.h"
//Constants for screen size
const int SCREEN_W = 640;
const int SCREEN_H = 480;
//Variables for Width and Height
const int WIDTH = 50;
const int HEIGHT = 50;
//Function prototype
void setup();
void drawSquare(int, int);
void drawCircle(int, int);
void playGame();
void endGame();
//Main entry point for the application
void DarkGDK ( void )
{
setup();
playGame();
endGame();
}
void setup()
{
//Sets the window and title seed.
dbSetWindowTitle("Round Peg in a Square Hole");
//Seed the random number generator
int seed = dbTimer();
dbRandomize( dbTimer() );
void drawSquare(int centerX, int centerY);
{
//Square Variables
int x1 = centerX - WIDTH/ 2;
int y1 = centerY - HEIGHT/ 2;
int x2 = centerX + WIDTH/ 2;
int y2 = centerY + HEIGHT/ 2;
//Drawing the square
dbLine(x1, y1, x2, y1); // Top
dbLine(x2, y1, x2, y2); // Right
dbLine(x2, y2, x1, y2); // Bottom
dbLine(x1, y2, x1, y1); // Left
}
void drawCircle(int centerX, int CenterY);
{
const int RADIUS = WIDTH / 2;
//Draw circle
dbCircle(centerX, centerY, RADIUS);
}
/* The playGame function prompts the user to guess the XY coordinates of the square
then draws a circle around the guessed coordinates.This repeats until the user gets
it right */
void playGame();
{
//Variables for the center points of the circle and square
int randomX = 0;
int randomY = 0;
int circleX = 0;
int circleY = 0;
//Repeat the process until user guesses correctly
do
{
//Clear the screen
dbCLS();
//Generate a random center point.
randomX = WIDTH / 2 + dbRND(SCREEN_W - WIDTH);
randomY = HEIGHT / 2 + dbRND(SCREEN_H - HEIGHT);
//Draw square at random location
drawSquare(randomX, randomY);
//Prompt user the guess square's center point.
dbPrint("Guess the X and Y values of the square's center point.");
//Get the user's input for the X value.
dbPrint("Enter your guess for the X value.");
circleX = atoi(dbInput());
//Get the user's input for the Y value.
dbPrint("Enter your guess for the Y value.");
circleY = atoi(dbInput());
//Wait for user to press a key.
dbWaitKey();
}while (circleX != randomX && circleY != randomY);
}
// The endGame function clears the screen and displays a message if the user gets the answer correct.
void endGame();
{
//Clear the screen.
dbCLS();
// Increase the size of the text to 24 point.
dbSetTextSize(24);
// Display a congratulations message
dbCenterText(SCREEN_W / 2, SCREEN_H / 2,
"CONGRATULATIONS!");
// Wait for one second, then exit.
dbWait(1000);
}
|