Pages

Saturday, March 14, 2009

Game Designing

This is my first game designed and developed through C. Rapid progress! Ha ha... Check out guys!
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "time.h"
#define limit 10
int main()
{
int k,num,guess,i=0,c=0;
double y;
char ch,a;
printf("THIS IS A SIMPLE GUESS GAME DEVEOPED BY CHAMMA\n\n");
printf("In this game, you get 3 chances to guess a number predefined by the computer\n");
printf("You have to enter a number between 0 and 9, inclusive\n");
printf("If you were able to guess it correctly, inside those 3 chances, YOU WIN!\n\n");
for(;;)
{
srand(time(NULL));
num=rand()%limit;
i++;
printf("GAME # %d:\n\n",i);
for(k=3;k>0;k--)
{
printf("You have %d guess%s left\n",k,k==1 ? "":"es");
printf("Enter your guess:");
scanf("%d",&guess);
getchar();
if(guess==num)
{
c++;
printf("BRAVO, YOU WIN!!!\n");
goto P;
}
else if(guess!=num && (k==3 || k==2))
printf("\nWrong guess. Try again\n");
else
{
printf("Damn, you lose the game %d\n",i);
printf("Number that chosen was %d!\n",num);
goto P;
}
}
P:
printf("\nIf you wish to continue to another game, press Enter\n");
printf("If you wish to quit and go to the summary, press X\n");
ch=getchar();
fflush(stdin);
a=toupper(ch);
if(a=='X')
break;
}
printf("Results summary:\n");
printf("\tNumber of games played :%d\n",i);
printf("\tNumber of wins :%d\n",c);
y=(double)(c/i)*100;
printf("\tWinning percentage :%f%%\n",y);
getchar();
return 0;
}

0 comments:

Post a Comment

මේ ලිපිය ගැන ඔබට හිතෙන්නේ මොකක්ද? ගල්, මුල්, මල් ඕන දේකට ඉඩ...
සිංහලෙන් යතුරු කරන්නට යුනිකේත එසැණින් පරිවර්තකය භාවිතා කරන්න පුළුවන්.