Question

In: Computer Science

write a code for a typing game in plain C coding.

write a code for a typing game in plain C coding.

Solutions

Expert Solution

#include<time.h>

#include<conio.h>

#include<stdio.h>

#include<dos.h>

#include<stdlib.h>

#include<shashi.h>//contains the definition of gotoxy,setcolor etc.

static int x=1;//used for x cursor co-ordinate

#define pos gotoxy(33,x++) /*for cursor movement*/

#define ln printf(".......................");

//.............................................................................................................................................

void sett();//sets time limit for playing game

int t=30;

int c=0;

int size =5;

int limit=5;

char name[15];

void rstring();

void getscore(int score,int speed,int level);

void startgame(); //to start the game

void scorecard(); //to update high score

void About_me();

void help();

void rectangle(int x,int y,int l,int b)//to create a rectangle

{

int i,m;

gotoxy(x,y); printf("%c",201);

for(i=x+1;i<l-1;i++)

{

gotoxy(i,y);

printf("%c",205);

}

gotoxy(i,y); printf("%c",187);

for (m=y+1;m<b;m++)

{

gotoxy(x,m);

for(i=x;i<l;i++)

{

if(i==x||i==l-1)

{

gotoxy(i,m); printf("%c",186);

}

}

}

gotoxy(x,m); printf("%c",200);

for(i=x+1;i<l-1;i++)

{

gotoxy(i,m);

printf("%c",205);

}

gotoxy(i,m); printf("%c",188);

}

// main function

int main()

{ int ch;

time_t t;

time(&t);

// rectangle(0,0,70,15);

x=1;

system("cls");

pos;

setcolor(12) ;

printf("welcome to typing game ");

setcolor(10) ;

pos;

printf("%s",ctime(&t));

pos;

ln pos;

if(c==0)

   { printf("Enter player's name::");

gets(name);

   }

   c++;

pos;ln pos;

printf("#..MAIN MENU..#");pos;

ln

pos;

printf("1.startgame");

pos;

printf("2.scorecard");

pos;

printf("3.Set the time limit::");

pos;

printf("4.Help");

pos;

printf("5.About me");

pos;

printf("0.exit");

pos;

printf("Enter your choice::");

scanf("%d",&ch);

pos;

switch(ch)

{ case 1:startgame();break;

case 2:scorecard();break;

case 3:sett();main();

case 4:help();break;

case 5:About_me();break;

case 0:system("cls");gotoxy(17,10);printf("#This Game is created by computer#");delay(1000);exit(1);

default:main();

}

getch();

}

//.....................end of main function.................................

   //startgame

//..........................................................................

void startgame()

{ int score=0,level=1,mode=100,count=0;

clock_t begin;int time_spent,speed;

int r,letter,ch;

rectangle(0,0,70,15);

delay(500);

system("cls");

srand(time(NULL)) ; //initilizes random function and seed with time

x=2;

pos;

setcolor(12);

printf("#select the Mode#");pos;

ln

pos;

printf("1.Easy mode(upper case alphabet)#");

pos;

printf("2.Normal mode(lower case alphabet)#");

pos;

printf("3.hard mood(words)#");

pos;

printf("4.Back to main menu#");

pos;

scanf("%d",&level);

if(level==4)

main();

else

{ if(level==1) //boundary addition for lowercase alphabet

   mode=65;

   if(level==2) //boundary addition for uppercase

mode=97;

   if(level==3) //condition for mixed case

rstring();

else

{

begin=clock();

while(1)

{ system("cls");

time_spent=(int)(clock()-begin)/CLOCKS_PER_SEC;

if(time_spent>=t)

break;

r=rand()%1000;

r=r%26+mode;

gotoxy(20,8);

printf("....Type the following character....");

gotoxy(36,11) ;

printf(" %c",r); //prints random character

letter=getch();

if(letter!=r)

break;

else

{ count++;

score=score+10;

gotoxy(28,9);

printf("score=%d",score);//prints score

gotoxy(37,9);

printf("time_spent=%d sec",time_spent);//prints time spent during game

if(level==1)

delay(400);

if(level==2)

delay(200);

if(level==3)

delay(100);

} //end of else

}//end of while

gotoxy(26,x);

delay(400);

setcolor(5); //blue text color

++x;

pos;

speed=(count*60)/time_spent ;

if(time_spent<t-1)

printf("You are looser!loser!loser!Game Over!");

else

{ setcolor(11);

printf("Times up !Game over!");

pos;

setcolor(5);

if((speed>=40)&&(speed<=50))

{ printf("Good Work !Keep it up!");pos;

printf("You got silver medal");

}

else

if(speed>50)

{

printf("Nice work! You got Gold medal");

}

else

printf("Sorry no medal !you need practise..");

}

pos;

printf("Total score is ::%d",score);

pos;

printf("Your net speed=%d letter per minute",speed);

getscore(score,speed,level);//saves data to file

++x;

pos;

printf("1.# play again #");

pos;

printf("2.# main menu #");pos;

printf("3.exit"); pos;

printf("Enter your choice::");

scanf("%d",&ch);

switch(ch)

{

case 1:startgame();break;//recursive call

case 2:main();break;

case 3:system("cls");gotoxy(17,10);printf("#This Game is created by computer#");delay(1000);exit(1);

default:pos;printf("wrong choice!");pos;

main();

}

}

}

}

//......................end of start game function..........................

//...........................sett function starts..........................

void sett() //set time limit

{

int ch;

system("cls");

//rectangle(0,0,70,15);

setcolor(11);

x=5;

pos;

printf("Set the time limit for game in minute::");

pos;

ln

pos;

printf("press 0 for half minute") ;pos;

printf("press 1 for 1 minute"); pos;

printf("press 2 for 2 minute");pos;

scanf("%d",&ch);

switch(ch)

{

case 0:t=30;break;

case 1:t=60;break;

case 2:t=120;break;

default:main();

}

}

//....................sett function ends....................................

//........................................................................

void help()

{

system("cls");

//rectangle(0,0,70,15);

gotoxy(7,5);

setcolor(6);

printf("#......Rules of the Game......#");gotoxy(7,6);

printf("=>Enter your name as player name");gotoxy(7,7);

printf("=>Set the time limit under option 3 in main menu(default limit is 30 sec)");gotoxy(7,8);

printf("=>select the level and get started :");gotoxy(7,9);

printf("=>Characters are displayed and you have to type them as fast as you can..");gotoxy(7,10);

printf("=>Avoid incorrect typing otherwise game will be over..");gotoxy(7,11);

printf("=>Hit Enter in hard mode after typing the word:");

getch();main();

}

void About_me()

{ system("cls");

gotoxy(7,7);

printf("Hello every on I am comuter");

printf(".I think it would be better....thanks... have fun");

getch();

main();

}

//.........................................................................

void getscore(int score,int speed,int level)

{

FILE *fp;

fp=fopen("file.txt","a");

pos;

if(fp==NULL)

printf("error in opening file");

fprintf(fp,"\nname=%s score=%d speed=%d level=%d",name,score,speed,level);

fclose(fp);

pos;

//printf("scorecard updated");

}

void scorecard()

{ int ch;

FILE *fp;

system("cls");

//rectangle(0,0,70,15);

x=3;

printf("\t\t\t....The scores are...\n");

fp=fopen("file.txt","r");

while((ch=fgetc(fp))!=EOF)

{ printf("%c",ch);

}

getch();

main();

}

//.....................................................................................................................

//function for third level hard mode (to generate the strings randomly)

void rstring()

{ int time_spent,score=0,level=3,speed=0;

pos;

setcolor(13);

printf("Enter the no of letters of the word::");

scanf("%d",&limit);

pos;

srand(time(NULL));

clock_t begin;

begin=clock();

while(1)

{ // printf("Enter the following word");

system("cls");

x=8;

pos;

printf("Enter the following word");

time_spent=(int)(clock()-begin)/CLOCKS_PER_SEC;

if(time_spent>=t)

{

pos;

printf("\t......Times Up.....");

pos;

speed=(score*60)/(time_spent*20);

printf("Total score=%d speed=%d word per minute",score,speed);pos;

getscore(score,speed,level);

printf("Enter any key to go to back menu..");

getch();

startgame();

}

pos;

printf("time_spent=%d score=%d",time_spent,score);

size=limit;

char src1[size];

char src[size];

//size = rand() % size; // this randomises the size (optional)

src[size] = '\0'; // start with the end of the string...

// ...and work your way backwards

while(--size > -1)

src[size] = (rand() % 26) + 97;

pos;

puts(src);

pos;

scanf("%s",&src1);

if(strcmp(src,src1))

{ pos;

printf("\t......wrong.....");

pos;

speed=(score*60)/(time_spent*20);

printf("Total score=%d speed=%d word per minute",score,speed);pos;

getscore(score,speed,level);

printf("Enter any key to go to back menu..");

getch();

startgame();

}

else

{ score=score+20;

continue;

}

}

}


Related Solutions

Write a simple code for a simple connect the dots game in plain C coding.
Write a simple code for a simple connect the dots game in plain C coding.
Simple code for a game on C coding.
Simple code for a game on C coding.
Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c program.
Write a code for simple racing game (using dots) on c program.
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit via Blackboard): Keep everything as Integers. Row and Column Numbering starts at 1. Equation for each Cell :   Coll = (Row * Col * 10) Using Nested Loops display the following exactly as it is shown below:                                  Columns % Brand         1           2         3          4               A            10         20       30       40          B            20         40        60       80           C            30         60        90    ...
Coding in C++: For this verse, you need to write a program that asks the user...
Coding in C++: For this verse, you need to write a program that asks the user to input the inventory id number (integer) and the price (float) for 5 inventory items. Once the 5 inventory items are input from the user, output the results to the screen. Please ensure you use meaningful names for your variables. If your variables are not named meaningfully, points will be deducted.
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
The Case of the Coding Dilemma Background: Coding is the process of assigning a billing code...
The Case of the Coding Dilemma Background: Coding is the process of assigning a billing code to a patient diagnosis. The billing code comes from a standardized code book. Each code represents a specific diagnosis and a designated amount of reimbursement by government and private insurers. Entering a higher code than is warranted will result in overpayment for the patient’s particular diagnosis. Entering a lower code than is warranted will result in underpayment for the patient’s particular diagnosis. All diagnoses...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT