Heres their program's header file
/**
* StopDice.h
* Defines constants used for StopDice program logic and graphics
*
* NOTE that string constants are NOT declared constants in order
* to conform to the requirements of WinBGIm functions that do
* not define constant string parameters when they should. This will
* be fixed when WinBGIm is itself fixed.
*
* @author . . .
* @version 1.0 May 2008
*/
/*------------- Program Constants ------------------*/
char GAME_NAME[] = "Stop the Dice";
char GAME_CLAIM[] = "- Extreme Challenge!";
char GAME_INTRO1[] = "* Stop with 2 dice showing the same value => Score 1 point";
char GAME_INTRO2[] = "* Stop with 3 dice of the same value => Bingo! add 1 and multiply by value";
char GAME_INTRO3[] = "Press the [Space bar] to start or stop";
const int DELAY = 160;/* milliseconds between dice rolls */
const int NUM_DICE = 3; /* number of dice displayed */
const int NUM_IMAGES = 6; /* number of different dice images */
/*------------- Graphics Constants -----------------*/
const int IMAGE_SIDE = 142; /* pixel length of a die side */
const int WINDOW_WIDTH = 4 * IMAGE_SIDE;
const int WINDOW_HEIGHT = 2 * IMAGE_SIDE;
const int IMAGE_TOP = IMAGE_SIDE / 3;
const int IMAGE_BOTTOM = IMAGE_TOP + IMAGE_SIDE;
const int BK_COLOR = WHITE; /* Screen background colour */
and the program's source code
/**
* StopDice.c
* Implements the "immortal" StopDice game
*
* @author . . .
* @version 1.0 - May 2008
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> /* Available in C99 for bool type */
#include <graphics.h> /* Defines the WinBGIm functions */
#include "StopDice.h" /* Defines the program constants */
/* Function Prototypes */
/**
* Initialise the game screen
* Loads dice images to memory
* @param images void *[] array for storage of dice images
*/
void initialise(void *images[]);
/**
* Loads dice images from disk to memory
* @param images void *[] array for storage of dice images
*/
void initImages(void *images[]);
/**
* Display game intro to screen
*/
void gameIntro(void);
/**
* Display a die image given its value (1 to 6) and its position
* on the screen (1, 2, or 3 = left, middle or right).
* @param value int, the value of the die between 1 and 6.
* @param position int, the position of the die between 1 and 3
* @param images void *[], image array to get the die picture from
*/
void displayDie(int value, int position, void *images[]);
/* TEMPORARY FUNCTION to get dice moving. REPLACE by proper game logic */
void changeDice(void *images[], int key);
/*--------------------------------------------------------------------------*/
int main()
{
void *images[NUM_IMAGES]; /* Array of dice images */
int key;
/* Initialise application (open window, load images...) */
initialise(images);
/* LOOP is TEMPORARY CODE: change dice until space bar is pressed */
do
{
key = 0; /* Reset key to any non-meaningful value */
if(kbhit()) /* If the keyboard has been used, get a character */
key = getch();
/* Take proper action in function of key pressed */
changeDice(images, key);
delay(DELAY);
} while(true);
return 0;
}
/* Initialise application (open window, load images draw first screen) */
void initialise(void *images[])
{
/* Open a window in background colour with double-buffering off */
initwindow(WINDOW_WIDTH, WINDOW_HEIGHT, GAME_NAME, 150, 80, false, true);
setbkcolor(BK_COLOR);
cleardevice();
/* Load images to memory */
initImages(images);
/* Display game introduction */
gameIntro();
}
/* Load images from disk to memory */
void initImages(void *images[])
{
int i, j;
unsigned int imageSize; /* The size of an image in memory (in bytes) */
int imageNo; /* Image number */
int left; /* Left coordinate of an image */
int right; /* Right coordinate of an image */
char imageFilename[8];
/* Load the dice images */
for(i = 0; i < NUM_IMAGES / NUM_DICE; i++)
{
for(j = 0; j < NUM_DICE; j++)
{
imageNo = (j + 1) + (i * NUM_DICE); /* 1 to 6 */
/* Left and right corners of image */
left = j * (IMAGE_SIDE + IMAGE_SIDE / 4) + IMAGE_SIDE / 4;
right = left + IMAGE_SIDE;
sprintf(imageFilename, "%i.gif", imageNo ); /* Build up filename */
/* Read from file and get size */
readimagefile(imageFilename, left, IMAGE_TOP, right, IMAGE_BOTTOM);
imageSize = imagesize(left, IMAGE_TOP, right, IMAGE_BOTTOM);
/* Store each image in turn into the image array */
images[imageNo - 1] = malloc(imageSize); /* allocate storage */
getimage(left, IMAGE_TOP, right, IMAGE_BOTTOM, images[imageNo - 1]);
}
}
}
/* Print flash screen information */
void gameIntro(void)
{
/* Print game name and claim */
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
setcolor(GREEN);
moveto(20, IMAGE_TOP / 3);
outtext( GAME_NAME);
outtextxy(getx() + 10, gety(), GAME_CLAIM);
/* Print game rules */
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 1);
setcolor(BLUE);
moveto(12, IMAGE_BOTTOM + 14);
outtext(GAME_INTRO1);
moveto(12, gety() + 24);
outtext(GAME_INTRO2);
setcolor(RED);
moveto(110, gety() + 28);
outtext(GAME_INTRO3);
}
/* Display a die image given its value and its position on screen */
void displayDie(int value, int position, void *images[])
{
/* Left corners of image */
int left = (position - 1) * (IMAGE_SIDE + IMAGE_SIDE / 4) + IMAGE_SIDE / 4;
putimage(left, IMAGE_TOP, images[value - 1], COPY_PUT);
}
/* ============== DISCARD BELOW THIS LINE. TEMPORARY CODE ============== */
/* Temporary function to get dice moving. Does not implement the game.
REPLACE by proper game logic */
void changeDice(void *images[], int key)
{
static bool started = false;
static int value = 1; /* static to remember next time we come in */
switch(key)
{
case ' ': /* Space bar has been hit */
if(started)
{
delay(1000); /* pause for 1 sec, then exit program */
exit(0);
}
else
started = true;
break;
default:
break;
}
/* dice go round and round in endless loop*/
if (started)
{
value = ((value + 1) % 7);
if (!value)
++value;
displayDie(value, 1, images);
displayDie((value + 4) % 6 + 1, 2, images);
displayDie((value + 5) % 6 + 1, 3, images);
}
}
now don't say i never did nothin' for no one :P