Смекни!
smekni.com

Застосування BORLAND C BUILDER для створення ігрових програм (стр. 3 из 3)

flag = 0;

}

}

else if(random(20) == 12)

{

first = time(NULL);

printf(" Tan 45 Degree :? ");

printf("\n\n A) 1/2 \t\t B) 2 \n C) 1 \t\t\t D) 0 ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "c") == 0) || (strcmpi(dummy, "1") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> C / 1 ");

flag = 0;

}

}

else if(random(20) == 13)

{

first = time(NULL);

printf(" Oracle 8i Is A :? ");

printf("\n\n A) LANGUAGE \t\t B) SUBJECT \n C) DATABASE \t\t D) NONE ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "c") == 0) || (strcmpi(dummy, "database") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> C / DATABASE");

flag = 0;

}

}

else if(random(20) == 14)

{

first = time(NULL);

printf(" C++ Was Developed By :? ");

printf("\n\n A) BJARNE STROUSTRUP \t\t B) GURJIT \n C) DENNIS RITCHIE \t\t D) KERNINGHAM ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "a") == 0) || (strcmpi(dummy, "bjarne stroustrup") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> A / BJARNE STROUSTRUP ");

flag = 0;

}

}

else if(random(20) == 15)

{

first = time(NULL);

printf(" Which Lizard Can Change Colors :? ");

printf("\n\n A) WALL \t\t B) MONSTER \n C) CHAMELEON \t\t D) NONE ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "c") == 0) || (strcmpi(dummy, "chameleon") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> C / CHAMELEON ");

flag = 0;

}

}

else if(random(20) == 16)

{

first = time(NULL);

printf(" Mowgli Is a Character Of The Popular Comic :? ");

printf("\n\n A) CASPER \t\t B) JUNGLE BOOK \n C) ANASTITIA \t\t D) ALLADIN ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "b") == 0) || (strcmpi(dummy, "jungle book") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> B / JUNGLE BOOK ");

flag = 0;

}

}

else if(random(20) == 17)

{

first = time(NULL);

printf(" Author Of The Jungle Book :? ");

printf("\n\n A) G B SHAW \t\t\t\t B) PREM CHAND \n C) WILLIAM SHAKESPEARE \t\t D) RUDYARD CIPLING ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "d") == 0) || (strcmpi(dummy, "rudyard cipling") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> D / RUDYARD CIPLING ");

flag = 0;

}

}

else if(random(20) == 18)

{

first = time(NULL);

printf(" India Is a :? ");

printf("\n\n A) PENNINSULA \t\t B) ISLAND \n C) PLATEAU \t\t D) NONE ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "a") == 0) || (strcmpi(dummy, "penninsula") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> A / PENNINSULA ");

flag = 0;

}

}

else if(random(20) == 19)

{

first = time(NULL);

printf(" Earth's Only Natural Satellite :? ");

printf("\n\n A) SUN \t\t B) PLUTO \n C) JUPITER \t\t D) MOON ");

scanf(" %[^\n]", dummy);

second = time(NULL);

ret = difftime(second, first);

if( (strcmpi(dummy, "d") == 0) || (strcmpi(dummy, "moon") == 0) )

{

printf(" RIGHT ANSWER ");

flag = 1;

}

else

{

printf(" WRONG ANSWER______The Answer Is ---> D / MOON ");

flag = 0;

}

} else

{

goto raj;

}

}

return(ret);

}

void rules()

{

clrscr();

printf("Hello And Welcome To WHO'LL BE A MILLIONAIRE ");

printf(" \n\n");

printf(" This Game Will Be Played Using 10 Contenders One Out Of 10,");

printf(" Will \n Be Selected In The First Round : FASTEST CONTENDER FIRST \n\n");

printf(" He/She Will Then be Asked 15 Questions And Shall Win Money[$] As : \n");

printf("\n Question No. 1 -> $1000 "

"\n Question No. 2 -> $2000 "

"\n Question No. 3 -> $3000 "

"\n Question No. 4 -> $4000 "

"\n Question No. 5 -> $5000[ 1st HURDLE ] "

"\n Question No. 6 -> $10,000 "

"\n Question No. 7 -> $20,000 "

"\n Question No. 8 -> $40,000 "

"\n Question No. 9 -> $80,000 "

"\n Question No.10 -> $1,60,000 "

"\n Question No.11 -> $3,20,000 [ 2nd HURDLE ] "

"\n Question No.12 -> $9,60,000 "

"\n Question No.13 -> $28,80,000 "

"\n Question No.14 -> $86,40,000 "

"\n Question No.15 -> $25,920,000 [ You Are a Millionaire ]");

printf("\n\n\n To CONTINUE READING The Rules Of This Game Please Press ENTER.....");

getch();

printf(" \n\n (** If You Fail To Cross The [1st HURDLE] You Take Home $ 0 **)");

printf(" \n (** Cross [1st HURDLE] = You Win atleast $10,000 **) \n (** Cross [2nd HURDLE] = You Win Atleast $4,80,000 **) ");

getch();

}

void contend()

{

int j;

clrscr();

printf(" \n\n Please Enter The 10 Contenders : \n\n");

for(j = 0; j < n; j++)

{

printf("&bsol;n CONTENDER %2d: ", j+1);

scanf(" %[^&bsol;n]", &name[j]);

}

}

void game()

{

int que, i, val=0;

long sum = 0;

float ret=0, temp = 100;

clrscr();

for(i = 0; i < n; i++)

{

printf("&bsol;n&bsol;n %d. %s --- ", i+1, name[i]);

ret = question();

if(flag == 1)

{

printf("&bsol;n&bsol;n %s You took %f seconds", name[i], ret);

take = flag;

if(ret < temp)

{

temp = ret;

val = i;

}

}

}

if(take == 0)

{

printf("&bsol;n&bsol;n &bsol;a NOBODY QUALIFIES FOR THE FINAL ");

getch();

}

else if(take == 1)

{

printf(" &bsol;n&bsol;n Congratulations %s You Shall Play Because You Took %f seconds ", name[val], temp);

printf(" &bsol;n&bsol;n&bsol;n %s , Let's PLAY WHO'LL BE A MILLIONAIRE ........PLEASE PRESS ANY KEY ", name[val] );

getch();

for(i = 0; i < 15; i++)

{

printf("&bsol;n&bsol;n Here's Your %d Question %s --> ", i+1, name[val]);

printf("&bsol;n");

question();

if(flag == 1 && i <= 4)

{

printf("&bsol;n&bsol;n %s You WIN $ %ld ", name[val], sum += 1000);

}

else if(flag == 0 && i <= 4)

{

printf("&bsol;n&bsol;n&bsol;a %s SORRY You WIN $ 0", name[val]);

getch();

goto close;

}

if(i == 4)

{

textcolor(LIGHTMAGENTA);

printf("&bsol;n&bsol;n");

cprintf(" Congratulations %s -- $$ Crossing The 1st HURDLE -- YOU WIN $5000 ", name[val]);

}

if( (flag == 1) && (i > 4 && i <= 10) )

{

printf("&bsol;n&bsol;n %s You WIN $ %ld ", name[val], sum *= 2);

}

else if( (flag == 0) && (i > 4 && i <= 10) )

{

printf("&bsol;n&bsol;n&bsol;a %s SORRY You WIN $ 10,000", name[val]);

getch();

goto close;

}

if(i == 10)

{

textcolor(LIGHTGREEN);

printf("&bsol;n&bsol;n");

cprintf(" Congratulations %s -- $$ Crossing The 2nd HURDLE -- YOU WIN $3,20,000 ", name[val]);

}

if( (flag == 1) && (i > 10 && i <= 14) )

{

printf("&bsol;n&bsol;n %s You WIN $ %ld ", name[val], sum *= 3);

}

else if( (flag == 0) && (i > 10 && i <= 14) )

{

printf("&bsol;n&bsol;n&bsol;a %s SORRY You WIN $ 3,20,000", name[val]);

getch();

goto close;

}

if(i == 14)

{

for(int k = 0; k < 1000; k++)

{

textbackground(LIGHTRED);

textcolor(LIGHTGREEN);

cprintf("_ MILLIONAIRE _");

}

}

getch();

} // END OF for

}// END OF else

close:

}// END OF game()

main()

{

clrscr();

while(choice != 4)

{

choice = 0;

textcolor(LIGHTCYAN);

menu();

switch(choice)

{

case 1 : textcolor(LIGHTGREEN);

rules();

break;

case 2 : textcolor(LIGHTMAGENTA);

contend();

break;

case 3: textcolor(LIGHTCYAN);

game();

break;

case 4 : break;

default : printf("&bsol;n&bsol;aSorry Wrong Choice Entered , ENTER ->> [1/2/3/4] ");

getch();

getch();

}

}

return(0);

}


Результат роботи програми

Скрін 1. Загальний текстовий інтерфейс ігрової програми

Скрін 2. Початок гри

Скрін 3. Етапи гри (варіанти відповідей)

Висновки

В роботі були проаналізовані питання відносно теоретичної основи побудови програм з простим інтерфейсом користувача а також проблеми, які виникають при цьому. Результатом цього є програма (ігрова) яка реалізує просту текстову інтерфейсну гру “О счасливчик”.

Програма відрізняється від існуючих на ринку простотою інтерфейсу і настроювань.


Література

[1]Касаткин А.И., Вальвачев А.Н. Профессиональное прогрпммирование на языке Си. Мн., 1992. 240 С.

[2]Бруно Бабэ. Просто и ясно о Borland C++. М., 1996. 400 С.

[3]Справочник по классам Borland C++ 4.0. К., 1994. 256 С.

[4]ObjectWindows для C++. К., 1993., 208 С.