#include "DarkGDK.h"
int choice2 = 3;
int choice1 = 4;
bool mouseFullClick(int &, int &);
bool onSprite(int, int, int);
void DetermineWinner(int choice1, int choice2);
void DarkGDK()
{
dbRandomize( dbTimer() );
int mouseX, mouseY;
dbLoadImage("scissors.png",1);
dbLoadImage("rock.png",2);
dbLoadImage("paper.png",3);
dbLoadImage("pointer.png",4);
dbSyncOn ();
dbSyncRate (1000);
while ( LoopGDK () )
{
dbSprite(1, 100, 100, 1);
dbSprite(2, 200, 100, 2);
dbSprite(3, 300, 100, 3);
dbSprite(7, dbMouseX(), dbMouseY(), 4);
dbSetSpritePriority(7, 1);
dbHideMouse();
if ( mouseFullClick(mouseX, mouseY) )
{
// Determine whether the user clicked on the scissors.
if ( onSprite(1, mouseX, mouseY) )
{
dbSprite(1, 200, 200, 1);
dbHideSprite(2);
dbHideSprite(3);
choice1 = 1;
}
if ( onSprite(2, mouseX, mouseY) )
{
dbHideSprite(1);
dbSprite(2, 200, 200, 2);
dbHideSprite(3);
choice1 = 2;
}
if ( onSprite(3, mouseX, mouseY) )
{
dbHideSprite(1);
dbHideSprite(2);
dbSprite(3, 200, 200, 3);
choice1 = 3;
}
if ( choice2 == 0 )
{
dbSprite(5, 400, 400, 1);
}
if ( choice2 == 1 )
{
dbSprite(6, 400, 400, 2);
}
if ( choice2 == 2 )
{
dbSprite(7, 400, 400, 3);
}
DetermineWinner(choice1, choice2);
dbSync();
}
}
}
bool mouseFullClick(int &x, int &y)
{
// Variable to hold the return value.
bool buttonClick = false;
// If the mouse button is pressed, process
// a full clicking action.
if ( dbMouseClick() == 1 )
{
// Get the mouse pointer coordinates.
x = dbMouseX();
y = dbMouseY();
choice2 = dbRND(2);
return choice2;
// Wait for the user to release the
// mouse button.
while ( dbMouseClick() == 1)
{
// Do nothing in this loop.
}
// Set buttonClick to true.
buttonClick = true;
}
// Return true or false to indicate whether the
// mouse was clicked.
return buttonClick;
}
bool onSprite(int spriteNum, int pointX, int pointY)
{
// Variable to hold the value to return.
bool insideSprite;
// Get the X coordinate of the sprite's upper-left corner.
int upperX = dbSpriteX(spriteNum) - dbSpriteOffsetX(spriteNum);
// Get the Y coordinate of the sprite's upper-left corner.
int upperY = dbSpriteY(spriteNum) - dbSpriteOffsetY(spriteNum);
// Get the X coordinate of the sprite's lower-right corner.
int lowerX = upperX + dbSpriteWidth(spriteNum);
// Get the Y coordinate of the sprite's lower-right corner.
int lowerY = upperY + dbSpriteHeight(spriteNum);
// Determine whether (pointX, pointY) is inside the
// sprite's bounding rectangle.
if (pointX >= upperX && pointY >= upperY &&
pointX <= lowerX && pointY <= lowerY)
{
insideSprite = true;
}
else
{
insideSprite = false;
}
// Return the value of insideSprite.
return insideSprite;
}
void DetermineWinner(int choice1, int choice2)
{
int comppoints = 0;
int playerpoints = 0;
dbLoadImage("win.bmp",15);
dbLoadImage("lose.bmp",16);
dbLoadImage("tie.bmp",17);
if (choice1 == 1)
{
if (choice2 == 0)
{
dbPasteImage(17, 300, 300);
}
else if (choice2 == 1)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
else if (choice2 == 2)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
}
if (choice1 == 2)
{
if (choice2 == 0)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
else if (choice2 == 1)
{
dbPasteImage(17, 300, 300);
}
else if (choice2 == 2)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
}
if (choice1 == 3)
{
if (choice2 == 0)
{
dbPasteImage(16, 300, 300);
comppoints ++;
}
else if (choice2 == 1)
{
dbPasteImage(15, 300, 300);
playerpoints ++;
}
else if (choice2 == 2)
{
dbPasteImage(17, 300, 300);
}
}
if (playerpoints == comppoints)
{
dbPrint("It's a Tie!");
}
if (playerpoints < comppoints)
{
dbPrint("You Lose!");
}
if (playerpoints > comppoints)
{
dbPrint("You Win!");
}
}
Sorry about the lack of indentation.