diff --git a/Cameras/example1.txt b/Cameras/example1.txt new file mode 100644 index 0000000..720bd68 --- /dev/null +++ b/Cameras/example1.txt @@ -0,0 +1,14 @@ +wa 1 +i Hello! +wa 3 +i Welcome to the example! +wa 5 +i I just waited until the 5 second mark! This should have looked like two seconds to you. +wr 4 +i I just waited 4 seconds. +wa 10 +i This should pop up at the 10 second mark +wa 12 +i Let's change cameras +wa 15 +camera example2 diff --git a/Cameras/example2.txt b/Cameras/example2.txt new file mode 100644 index 0000000..b833172 --- /dev/null +++ b/Cameras/example2.txt @@ -0,0 +1,35 @@ +wa 1 +oa 20 this camera has been waiting for you for a while. 15 seconds, give or take. +i Waiting for camera to change +wa 5 +i Still waiting +wa 10 +i STIIIIIILLLL waiting +wa 15 +i Hello! This is a different camera! +wa 17 +i I can also pause your game. Behold! +p +i Welcome back! Sorry for pausing you so abruptly +wa 20 +i I can also pause your game without it telling you that it's paused, like so (press enter to continue): +ps +i Isn't that cool!? +wa 22 +i And unnecessary!? +wa 23 +i ... +wa 24 +i ... +wa 25 +i yes, it probably is +wa 27 +i ... +wa 29 +i ... +wa 31 +i Oh well, all's well that ends well. +wa 33 +i Such as this game +wa 34 +q diff --git a/Cameras/start.txt b/Cameras/start.txt new file mode 100644 index 0000000..b7671d4 --- /dev/null +++ b/Cameras/start.txt @@ -0,0 +1,6 @@ +i Hello! +wa 4 +i You are now 5 seconds into the game. +wa 5 +i 1 second has passed since the previous message +q diff --git a/Cameras/test1.txt b/Cameras/test1.txt new file mode 100644 index 0000000..de9310c --- /dev/null +++ b/Cameras/test1.txt @@ -0,0 +1,30 @@ +i test1 seconds: 0 +oa 10 test1 seconds: 0 +wa 1 +i test1 seconds: 1 +oa 10 test1 seconds: 1 +wa 2 +i test1 seconds: 2 +oa 10 test1 seconds: 2 +wa 3 +i test1 seconds: 3 +oa 10 test1 seconds: 3 +wa 4 +i test1 seconds: 4 +oa 10 test1 seconds: 4 +wa 5 +i test1 seconds: 5 +oa 10 test1 seconds: 5 +wa 6 +i test1 seconds: 6 +oa 10 test1 seconds: 6 +wa 7 +i test1 seconds: 7 +oa 10 test1 seconds: 7 +wa 8 +i test1 seconds: 8 +oa 10 test1 seconds: 8 +wa 9 +i test1 seconds: 9 +oa 10 test1 seconds: 9 +q diff --git a/Cameras/test2.txt b/Cameras/test2.txt new file mode 100644 index 0000000..16c85c9 --- /dev/null +++ b/Cameras/test2.txt @@ -0,0 +1,30 @@ +i test2 seconds: 0 +oa 10 test2 seconds: 0 +wa 1 +i test2 seconds: 1 +oa 10 test2 seconds: 1 +wa 2 +i test2 seconds: 2 +oa 10 test2 seconds: 2 +wa 3 +i test2 seconds: 3 +oa 10 test2 seconds: 3 +wa 4 +i test2 seconds: 4 +oa 10 test2 seconds: 4 +wa 5 +i test2 seconds: 5 +oa 10 test2 seconds: 5 +wa 6 +i test2 seconds: 6 +oa 10 test2 seconds: 6 +wa 7 +i test2 seconds: 7 +oa 10 test2 seconds: 7 +wa 8 +i test2 seconds: 8 +oa 10 test2 seconds: 8 +wa 9 +i test2 seconds: 9 +oa 10 test2 seconds: 9 +q diff --git a/Instructions.c b/Instructions.c new file mode 100644 index 0000000..c36211d --- /dev/null +++ b/Instructions.c @@ -0,0 +1,59 @@ +#include "Instructions.h" +#include +#include + +/* Here's a dictionary mapping the types of instruction with the strings that call them */ +/* to differentiate between instructions, it's best to put a space after instructions with arguments and '\n' after instructions without any */ +const InstructionMap instructionCalls[] = { + {INSTANT_EVENT, "i "}, + {INSTANT_EVENT, "instant "}, + {ONGOING_EVENT_ABSOLUTE, "oa "}, + {ONGOING_EVENT_ABSOLUTE, "ongoing_till "}, + {ONGOING_EVENT_RELATIVE, "or "}, + {ONGOING_EVENT_RELATIVE, "ongoing_for "}, + {WAIT_ABSOLUTE, "wa "}, + {WAIT_ABSOLUTE, "wait_till "}, + {WAIT_RELATIVE, "wr "}, + {WAIT_RELATIVE, "wait_for "}, + {COMMENT, "//"}, + {EXIT, "q\n"}, + {EXIT, "quit\n"}, + {EXIT, "exit\n"}, + {EXIT, "end\n"}, + {CHANGE_CAMERA, "c "}, + {CHANGE_CAMERA, "camera "}, + {LIST_CAMERAS, "cameras\n"}, + {PAUSE, "p\n"}, + {PAUSE, "pause\n"}, + {PAUSE, "\n"}, + {PAUSE_SILENT, "ps\n"}, + {PAUSE_SILENT, "pause_silent\n"}, + {HELP, "help\n"}, + {HELP, "h\n"}, + {HELP, "?\n"} +}; + +/* binds the commands that the player can input to their help text */ +const InstructionMap playerInstructionHelp[] = { + {CHANGE_CAMERA, "To change the camera, type \"camera \""}, + {LIST_CAMERAS, "To get a list of cameras, type \"cameras\""}, + {EXIT, "To quit, type \"quit\""}, + {PAUSE, "To pause, press enter"} +}; + +/* Finds the instruction that a string calls */ +/* str: the string that calls an instruction */ +/* Returns: instructionType and the instruction's arguments. If the string doesn't match any instruction, returns UNDEFINED and NULL */ +InstructionMap getInstruction(char* str){ + for(int i = 0; i < sizeof(instructionCalls) / sizeof(InstructionMap); i++){ + if(strncmp(instructionCalls[i].args, str, strlen(instructionCalls[i].args)) == 0){ + return (InstructionMap){instructionCalls[i].type, str + strlen(instructionCalls[i].args)}; + } + } + return (InstructionMap){UNDEFINED, NULL}; +} + +void printHelpText(){ + for(int i = 0; i < sizeof(playerInstructionHelp) / sizeof(InstructionMap); i++) + printf("%s\n", playerInstructionHelp[i].args); +} diff --git a/Instructions.h b/Instructions.h new file mode 100644 index 0000000..3eebf5e --- /dev/null +++ b/Instructions.h @@ -0,0 +1,23 @@ +typedef enum InstructionType{ + UNDEFINED, + INSTANT_EVENT, + ONGOING_EVENT_ABSOLUTE, + ONGOING_EVENT_RELATIVE, + WAIT_ABSOLUTE, + WAIT_RELATIVE, + COMMENT, + EXIT, + CHANGE_CAMERA, + LIST_CAMERAS, + PAUSE, + PAUSE_SILENT, + HELP +}InstructionType; + +typedef struct InstructionMap { /* used to map an instruction to a string */ + InstructionType type; + char* args; +}InstructionMap; + +InstructionMap getInstruction(char* str); +void printHelpText(); diff --git a/OldVersion/Cameras/delayTest.txt b/OldVersion/Cameras/delayTest.txt new file mode 100644 index 0000000..089bdbb --- /dev/null +++ b/OldVersion/Cameras/delayTest.txt @@ -0,0 +1,4 @@ +d1] 1 second delay +d10] 10 second delay +d5] Will exit in 5 seconds +_end diff --git a/OldVersion/Cameras/otherCamera.txt b/OldVersion/Cameras/otherCamera.txt new file mode 100644 index 0000000..c13bb3a --- /dev/null +++ b/OldVersion/Cameras/otherCamera.txt @@ -0,0 +1,17 @@ +s27] There is a tired looking man at his desk +d5] There is a man sleeping at his desk +d3] He wakes up +d3] He looks around +d5] He shrugs and twiddles his thumbs +d3] He scratches his head +d3] He closes his eyes +d5] He starts to fall asleep again +d1] He wakes up with a start +d3] Man: Oh! Hello! Welcome to the other camera! +d1] Man: Erm, that's... +d1] Man: Uh... +d3] Man: My teleprompter doesn't say anything else +d3] The man looks somewhere out of the camera's field of view +d3] The man appears to be mouthing words at someone +d3] Man: Erm... TECHNICAL DIFFICULTIES +_end diff --git a/OldVersion/Cameras/start.txt b/OldVersion/Cameras/start.txt new file mode 100644 index 0000000..cc930b4 --- /dev/null +++ b/OldVersion/Cameras/start.txt @@ -0,0 +1,17 @@ +d3] A man walks into view. He is wearing a suit, although it looks a bit too small. +s3] There is a man wearing a suit that's a bit too small for him. +d3] He clears his throat. +d3] He tightens his tie. +d2] He clears his throat again. +d3] Man: Welcome to the text adventure! +d5] Man: To pause the game, press enter. Try it! +d3] Man: This game is all about cameras. +d5] Man: To change cameras, pause the game and type "camera otherCamera" +d4] Man: Go ahead, I'll wait +d4] Oh, Hell. The teleprompter's broken +d3] The man runs to the edge of the camera's view +d2] The man waves, trying to get someone's attention +d3] The man makes difficult-to-interpret hand gestures at the person +d3] The man glares +d3] The man stage whispers: You're fired +_end diff --git a/OldVersion/Cameras/syntax.md b/OldVersion/Cameras/syntax.md new file mode 100644 index 0000000..0b60028 --- /dev/null +++ b/OldVersion/Cameras/syntax.md @@ -0,0 +1,11 @@ +#Camera Syntax +##Events +###Watching Events +To write a normal event, the syntax is "d] " +Where is the string to print and is the delay between that event and the next one +###Switching Events +Switching events are only sent if the player switches to the camera that calls them between the time it is called and the time it is called + the duration it specifies +The syntax is: "s] " +Where is the string to print and is the duration +##Exiting +To automatically exit the game, write "_exit" or "_end" at the end of the files diff --git a/OldVersion/Cameras/test1.txt b/OldVersion/Cameras/test1.txt new file mode 100644 index 0000000..e42152f --- /dev/null +++ b/OldVersion/Cameras/test1.txt @@ -0,0 +1,21 @@ +s10] 1s 0 seconds +d1] 1d 0 seconds +s10] 1s 1 seconds +d1] 1d 1 seconds +s10] 1s 2 seconds +d1] 1d 2 seconds +s10] 1s 3 seconds +d1] 1d 3 seconds +s10] 1s 4 seconds +d1] 1d 4 seconds +s10] 1s 5 seconds +d1] 1d 5 seconds +s10] 1s 6 seconds +d1] 1d 6 seconds +s10] 1s 7 seconds +d1] 1d 7 seconds +s10] 1s 8 seconds +d1] 1d 8 seconds +s10] 1s 9 seconds +d1] 1d 9 seconds +_end diff --git a/OldVersion/Cameras/test2.txt b/OldVersion/Cameras/test2.txt new file mode 100644 index 0000000..a8e3a80 --- /dev/null +++ b/OldVersion/Cameras/test2.txt @@ -0,0 +1,21 @@ +s10] 2s 0 seconds +d1] 2d 0 seconds +s10] 2s 1 seconds +d1] 2d 1 seconds +s10] 2s 2 seconds +d1] 2d 2 seconds +s10] 2s 3 seconds +d1] 2d 3 seconds +s10] 2s 4 seconds +d1] 2d 4 seconds +s10] 2s 5 seconds +d1] 2d 5 seconds +s10] 2s 6 seconds +d1] 2d 6 seconds +s10] 2s 7 seconds +d1] 2d 7 seconds +s10] 2s 8 seconds +d1] 2d 8 seconds +s10] 2s 9 seconds +d1] 2d 9 seconds +_end diff --git a/OldVersion/README.md b/OldVersion/README.md new file mode 100644 index 0000000..80b6989 --- /dev/null +++ b/OldVersion/README.md @@ -0,0 +1,21 @@ +#How to play the game +The game consists of a series of messages that print out at specific times. The player interacts with the game using commands. Although not required, before writing a command, press enter to pause the messages, then write the command, then press enter again to unpause them. The commands are as follows. +### Pausing the game +To pause the game, press enter +### Changing the camera +To change the camera, type "camera " +To get a list of available cameras, type "camera" +### Listing the commands +To get a list of commands, type "help" +### Quitting +To quit, type "quit" +#How to make a game +The game runs using .txt files (which I call cameras, in this context) in the Cameras directory. When it launches, its camera will be start.txt, so that should be written first. There are 3 possible commands for a camera, which are the following. +### Witnessed Events +Witnessed events are events that only print if the player is watching the camera that the event is on when it occurs. The syntax for a witnessed event is `"d] "` where `` is the delay, in seconds, between the event in question and the event following it, and `` is the message to be sent. +### Ongoing Events +Ongoing events are events that only print if the player switches to the camera that the event is on after the event starts and before it stops. The syntax for an ongoing event is `"s] "` where `` is the time, in seconds, between the event starting and the event ending, and `` is the message to be sent +### Automatic exit +To automatically quit the program, put "_end" or "_exit" at the end of the file. +# How to compile it +to compile it, use `gcc textAdventure.c -o textAdventure -lpthread` diff --git a/OldVersion/README_OLD.md b/OldVersion/README_OLD.md new file mode 100644 index 0000000..6ff9dd5 --- /dev/null +++ b/OldVersion/README_OLD.md @@ -0,0 +1,46 @@ +# Final Project + +## Objectives +To review and implement concepts learned from class in a self-designed program. + +### Description +You will design, propose, and implement a project of your own choosing. Your project must implement or include each of the following concepts: + - Variables/data types + - Input/output + - Conditional statements + - Loops + - Functions + - Arrays/strings (either directly or as a pointer) + - Advanced data types (structures and enumerated lists)
+ +If it is appropriate to use a header file and/or an external .c file containing utility functions, you should do so. If you have more than a few functions in your program, this applies to you. + +Your program must be well-commented and provide the user with information on how to use your program. Interaction with the program should be specified within the program as well as within a readme.txt document. Rules for games should also be included in the readme.txt document. +Additionally, your code must be written efficiently and handle invalid user input appropriately. This means that if you have the user enter a number, and the user enters a string or a character, your program should not crash, go into an infinite loop, or produce anything outside of the expected functionality. + +Examples of projects include (but are not limited to): game simulators (board games, battle arena, other games), text adventure games, artificial intelligence applications, etc. + +Note: There may be functionality you wish to include in your project that we have not gone over yet in class. You can check with your instructor (me) or your TA (Lesley) to see if we intend to go over it or if it is possible. You may wish to temporarily hardcode data, functionality, etc. until we go over it. Your final code for those sections should not be hardcoded. + +### Part 1: Proposal +You must submit a proposal that details the following: + - Descriptive overview of project (what it does, what game it implements/simulates, etc). This should be long enough to explain what your program is and what it does/does not do. + - Detailed examples of concept implementation (an example each of how you will use functions, loops, etc.). You do not need to explain how you will use variables or input/output unless it is not inherently obvious. + - Your reasons for picking this project (you are interested in game design and wanted to create a game, you think the application is interesting and why, etc.). + - Any external libraries you are considering using and what you will use them for. Keep in mind that most of your code should be your own, and we cannot provide any help for external libraries. This includes graphics libraries. You are responsible for learning and figuring them out on your own. Also detail any code you will use that is not yours. + +### Part 2: Project Implementation +You must implement the project as described in your proposal and conforming to the expectations in the Description section. + +Functions and large code blocks should be documented (have comments briefly explaining their purpose, as well as any parameters or return values, if applicable). + +You must include a readme.txt detailing how to run your project, a brief overview of what it does, and a brief explanation of interaction with the program (e.g. “You may enter commands at the >> prompt. For help/suggestions of commands to enter at any time, type ‘help’.” for a text adventure game). If your project is a game or game simulator, you should also include any rules as applicable (e.g. “Go Fish is a game of matching cards. If you suggest a card your opponent has, he/she must give you that card. Likewise, if the opponent asks for a card you have, you must give him/her that card. If no card matches, player draws from the pile. Otherwise, players continue asking for cards until they ask for a card no one has.”). + +Your readme.txt should also detail any changes made that do not follow your original proposal and explain why they differ. + + +### Deliverables +Your proposal should be submitted by 10am on Monday, July 11, 2016. It will either be approved or modification requested by Monday night. Note that if you submit your proposal early, it will likely be evaluated early, and you will be able to begin work on your project as soon as it is approved. Your proposal should be in a .doc, .pdf, or .txt document. + +Your project is due Friday, July 15, 2016 at 4pm. Please submit ALL files (source code, external libraries, data files, and executable). + diff --git a/OldVersion/textAdventure b/OldVersion/textAdventure new file mode 100755 index 0000000..ca4b24f Binary files /dev/null and b/OldVersion/textAdventure differ diff --git a/OldVersion/textAdventure.c b/OldVersion/textAdventure.c new file mode 100644 index 0000000..5b2168c --- /dev/null +++ b/OldVersion/textAdventure.c @@ -0,0 +1,172 @@ +#include +#include +#include +#include +#include +/* Have to use #define because using a const throws an error about variables +being used in array initializers.*/ +#define MAX_MESSAGE_LENGTH 256 + +struct threadVars{ /* struct because I can only pass one argument to the threads */ + unsigned int* gameTime; /* Time travelers will (hopefully) never try to run this code before 1970 */ + FILE** finptr; /* double pointer because inputThread might change the file */ + int* paused; + unsigned int* timeDelay; +}; + +/* Prevents the program from continuing for a certain amount of seconds */ +/* seconds: the amount of seconds to wait */ +void delay(unsigned int seconds){ + unsigned int start = time(0); + while(time(0) - start < seconds)/*printf("%ld\b", time(0) - start)*/; +} + +/* Reads the next line in the stream of events */ +/* fin: the stream of events to read from */ +/* gameTime: the time, in seconds, since the program started (not including pause time) */ +/* timeDelay: the delay, in seconds, between the previous event and the current event */ +/* returns 1 if the game should continue, or 0 if the game is over */ +int readNextLine(FILE* fin, unsigned int* gameTime, unsigned int* timeDelay){ + *gameTime += *timeDelay; /* add the previous message's delay to the game's time */ + char input[MAX_MESSAGE_LENGTH]; + int stringIndex = 0; + fgets(input, MAX_MESSAGE_LENGTH, fin); + if(sscanf(input, "d%u] %n", timeDelay, &stringIndex)){ + printf("%s", input + stringIndex); + delay(*timeDelay); + }else if(sscanf(input, "s%u] ", timeDelay)){ + /* if it's an ongoing event, it should not have a delay */ + *timeDelay = 0; + }else if(strstr(input, "_end") != NULL || strstr(input, "_exit") != NULL){ + return 0; + } + return 1; +} + +void* outputThread(void* arg){ + struct threadVars* vars = arg; + unsigned int* gameTime = vars->gameTime; + FILE** finptr = vars->finptr; + /* store this as a pointer because it might get changed by the other thread */ + int* paused = vars->paused; + /* declare timeDelay here because readNextLine needs to access the previous line's timeDelay */ + int* timeDelay = vars->timeDelay; + /* if paused is true, then it won't even bother checking the other side of + the || so readNextLine will never be executed. */ + while(*paused || readNextLine(*finptr, gameTime, timeDelay)); + /* if the code reaches this point, it's time to exit! */ + printf("The end! Feel free to play again using a different camera! Exiting...\n"); + exit(0); +} + +/* If there exists a file named "Cameras/.txt", will switch fin to that, +move the stream to the first message that comes chronologically after +previousMessageTime */ +/* name: the name of the camera in question */ +/* gameTime: the time, in seconds, since the program started (not including pause time) */ +/* finptr: a pointer to the file stream in question */ +/* returns 1 if the file exists, or 0 if it does not */ +int switchCamera(char* name, unsigned int gameTime, FILE** finptr, int* timeDelay){ + char path[50]; + sprintf(path, "./Cameras/%s.txt", name); + FILE* open = fopen(path, "r"); + if(open == NULL) return 0; + fclose(*finptr); /* close the currently open file to prevent memory leaks */ + *finptr = open; + unsigned int skipTime = 0; + *timeDelay = 0; /* reset the timeDelay so the time doesn't advance when it shouldn't */ + char nextLine[MAX_MESSAGE_LENGTH]; + /* loops until the stream is right before the first message that should be printed at or after the gameTime */ + while(skipTime < gameTime && fgets(nextLine, MAX_MESSAGE_LENGTH, *finptr)){ + int lineDelay, stringIndex; + char eventType; + + //printf("%d\n", sscanf(nextLine, "%c%d] %n", &eventType, &lineDelay, &stringIndex)); + if(sscanf(nextLine, "%c%d] %n", &eventType, timeDelay, &stringIndex) >= 2){ + switch(eventType){ + /* if it starts with a d, it is an instant event, and because it happened in the past, + the message shouldn't print because the player didn't witness it */ + case 'd': + skipTime += *timeDelay; + + break; + /* if it starts with a d, it is an ongoing event, and although the player didn't + witness it starting, they still see it before it's over, so it should print */ + case 's': + if(skipTime + *timeDelay >= gameTime) + printf("%s", nextLine + stringIndex); + *timeDelay = 0; + break; + } + }else if(strstr(nextLine, "_end") != NULL || strstr(nextLine, "_exit") != NULL){ + printf("%u %u %s\n", gameTime, skipTime, nextLine); + printf("Camera has already ended. Quitting\n"); + exit(0); + } + } + return 1; +} + +/* identifies the command that the player has input and executes it.*/ +/* command: the command in question */ +/* gameTime: the time, in seconds, since the program started (not including pause time) */ +/* finptr: a pointer to the event stream that might be changed by a command */ +/* paused: boolean value representing whether or not the output is paused */ +void handlePlayerCommand(char* command, unsigned int* gameTime, FILE** finptr, int* paused, unsigned int* timeDelay){ + /* use strcmp here because the string should consist solely of '\n' */ + if(strcmp(command, "\n") == 0){ + *paused = !*paused; + if(*paused) + printf("Game is paused. To unpause, press enter\n"); + }else if(strstr(command, "help") != NULL){ + printf("To switch cameras, type \"camera\"\n\ + To quit, type \"quit\"\n"); + }else if(strstr(command, "camera") != NULL){ + char arg[25]; + if(sscanf(command, "camera %s", arg)){ + /* dereference gameTime because there's no reason to expect that it would change during the execution of switchCamera */ + if(switchCamera(arg, *gameTime, finptr, timeDelay)) return; + /* if no camera is specified or if it is not a valid camera, print out a list of valid cameras + the list is hardcoded because there is no platform independent way to list files as far as I know */ + printf("The cameras are: start, otherCamera\n"); + } + }else if(strstr(command, "quit") != NULL){ + exit(0); + }else{ + printf("Command not recognised. Type \"help\" for a list of commands\n"); + } +} + +/* Waits for player input and processes it */ +void* inputThread(void* arg){ + struct threadVars* vars = arg; + unsigned int* gameTime = vars->gameTime; + FILE** finptr = vars->finptr; + int* paused = vars->paused; + unsigned int* timeDelay = vars->timeDelay; + + int inputLength = 100; + char input[inputLength]; + while(1) + handlePlayerCommand(fgets(input, inputLength, stdin), gameTime, finptr, paused, timeDelay); +} + +int main(){ + int gameTime = 0; + FILE* fin = fopen("./Cameras/start.txt", "r"); + int paused = 0; + int timeDelay = 0; + struct threadVars vars = {&gameTime, &fin, &paused, &timeDelay}; + /* declare threads */ + pthread_t outpThread; + pthread_t inpThread; + /* create threads */ + pthread_create(&outpThread, NULL, outputThread, &vars); + pthread_create(&inpThread, NULL, inputThread, &vars); + /* link the threads to their return values(?) */ + pthread_join(outpThread, NULL); + pthread_join(inpThread, NULL); + fclose(fin); + return 0; +} +//FILE* fin = fopen("./Cameras/exampleCam.txt", "r"); diff --git a/OldVersion/thread.c b/OldVersion/thread.c new file mode 100644 index 0000000..2c876b8 --- /dev/null +++ b/OldVersion/thread.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int keepSayingHi = 1; +void* thread1(){ + int start = time(0); + while(keepSayingHi){ + if(time(0) - start >= 1){ + printf("hi\n"); + start = time(0); + } + } +} + +void* thread2(){ + int num; + scanf("Exit %d", &num); + printf("Exiting\n"); + keepSayingHi = 0; +} + +int main(){ + pthread_t tid1, tid2; + pthread_create(&tid1, NULL, thread1, NULL); + pthread_create(&tid2, NULL, thread2, NULL); + pthread_join(tid1, NULL); + pthread_join(tid2, NULL); +} diff --git a/README.md b/README.md index 6ff9dd5..663db16 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,47 @@ -# Final Project - -## Objectives -To review and implement concepts learned from class in a self-designed program. - -### Description -You will design, propose, and implement a project of your own choosing. Your project must implement or include each of the following concepts: - - Variables/data types - - Input/output - - Conditional statements - - Loops - - Functions - - Arrays/strings (either directly or as a pointer) - - Advanced data types (structures and enumerated lists)
- -If it is appropriate to use a header file and/or an external .c file containing utility functions, you should do so. If you have more than a few functions in your program, this applies to you. - -Your program must be well-commented and provide the user with information on how to use your program. Interaction with the program should be specified within the program as well as within a readme.txt document. Rules for games should also be included in the readme.txt document. -Additionally, your code must be written efficiently and handle invalid user input appropriately. This means that if you have the user enter a number, and the user enters a string or a character, your program should not crash, go into an infinite loop, or produce anything outside of the expected functionality. - -Examples of projects include (but are not limited to): game simulators (board games, battle arena, other games), text adventure games, artificial intelligence applications, etc. - -Note: There may be functionality you wish to include in your project that we have not gone over yet in class. You can check with your instructor (me) or your TA (Lesley) to see if we intend to go over it or if it is possible. You may wish to temporarily hardcode data, functionality, etc. until we go over it. Your final code for those sections should not be hardcoded. - -### Part 1: Proposal -You must submit a proposal that details the following: - - Descriptive overview of project (what it does, what game it implements/simulates, etc). This should be long enough to explain what your program is and what it does/does not do. - - Detailed examples of concept implementation (an example each of how you will use functions, loops, etc.). You do not need to explain how you will use variables or input/output unless it is not inherently obvious. - - Your reasons for picking this project (you are interested in game design and wanted to create a game, you think the application is interesting and why, etc.). - - Any external libraries you are considering using and what you will use them for. Keep in mind that most of your code should be your own, and we cannot provide any help for external libraries. This includes graphics libraries. You are responsible for learning and figuring them out on your own. Also detail any code you will use that is not yours. - -### Part 2: Project Implementation -You must implement the project as described in your proposal and conforming to the expectations in the Description section. - -Functions and large code blocks should be documented (have comments briefly explaining their purpose, as well as any parameters or return values, if applicable). - -You must include a readme.txt detailing how to run your project, a brief overview of what it does, and a brief explanation of interaction with the program (e.g. “You may enter commands at the >> prompt. For help/suggestions of commands to enter at any time, type ‘help’.” for a text adventure game). If your project is a game or game simulator, you should also include any rules as applicable (e.g. “Go Fish is a game of matching cards. If you suggest a card your opponent has, he/she must give you that card. Likewise, if the opponent asks for a card you have, you must give him/her that card. If no card matches, player draws from the pile. Otherwise, players continue asking for cards until they ask for a card no one has.”). - -Your readme.txt should also detail any changes made that do not follow your original proposal and explain why they differ. - - -### Deliverables -Your proposal should be submitted by 10am on Monday, July 11, 2016. It will either be approved or modification requested by Monday night. Note that if you submit your proposal early, it will likely be evaluated early, and you will be able to begin work on your project as soon as it is approved. Your proposal should be in a .doc, .pdf, or .txt document. - -Your project is due Friday, July 15, 2016 at 4pm. Please submit ALL files (source code, external libraries, data files, and executable). - +Hello! This is my final project. +If you plan on writing a game in this, you should definitely read the "issues" section on the bottom of this readme +#Playing a game +The game consists of a series of messages that print out at specific times. The messages change depending on which "camera" the user is looking through. To start the game with the default camera, launch the game normally. To start the game with a different camera, launch the game with the camera's name as an argument. +##Commands +The player interacts with the game using commands. Although not required, before writing a command, press enter to pause the messages, then write the command, then press enter again to unpause them. The commands are as follows. +### Pausing the game +To pause the game, press enter +### Changing the camera +To change the camera, type `"camera "` +To get a list of available cameras, type "cameras" +### Listing the commands +To get a list of commands, type "help" +### Quitting +To quit, type "quit" +# Writing a game! +## Events! +### Instant Events + To print a line of text to the screen, use an instant event. It will only print if the player is using the camera that the event is declared on when it is scheduled to print + to write an instant event, use `i ` +### Ongoing Events + Ongoing events are events that are carried out over time. They will only print if the player switches to the camera that they are declared on after they are scheduled to start and before they are scheduled to end. + + There are two different ways to specify the duration of the event. The first is telling it the time that it will end. + To do so, use `oa