/* russian roulette game -- test your luck */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sleep(int nbr_sec)
{
clock_t goal;
goal = (nbr_sec * CLOCKS_PER_SEC) + clock();
while(goal > clock())
{
; /* loop */
}
}
int click(void)
{
int x, play = 0;
int wait = 5;
char ch;
while (1)
{
for(x = 1; x <= wait; x++)
{
printf("\nPulling");
fflush(stdout);
sleep( (int) 1 );
}
srand((unsigned)time(NULL));
x = rand()%6;
if(x == 1)
{
puts("\n\nBANG!!! -- You're dead.");
printf("\nYou got %d tries before you killed »
yourself. ", play);
if (play >= 10)
{
puts("\nPlay the lottery! You're golden!!");
}
else if (play >= 5)
{
puts("\nNot too bad. You're about average »
in the luck department. Keep trying.");
}
else
{
puts("\nWhoa!! Not much luck at all.");
}
play = 0;
}
else
puts("\n\nCLICK -- You're still alive.");
puts("Feeling lucky? (y or n)?");
do
{
ch = getch();
++play;
}
while(ch != 'n' && ch != 'y');
if(ch == 'n')
break;
}
}
int main()
{
char ch;
puts("********** Russian Roulette **********");
puts("\nEnter p to Play, l to Leave: ");
ch = getch();
if(ch == 'p')
{
click();
}
else
puts("\nSo long, scaredy cat!!");
system("PAUSE");
return 0;
}
:: Top ::