Skip to content

Commit

Permalink
Added a game and update file
Browse files Browse the repository at this point in the history
  • Loading branch information
CapedDemon committed Jan 3, 2022
1 parent 18d8fc7 commit b4d9933
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 2 deletions.
Binary file removed CommandConsole
Binary file not shown.
Binary file modified CommandConsole.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions MainCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void mkdr()
//function to print the help menu.
void help()
{
printf("For extra information read the README.md file\n");
printf("\tIn all the cases first write the command hit enter and then give the arguements\n\n");

printf(">>calc - This command open a terminal calculator and you can do simple calculator operation in this.\n\tThe operaation are - (+, -, * , /, ^(Power of. Ex- 3^2 = 9)\n\tFirst number (operation) Second Number\n\tFor doing operation in decimal give d and for integer give i\n\n\n");
Expand Down Expand Up @@ -244,6 +245,7 @@ void help()
printf(">>getf - This will confirm you that the fille or folder name you have given is present in the directory that you specified.\n\n");
printf(">>findf - This will find the specified word in a given file and print the line where it is located.\n\n");
printf(">>hist - This will print all the commands which you have written\n\n");
printf(">>game - This will start a cricket game.\n\n");
}

//function to list all the files in the current directory.
Expand Down
2 changes: 0 additions & 2 deletions Makefile

This file was deleted.

187 changes: 187 additions & 0 deletions Others/cricket.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int random_selector(int lower, int upper, int count)
{
int num;
for (int i = 0; i < count; i++)
{
num = (rand() % (upper - lower + 1)) + lower;
}
return num;
}

int playerBat(int done, int computerRun)
{
int playerHit, ComputerBall, playerRun = 0, computerHit, playerBall;
if (done == 0)
{
while (1)
{
printf("You should play between 1 to 6 or else you will be out\n:");
scanf("%d", &playerHit);
ComputerBall = random_selector(1, 6, 1);
printf("COMPUTER GAVE : %d", ComputerBall);
printf("\n");
if (playerHit != ComputerBall)
{
playerRun += playerHit;
}
if (playerHit == ComputerBall)
{
printf("YOU ARE OUT\n");
break;
}
if (playerHit > 6 || playerHit < 1)
{
printf("YOU LOSE!\n");
return -1;
break;
}
}
}
if (done == 1)
{
while (1)
{
printf("You should play between 1 to 6 or else you will be out\n:");
scanf("%d", &playerHit);
ComputerBall = random_selector(1, 6, 1);
printf("COMPUTER GAVE : %d", ComputerBall);
printf("\n");
if (playerHit != ComputerBall)
{
playerRun += playerHit;
}
if (playerHit == ComputerBall && playerRun <= computerRun || playerHit < 1 || playerHit > 6)
{
printf("YOU LOSE!!\n");
break;
}
if (playerRun > computerRun)
{
printf("CONGRATULATIONS! YOU WON THE MATCH\n");
break;
}
}
}
return playerRun;
}

int playerBall(int done, int playerRun)
{
int computerHit, computerRun = 0, playerBall;
if (done == 1)
{
while (1)
{
computerHit = random_selector(1, 6, 1);
printf("You are balling. Selecet between 1 to 6 or else computer will own\n:");
scanf("%d", &playerBall);
printf("COMPUTER GAVE : %d\n", computerHit);

if (computerHit != playerBall)
{
computerRun += computerHit;
}
if (computerHit == playerBall && computerRun <= playerRun)
{
printf("CONGRATULATIONS! YOU WON THE MATCH\n");
break;
}
if (computerRun > playerRun || playerBall > 6 || playerBall < 1)
{
printf("YOU LOSE\n");
break;
}
printf("COMPUTER TOTAL RUN : %d\n", computerRun);
}
}
if (done == 0)
{
while (1)
{
computerHit = random_selector(1, 6, 1);
printf("You are balling. Selecet between 1 to 6 or else computer will own\n:");
scanf("%d", &playerBall);
printf("COMPUTER GAVE : %d\n", computerHit);

if (computerHit != playerBall)
{
computerRun += computerHit;
}
if (computerHit == playerBall)
{
printf("COMPUTER IS OUT\n");
break;
}
if (playerBall > 6 || playerBall < 1)
{
printf("YOU LOSE\n");
return -1;
break;
}
printf("COMPUTER TOTAL RUN : %d\n", computerRun);
}
}
return computerRun;
}

void game()
{
int toss, playerChoice, decision, playerRun = 0, playerHit, ComputerRun = 0, ComputerHit, ComputerBall;

printf("WELCOME TO CRICKET GROUNDS\n\nChose Head(1) or Tail(0)\n");
scanf("%d", &playerChoice);

//toss evaluation
srand(time(0));
if (random_selector(1, 100, 1) % 2 == 0)
{
toss = 0;
}
else
{
toss = 1;
}

if (playerChoice == toss)
{
printf("CONGRATULATIONS! YOU WON THE TOSS\nPress 1 for Bat and 0 for Ball: ");
scanf("%d", &decision);

//if player chose to bat
if (decision == 1)
{
playerRun = playerBat(0, 0);
printf("\nYOUR TOTAL RUN : %d\n", playerRun);
ComputerRun = playerBall(1, playerRun);
}

// if player chose to ball
if (decision == 0)
{
ComputerRun = playerBall(0, playerRun);
playerRun = playerBat(1, ComputerRun);
}
}
else
{
decision = random_selector(1, 100, 1);
if (decision % 2 == 0)
{
printf("COMPUTER CHOSE TO BAT\n");
ComputerRun = playerBall(0, playerRun);
playerRun = playerBat(1, ComputerRun);
}
else
{
printf("COMPUTER CHOSE TO BALL\n");
playerRun = playerBat(0, 0);
printf("\nYOUR TOTAL RUN : %d\n", playerRun);
ComputerRun = playerBall(1, playerRun);
}
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The main program is written in the main.c file and the functions written there a
- To confirm that a file or folder is present in a directory specified by you: getf
- To get the number of line of a file in which a specified word is present: findf
- To get the list of past commands: hist
- To start a game: game.
(A new cricket game is added to this application so that the users can enjoy while doing work. Check Others/cricket.c)

**We have used the concept of *Linked List* and *Queue* in the code.**

Expand Down Expand Up @@ -82,6 +84,12 @@ sudo apt-get install wine
wine CommandConsole.exe
```
You can also download the zip file, and then run the CommandConsole.exe file.

# <b>Update<b>
For updating the CommandConsole application, run the update.sh file.
**Prerequisite**
- Git need to installed
- The folder or directory in which you have kept the application need to have the name CommandConsole or else there can be some error.

## I have given one screenshot which you can refer to.

Expand Down
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: C
*/
//header files(some are inbuilt and some header files I have created to organize different codes)
#include "MainCommands.h"
#include "Others/cricket.c"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -222,6 +223,11 @@ void main_loop()
insertion(q, "read");

}
else if(strcmp(cmd_str, "game") == 0)
{
game();
insertion(q, "game");
}
else if (strcmp(cmd_str, "cfile") == 0)
{
copy_file();
Expand Down
20 changes: 20 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
echo "UPGRADE SIMULATOR"
echo "Do you have git cli installed(y/n): "
read gitDownload
read -p "USERNAME: " USERNAME
read -sp "PASSWORD: " PASSWORD
echo
if [ "$gitDownload" == "y" ];
then
cd ..

rm -rf CommandConsole
git clone https://github.com/Shreejan-35/CommandConsole.git
#gh repo clone Shreejan-35/CommandConsole
else
echo "Open any browser and install git, you can directly head over to https://git-scm.com/downloads"
echo "After downloading and initializing if you want, you can again start this script"
fi
echo
echo "Press enter to stop"
read esc

0 comments on commit b4d9933

Please sign in to comment.