From 173b001ad17812b8a1a13271d44d71515facccc5 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 9 Jul 2016 13:02:21 -0400 Subject: [PATCH 1/4] Final project proposal --- final.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 final.txt diff --git a/final.txt b/final.txt new file mode 100644 index 0000000..20c0904 --- /dev/null +++ b/final.txt @@ -0,0 +1,9 @@ +Jack Rosen. +I am creating a text-based game where you need to escape the cops in a car. +The game will tell you how much gas you have, how much space is between you and the cops, how much oil is left, and how far you are from winning. You can win if you are over 30 miles from the cops. And you lose if you are under 5 miles from the cops. The user will be prompted to either go fast, go slow, refill gas, or refill the oil. +There will be a conditional so the person chooses what they want to do. +The loop will keep asking the person what they want to do until they win or lose. +The functions will be in use depending on what you input. +The structures will hold data about your name, the distance between you and the cops, the amount of gas left, and when you need to change oil. +The array will hold your name. +I chose this program because it uses all of the programming techniques we have learned and it seemed like an interesting way to use it. From 26fbefaad2b910e329c153277786cc16c8624098 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 15 Jul 2016 10:22:37 -0400 Subject: [PATCH 2/4] Executable file for the final project --- project | Bin 0 -> 13328 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 project diff --git a/project b/project new file mode 100755 index 0000000000000000000000000000000000000000..acaf9a06f1eea60be94b7f328329866bc1d997be GIT binary patch literal 13328 zcmeHOeQ;dWb-$~XY+)OH*v7~<#8(6}GO-ui*hUnnS6^mjgi&o7%rs{Gy!%%B@M?Fn z`<^XPKE$jAY*YtNQyM1IOwFXpBw?m;ryc4EV^+o#+01lC?o2vNnsgir%*ryvKp=_> zR)6Py?7m&CQran#e{wbZ&c{9H+;h)8_r7=EyLzIlXIquW!*r=)f6RzFKF=>$^2%86 zT0tsaE4zyM*(!D&n+Hw}etuCyP+}TRE7Ka*DmgD;HGZvClF?e_7l?+}Nj6%LMSDn) z+A9{nLM2?ZQj!`n#s!1)$k&E12@-IhKs1ahKavV+Jt9f3Md`IDJ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ypJb_M z*a%#=Eh^Nd<0}$bqy-hfj1+cs?z{DWz$JBDy?CT_ARl#q^tyZ%c$M1U(<1e!%8Zw{ F|KE&Hy} Date: Fri, 15 Jul 2016 10:22:51 -0400 Subject: [PATCH 3/4] Code for final project --- project.c | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 project.c diff --git a/project.c b/project.c new file mode 100644 index 0000000..9dae7f0 --- /dev/null +++ b/project.c @@ -0,0 +1,279 @@ +#include +#include +#include + +/*Creates a structure for the person*/ +typedef struct persona +{ + int distance; + int engine; + int gas; + int durability; +} person; + +/*Shows the distance the police move each turn*/ +int copDistance(int distance) +{ + int r = (rand() % 3) +1; + distance -= r; + return distance; +} + +/*Fixes the user's engine*/ +int fixEngine(int engine) +{ + engine = 6; + printf("Your engine is fixed!\n"); + return engine; +} + +/*Moves the user quickly*/ +int goFast(int distance) +{ + distance += (rand() % 3) + 4; + return distance; +} + +/*Moves the user slowly*/ +int goSlow(int distance) +{ + distance += (rand() % 2) + 2; + return distance; + +} + +/*Refills the user's gas*/ +int refillGas(int gas) +{ + gas = 20; + printf("Your gas tank is full!\n"); + return gas; +} + +int fixCar(int durability) +{ + durability = 2; + printf("Your car is fixed!\n"); + return durability; +} + +int main() +{ + + int moving; + /*starts the random number generator*/ + srand(time(0)); + /*Sets the scene for the game*/ + printf("You are on the run from the police. Can you escape? Choose your actions wisely because you can be caught!!\n"); + /*Calls for the user input and initializes the hiding places*/ + char input, hidingPlace[4][100] = {"Alley", "Store", "Concert", "Supermarket"}; + /*Initializes the while loop parameter*/ + int x = 0; + /*Initializes the structure*/ + person user; + user.distance = 10; + user.engine = 6; + user.gas = 20; + user.durability = 2; + /*Initializes the opportunity for car crash*/ + int crash = 0, crashchecker = 0; + /*Initializes the hiding place possibility*/ + int hiding[2] = {0,0}; + /*Initializes error checkers*/ + int hWorks = 0, error = 0, s = 0; + static int i = 0; + while (x == 0) //Start of while loop + { + s = 0; + /*Prompts the user for input*/ + printf("What would you like to do?\n"); + printf("Write q to quit, e to fix your engine, g to refill gas, f to go fast, i for information, d to fully fix your car to its full durability and s to go slow\n"); + /*Gives user possibility for hiding place*/ + hiding[1] = rand() % 10; + /*Checks to see if the user found a hiding spot*/ + if (hiding[1] == 8 && i > 0 && error == 0) + { + /*Decides the hiding place*/ + hiding[2] = rand() % 4; + printf("You have found a hiding spot. It is in the %s. Put in h to hide.\n", *(hidingPlace + hiding[2])); + } + /*Scans for user input*/ + scanf("%c", &input); + /*Checks user input*/ + if (input == '\n') + { + input = getchar(); + } + /*Checks if user input is valid for hiding*/ + if ((input == 'h' || input == 'H') && hiding[1] == 8) + { + hWorks++; + /*Decides if the user has hid from the cops*/ + hiding[2] = rand() % 6; + if (hiding[2] == 3) + { + printf("You hid from the cops and escaped the police, so you win!!\n"); + x++; + break; + } + else + { + printf("You did not escape the police, so you need to keep moving!\n"); + user.distance = copDistance(user.distance); + } + + } + error = 0; + /*Evaluates each user input*/ + switch (input) + { + case 'Q': + case 'q': + printf("You have chosen to quit, are you sure? Write y for yes or n for no!\n"); + /*Evaluates user input to see if they actually want to quit*/ + while (s == 0) + { + scanf("%c", &input); + if (input == '\n') + { + scanf("%c", &input); + } + if (input == 'y' || input == 'Y') + { + x++; + s++; + printf("Have a nice day! \n"); + } + else if (input == 'n' || input == 'N') + { + s++; + printf("Why would you lie to me like that?\n"); + } + else + { + printf("That is not a valid input \n"); + } + } + break; + case 'E': + case 'e': + user.engine = fixEngine(user.engine); + user.distance = copDistance(user.distance); + error ++; + break; + case 'G': + case 'g': + user.gas = refillGas(user.gas); + user.distance = copDistance(user.distance); + error++; + break; + case 'F': + case 'f': + moving = user.distance; + user.distance = goFast(user.distance); + /*Calculates how much the user has moved*/ + moving = user.distance - moving; + printf("You moved %d miles! \n", moving); + user.distance = copDistance(user.distance); + /*Calculates how much gas the user has lost*/ + user.gas -= (rand() % 2) + 3; + user.engine--; + break; + case 'S': + case 's': + moving = user.distance; + user.distance = goSlow(user.distance); + /*Calculates how much the user has moved*/ + moving = user.distance - moving; + printf("You moved %d miles! \n", moving); + user.distance = copDistance(user.distance); + /*Calculates how much gas the user has lost*/ + user.gas -= (rand() % 2) + 1; + user.engine--; + break; + case 'I': + case 'i': + /*Tells the users all of the information*/ + printf("You are %d miles away from the police, you have %d more moves before you need to fix your engine, you have %d more gallons of gas left, and your car can survive %d more crashes! \n", user.distance, (user.engine - 1), user.gas, (user.durability - 1)); + error++; + break; + case 'D': + case 'd': + user.durability = fixCar(user.durability); + user.distance = copDistance(user.distance); + break; + case 'H': + case 'h': + /*Checks if the user input is valid for h*/ + if (hWorks != 0) + { + break; + } + /*Returns errors if it is incorrect placement*/ + default: + printf("That is not a valid input\n"); + error++; + } + /*Checks if user crashed*/ + crash = rand() % 12; + if (crash == 11 && (input == 'f' || input == 'F' || input == 'S' || input == 's')) + { + if (user.durability == 2) + { + printf("You have crashed, and if you crash again you will lose!\n"); + user.durability--; + } + else if (user.durability == 1) + { + printf("You have crashed and your car broke. You lose!!\n"); + x++; + } + + } + /*Checks end-of-game scenarios*/ + if (x == 1) + { + break; + } + if (user.distance < 8 && user.distance >= 5) + { + printf("The police are calling out \"We are coming, you should pull over!\""); + printf("\n"); + } + else if (user.distance >= 35) + { + printf("You have outran the police!!\n"); + x++; + break; + } + else if (user.distance < 5) + { + printf("The police have caught you. You lose!\n"); + x++; + break; + } + if (user.gas <= 0) + { + printf("You lose because you ran out of gas!!\n"); + x++; + break; + } + if(user.engine == 1) + { + printf("Your engine needs fixing.\n"); + } + else if (user.engine < 1) + { + printf("You lose because you needed to fix your engine.\n"); + x++; + break; + } + if (user.gas <= 4 && user.gas > 0) + { + printf("Your gas level is very low\n"); + } + i++; + hWorks = 0; + printf("\n"); + } +} From 942c82a2728a508ab1e968a8a06d49e7fdd1839d Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 15 Jul 2016 10:23:02 -0400 Subject: [PATCH 4/4] ReadMe --- readme.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..1c3f5c4 --- /dev/null +++ b/readme.txt @@ -0,0 +1,12 @@ +Jack Rosen +Game Description: +This game is designed so that you are on the run from the police. It starts by giving a brief description and before every turn, the game displays the options that you can use. Randomly, a hiding spot will appear and you will have the option of hiding there. There is a chance that you will escape the police from that, but if you don't, the police will still keep moving. If you want to quit, press q and it will ask if you are sure that you want to quit. You can input your choice after it tells you all of the options. You can run it using the executable file that will be given to you. + +To win the game: +There are a couple of ways to win the game. You can get 35 miles or farther from the police. Also, if you try to hide from the police, there is a chance that you will win. + +Changes: +I added the hiding places and took out the name. The name did not seem important and the idea of hiding places was much better. I also changed "running out of oil" to "fixing the engine" to make the game more realistic. I also added durability and car crashes. The car will be able to survive one car crash, and if the person does not fix it and it crashes again, the user loses. + +Compilation: +To compile, use "gcc project.c -o project"