Contact Learn C
Copy

Program 295: Hand Cricket Game in C

Program 295: Hand Cricket Game in C
 
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
int GetPlayerToss(char player1[],char player2[],int oversToplay);
int batting(char battingplayer[],char bowlingplayer[],int oversToplay);
int main()
{
 int i,j,overs,noovers,player1Toss,player2Toss;
 char player1[50],player2[50];
 srand(time(NULL));
 printf("-----------------------------------WELCOME TO HAND CRICKET GAME-------------------------------------\n");
 printf("Enter Player 1 Name:");
 fflush(stdin);
 gets(player1);
 printf("Enter Player 2 Name:");
 fflush(stdin);
 gets(player2);
 printf("Enter\n1 - Fixed Overs\n2 - Play Until Out\n3 - How to Play?\n4 - Exit: ");
 scanf("%d",&noovers);
  do{
 if(noovers==1)
 {
  printf("Enter No Of Overs: ");
  scanf("%d",&overs);
  player1Toss=GetPlayerToss(player1,player2,overs); 
  
 }
 else if(noovers==2)
 {
  player1Toss=GetPlayerToss(player1,player2,0);
 }
 else if(noovers==3)
 {
  printf("How To Play?\n");
  printf("Until a player Won the toss Follow the Output and give whatever it asks you to give\n");
  printf("Then the Player who won the toss chooses either to Bat or to Bowl\n");
  printf("The Player who chose batting and bowling has to proceed by pressing enter Key one by one\n");
  printf("Where System will generate Random number as runs for both players.Player 1 runs keeps on adding until his runs equals to player 2 runs\n");
  printf("Finally When Player 1 is Out.Till then his runs are his final Score.The Same process will be Conducted for player 2.\n");
  printf("Finally whoever is having Highest Score is the Winner.\n\n");
  printf("For Example: Player 1 Won the Toss And Chose Batting.Then When Player 1 Press Enter Key,A score will be generated for Player 1\n");
  printf("Suppose runs are 5 So Player 1 Score=5.Then Player 2 Also Presses Enter key.Then if he got a Score of 4.So Player 2 Score =4\n");
  printf("As Player 1 Score is not equal to player 2 Score Then Player 1 is not out and hi score will be 5 after 1st ball \n");
  printf("In 2nd ball Player 1 got 3 runs and Player 2 got 4.Since again both are not equal.Player 1 Score=5+3=8\n");
  printf("If in the 3rd Ball Player 1 got 4 runs and Player 2 also got 4 runs Then Player 1 Score is equal to Player 2's Score Then Player 1 is Out\n");
  printf("Then Final Score of player 1 is 8 runs.\n");
  printf("The Same Process is done for Player 2.So Finaly who ever got more score is Winner\n");
 }
 else
 {
  printf("--------------------------------------------Invalid Choice--------------------------------------------\n");
 }
 printf("Enter 1 - Fixed Overs\n2 - Play Until Out\n3 - How to Play?\n4 - Exit: ");
 scanf("%d",&noovers);
  }while(noovers>=1 && noovers<=3);
 return(0);
}

int GetPlayerToss(char player1[],char player2[],int oversToplay)
{
 int player1Choice,player2Choice,toss,player1Toss,batorbowlChoice,player2Score,player1Score;
     printf("%s Choose your choice either 1 for head or 2 for tail: ",player1);
  scanf("%d",&player1Choice);
  if(player1Choice==1)
  {
   player2Choice=2;
   printf("%s Choice is Tail\n",player2);
  }
  else if(player1Choice==2)
  {
   player2Choice=1;
   printf("%s Choice is Head\n",player2);
  }
  else
  {
   printf("--------------------------------------------Invalid Choice--------------------------------------------\n");
   return(0);
  }
  toss=rand()%2;
  toss=toss+1;
  if(toss==1)
  printf("Toss is Head\n");
  else
  printf("Toss is Tail\n");
  if(toss==player1Choice)
  {
   player1Toss=1;
   printf("Player 1 %s Won the Toss\n",player1);
   printf("Choose\n1 - Batting\n2 - Bowl: ");
   scanf("%d",&batorbowlChoice);
   if(batorbowlChoice==1)
   {
        printf("----------------%s is Going to bat Now-----------------------\n",player1);
    player1Score=batting(player1,player2,oversToplay);
    printf("----------------%s is Going to bat Now-----------------------\n",player2);
    player2Score=batting(player2,player1,oversToplay);
    printf("----------------Its Time for Results-----------------------\n");
   }
   else
   {
    printf("----------------%s is Going to bat Now-----------------------\n",player2);
    player2Score=batting(player2,player1,oversToplay);
    printf("----------------%s is Going to bat Now-----------------------\n",player1);
    player1Score=batting(player1,player2,oversToplay);
    printf("----------------Its Time for Results-----------------------\n");
   }
  }
  else if(toss==player2Choice)
  {
   player1Toss=2;
   printf("Player 2 %s Won the Toss\n",player2);
   printf("Choose\n1 - Batting\n2 - Bowl: ");
   scanf("%d",&batorbowlChoice);
   if(batorbowlChoice==1)
   {
    printf("----------------%s is Going to bat Now-----------------------\n",player2);
    player2Score=batting(player2,player1,oversToplay);
    printf("----------------%s is Going to bat Now-----------------------\n",player1);
    player1Score=batting(player1,player2,oversToplay);
    printf("----------------Its Time for Results-----------------------\n");
   }
   else
   {
    printf("----------------%s is Going to bat Now-----------------------\n",player1);
    player1Score=batting(player1,player2,oversToplay);
    printf("----------------%s is Going to bat Now-----------------------\n",player2);
    player2Score=batting(player2,player1,oversToplay);
    printf("----------------Its Time for Results-----------------------\n");
   }
  }
  else
  {
   printf("------------------------------------------------Error-------------------------------------------------\n");
   return(0);
  }
  if(player1Score==player2Score)
  {
   printf("Draw Match\nThanks For Playing the Game\n");
  }
  if(player1Score>player2Score)
  printf("%s Won the Match\nThanks for Playing the Game\n",player1);
  if(player1Score<player2Score)
  printf("%s Won the Match\nThanks for Playing the Game\n",player2);
  return(player1Toss);
}

int batting(char battingplayer[],char bowlingplayer[],int oversToplay)
{
 int i,j,battingScore,sum=0,bowlerSocre,flag=1;
 char c;
 if(oversToplay>0)
 {
  for(i=1;i<=oversToplay;i++)
  {
   for(j=1;j<=6;j++)
   {
    printf("%d.%d ball\n",i,j);
    printf("%s Press Enter key to bowl :",bowlingplayer);
    fflush(stdin);
    scanf("%c",&c);
    fflush(stdin);
    bowlerSocre=(int)rand()%7;//Generate from 0-6 where 0 means no ball
    printf("%s Press Enter key to bat :",battingplayer);
    fflush(stdin);
    scanf("%c",&c);
    fflush(stdin);
    battingScore=rand()%7;//Generate 0-6 runs
    if(battingScore==bowlerSocre)
    {
     flag=0;
     printf("-----------------%s is Out----------------\n",battingplayer);
     printf("%s Total Score=%d\n",battingplayer,sum);
     if(sum==0)
            printf("-----------Hehehe Duck Out-----------------\n");
     break;
    }
    else
    {
     printf("Got %d runs\n",battingScore);
                    if(battingScore==6)
                    printf("Sixerrrrrr Keep it Up\n");
                    if(battingScore==4)
               printf("Its a Four Great Man\n");
     sum=sum+battingScore;
     printf("%s Score=%d\n",battingplayer,sum);
    }
   }
   if(flag==0)
   break;
  }
 
  return(sum);
 }
   if(oversToplay==0)
   {
      while(flag)
      {
        printf("%s Press Enter key to bowl :",bowlingplayer);
  fflush(stdin);
  scanf("%c",&c);
  fflush(stdin);
  bowlerSocre=(int)rand()%7;//Generate from 0-6 where 0 means no ball
  printf("%s Press Enter key to bat :",battingplayer);
  fflush(stdin);
  scanf("%c",&c);
  fflush(stdin);
  battingScore=rand()%7;//Generate 0-6 runs
  if(battingScore==bowlerSocre)
  {
   flag=0;
   printf("-----------------%s is Out----------------\n",battingplayer);
   printf("%s Total Score=%d\n",battingplayer,sum);
   if(sum==0)
   printf("-----------Hehehe Duck Out-----------------\n");
   break;
  }
  else
  {
   printf("Got %d runs\n",battingScore);
            if(battingScore==6)
            printf("Sixerrrrrr Keep it Up\n");
            if(battingScore==4)
       printf("Its a Four Great Man\n");
   sum+=battingScore;
   printf("%s Score=%d\n",battingplayer,sum);
  }
      }
      return(sum);
   }
 
}

Explanation:

//Coming Soon...

Output:

Hand Cricket Game in C

Hand Cricket Game in C

Hand Cricket Game in C

Hand Cricket Game in C

Hand Cricket Game in C








 

30 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. can i can i create a website like PSL 5 Schedule using this unique code.?

    ReplyDelete
  3. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

    ReplyDelete
  4. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. สล็อตไม่มีขั้นต่ำ

    ReplyDelete
  5. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. 토토

    ReplyDelete
  6. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. run 3 unblocked game

    ReplyDelete
  7. I m surprised to hear such an amazing article. I ll visit often. Thank you always. 토토커뮤니티순위

    ReplyDelete
  8. It s my great luck to find this place. I ll visit today and tomorrow. Thank you. 토토추천사이트

    ReplyDelete
  9. Incredible post I should state and much obliged for the data. Instruction is unquestionably a sticky subject 메이저사이트

    ReplyDelete
  10. It’s arduous to search out educated people on this subject, but you sound like you already know what you’re talking about! Thanks visit

    ReplyDelete
  11. As a seller of legal steroids, you can buy Crazy Bulk products, explore stacks and finally get the body you’ve always wanted Daget 77

    ReplyDelete
  12. A round of applause for your article. Really thank you! Awesome.
    pragmatic

    ReplyDelete
  13. buy views for youtube If you are one of those asking the question 'how does YouTube make money'? then you are about to be extremely happy. This is because you will know about the actual strategies that must be in place before YouTube makes you money; the top ways to create YouTube videos that will make money for you and the actual element every YouTube video must have before it can make you money. After reading, you should be able to make money with YouTube easily from now on.

    ReplyDelete
  14. Enjoyed every bit of your article. Thanks Again. Really Great.
    fortune 228 slot

    ReplyDelete
  15. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again. บาคาร่าUFABET

    ReplyDelete
  16. Thanks so much for sharing this awesome info! I am looking forward to see more postsby you! รีวิวเว็บแทงบอล UFABET

    ReplyDelete
  17. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. ราคาบอล ufabet

    ReplyDelete
  18. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. UFABET

    ReplyDelete
  19. Interesting and interesting information can be found on this topic here profile worth to see it. Off Page SEO

    ReplyDelete
  20. This is one awesome article post. Thanks Again. Really Great.
    slot akun demo

    ReplyDelete
  21. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. https://redditmmastreaming.live/

    ReplyDelete
  22. It was wondering if I could use this write-up on my other website, I will link it back to your website though.Great Thanks. https://redditnhlstreaming.live/

    ReplyDelete
  23. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. 먹튀

    ReplyDelete
  24. Appreciate you sharing great article. Really looking forward to read more. Great.
    minecraft servers

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Contrasted with pen and paper games, you're not expected to look into tables or enter long exhausting conversations on how rules ought to be deciphered.
    Join more than 5,250 fans of a new raising star in NFT games.

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide