From 23deb8c77fabbc290a68648aff2f66881caf5e84 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:09:33 +0100 Subject: [PATCH 01/51] initial commit --- build-project.sh | 0 src/c/main.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) mode change 100644 => 100755 build-project.sh create mode 100644 src/c/main.c diff --git a/build-project.sh b/build-project.sh old mode 100644 new mode 100755 diff --git a/src/c/main.c b/src/c/main.c new file mode 100644 index 0000000..9448ed1 --- /dev/null +++ b/src/c/main.c @@ -0,0 +1,27 @@ +//BIBs +#include +#include +#include + +bool gameRunning; + +int main() +{ + //define variables + char userInput[20]; //maximum defined user input length + gameRunning = 1; + + while (gameRunning == 1) //while running + { + // User Input + printf("User Input:"); + scanf(" %s", userInput); + printf("\n"); + + //NEXT STEP: + //Processing + //processInput(userInput); + } + + return 0; +}; \ No newline at end of file From ec70016bf9ac1ccbd20ea46cbd97bd7e5aa5cdf8 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:12:00 +0100 Subject: [PATCH 02/51] added rules and instructions --- src/content/game_instructions.txt | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/content/game_instructions.txt diff --git a/src/content/game_instructions.txt b/src/content/game_instructions.txt new file mode 100644 index 0000000..bfd0945 --- /dev/null +++ b/src/content/game_instructions.txt @@ -0,0 +1,36 @@ + + +************************************************************************************************************ + _____ __ __ ______ _____ _______ _____ _______ + / ____| /\ | \/ | ____| / ____|__ __|/\ | __ \__ __| + | | __ / \ | \ / | |__ | (___ | | / \ | |__) | | | + | | |_ | / /\ \ | |\/| | __| \___ \ | | / /\ \ | _ / | | + | |__| |/ ____ \| | | | |____ ____) | | |/ ____ \| | \ \ | | + \_____/_/ \_\_| |_|______| |_____/ |_/_/ \_\_| \_\ |_| + +************************************************************************************************************ + + + | | /| / /__ / /______ __ _ ___ / /____ / |/ / _ | / |/ / __/ + | |/ |/ / -_) / __/ _ \/ ' \/ -_) / __/ _ \ / / __ |/ /|_/ / _/ + |__/|__/\__/_/\__/\___/_/_/_/\__/ \__/\___/ /_/|_/_/ |_/_/ /_/___/ + + +///////////////////////////////////////////////////////////////////////////////////////////// + +INSTRUCTIONS: + +***** + + + + +Have fun! + +///////////////////////////////////////////////////////////////////////////////////////////// + + +************************************************************************************************************ + + +did you read our rules and instructions? Yes(y) or No(n) From a803b2d87911a9168f4d420ee2ef41beb0f34fae Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:13:57 +0100 Subject: [PATCH 03/51] added function for user to accept instructions --- src/c/main.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index 9448ed1..b0df59e 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -1,27 +1,89 @@ -//BIBs +// BIBs #include #include #include +#include bool gameRunning; +bool acceptedRules; + +// content +char *gameInstructionsFile = "../../src/content/game_instructions.txt"; + +// function declarations +void printInit(); int main() { - //define variables - char userInput[20]; //maximum defined user input length - gameRunning = 1; + // define variables + char userInput[20]; // maximum defined user input length + gameRunning = 1; + + // init and instructions + printInit(); - while (gameRunning == 1) //while running + if (acceptedRules == 1) { - // User Input - printf("User Input:"); - scanf(" %s", userInput); - printf("\n"); - - //NEXT STEP: - //Processing - //processInput(userInput); - } + while (gameRunning == 1) // while running + { + // User Input + printf("User Input:"); + scanf(" %s", userInput); + printf("\n"); + // NEXT STEP: + // Processing + // processInput(userInput); + } + } return 0; +}; + +// init dialogue +void printInit() +{ + FILE *stream; + char *line = NULL; + size_t len = 0; + ssize_t read; + + stream = fopen(gameInstructionsFile, "r"); + if (stream == NULL) + { + printf("ERROR: couldn't open or find file: INSTRUCTIONS !\n"); + exit(EXIT_FAILURE); // exit + } + + /* print line by line from file */ + while ((read = getline(&line, &len, stream)) != -1) + { + // printf("Retrieved line of length %u :\n", read); + printf("%s", line); + } + + free(line); /* Deallocate allocated memory */ + fclose(stream); /* closing file */ + + char userInput[1]; + bool inputState = 0; + int acceptCounter = 0; + while (inputState == 0) + { + scanf(" %c", userInput); + if (strcasecmp(userInput, "y") == 0) + { + acceptedRules = 1; + inputState = 1; //break while + } + else if (strcasecmp(userInput, "n") == 0) + { + printf("You didn't read our rules & instructions. The game will close now. \n\n"); + acceptedRules = 0; + inputState = 1; //break while + } + else + { + printf("Invalid Input!\n"); + } + } }; \ No newline at end of file From 48b661ef17844be58815b5aa8ce26d0b473b2610 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:15:45 +0100 Subject: [PATCH 04/51] refactoring: function for accept rules --- src/c/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index b0df59e..ecf1c18 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -12,6 +12,7 @@ char *gameInstructionsFile = "../../src/content/game_instructions.txt"; // function declarations void printInit(); +void acceptInstructions(); int main() { @@ -37,7 +38,7 @@ int main() } } return 0; -}; +} // init dialogue void printInit() @@ -64,6 +65,12 @@ void printInit() free(line); /* Deallocate allocated memory */ fclose(stream); /* closing file */ + acceptInstructions(); +} + +//accept rules and instructions for init dialogue +void acceptInstructions() +{ char userInput[1]; bool inputState = 0; int acceptCounter = 0; @@ -86,4 +93,4 @@ void printInit() printf("Invalid Input!\n"); } } -}; \ No newline at end of file +} \ No newline at end of file From c506575b0dd3c52587c379595b312ce3d5ef8c91 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:17:00 +0100 Subject: [PATCH 05/51] added function processInput and exit of game --- src/c/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/c/main.c b/src/c/main.c index ecf1c18..ecaa444 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -13,6 +13,7 @@ char *gameInstructionsFile = "../../src/content/game_instructions.txt"; // function declarations void printInit(); void acceptInstructions(); +void processInput(); int main() { @@ -34,7 +35,7 @@ int main() // NEXT STEP: // Processing - // processInput(userInput); + processInput(userInput); } } return 0; @@ -93,4 +94,18 @@ void acceptInstructions() printf("Invalid Input!\n"); } } +} + +//process user input +void processInput(char userInput[20]) +{ + if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) + { + gameRunning = 0; + printf("!GAME EXIT!\n"); + } + else + { + printf("Wrong Input!\n"); + } } \ No newline at end of file From fcda168e36e237863fdb421c5d09f858d38c65bb Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:18:27 +0100 Subject: [PATCH 06/51] refactoring: added checkExit function for clarity --- src/c/main.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index ecaa444..fca1071 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -14,6 +14,7 @@ char *gameInstructionsFile = "../../src/content/game_instructions.txt"; void printInit(); void acceptInstructions(); void processInput(); +int checkExit(); int main() { @@ -69,7 +70,7 @@ void printInit() acceptInstructions(); } -//accept rules and instructions for init dialogue +// accept rules and instructions for init dialogue void acceptInstructions() { char userInput[1]; @@ -81,13 +82,13 @@ void acceptInstructions() if (strcasecmp(userInput, "y") == 0) { acceptedRules = 1; - inputState = 1; //break while + inputState = 1; // break while } else if (strcasecmp(userInput, "n") == 0) { printf("You didn't read our rules & instructions. The game will close now. \n\n"); acceptedRules = 0; - inputState = 1; //break while + inputState = 1; // break while } else { @@ -96,10 +97,10 @@ void acceptInstructions() } } -//process user input +// process user input void processInput(char userInput[20]) { - if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) + if (checkExit(userInput) == 1) { gameRunning = 0; printf("!GAME EXIT!\n"); @@ -108,4 +109,15 @@ void processInput(char userInput[20]) { printf("Wrong Input!\n"); } +} + +//function for checking user input of exit +int checkExit(char userInput[20]) +{ + if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) + { + return 1; + } + + return 0; } \ No newline at end of file From 3267de4fe466f925c8f36f2cc5a92e37ca4d568a Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:19:00 +0100 Subject: [PATCH 07/51] added game.map file --- src/content/game.map | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/content/game.map diff --git a/src/content/game.map b/src/content/game.map new file mode 100644 index 0000000..96a4241 --- /dev/null +++ b/src/content/game.map @@ -0,0 +1,6 @@ +# LINES WITH '#' AT BEGINNING GET IGNORED +#ID;NAME ORT;MSG;successor;predeacessor;items(comma seperated);shop available (1=y,0=n); +0;office;welcome to office;1;-1;1,2;0 +1;hospital;welcome to the hospital;2;0;3;0 +2;fire department;welcome to fire department;3;1;4;1 +3;police station;welcome to police;4;2;5,6;0 \ No newline at end of file From d73a90e6b0dbe350f035e68e2c4fe2925bed36c8 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:20:57 +0100 Subject: [PATCH 08/51] added nav_helper with test --- src/c/nav_helper.c | 12 ++++++++++++ src/c/nav_helper.h | 9 +++++++++ test/c/test_nav_helper.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/c/nav_helper.c create mode 100644 src/c/nav_helper.h create mode 100644 test/c/test_nav_helper.c diff --git a/src/c/nav_helper.c b/src/c/nav_helper.c new file mode 100644 index 0000000..e36961d --- /dev/null +++ b/src/c/nav_helper.c @@ -0,0 +1,12 @@ +//bibs +#include + +//headers +#include "nav_helper.h" + +bool startsWith(const char *a, const char *b) +{ + if (strncmp(a, b, strlen(b)) == 0) + return 1; + return 0; +}; \ No newline at end of file diff --git a/src/c/nav_helper.h b/src/c/nav_helper.h new file mode 100644 index 0000000..9e513d2 --- /dev/null +++ b/src/c/nav_helper.h @@ -0,0 +1,9 @@ +#ifndef NAV_HELPER_H +#define NAV_HELPER_H + +#include +#include + +bool startsWith(const char *a, const char *b); + +#endif \ No newline at end of file diff --git a/test/c/test_nav_helper.c b/test/c/test_nav_helper.c new file mode 100644 index 0000000..cbf1d42 --- /dev/null +++ b/test/c/test_nav_helper.c @@ -0,0 +1,36 @@ +#ifdef TEST + +#include "unity.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_nav_helper(void) +{ + /* arrange */ + // Hier die Werte eingeben + char* stringToCheckIsTrue = "#test"; + char* stringToCheckIsFalse = "test"; + + /* act */ + // Die Funktion wird ausgeführt + bool valueIsTrue = startsWith(stringToCheckIsTrue,"#"); + bool valueIsFalse = startsWith(stringToCheckIsFalse, "#"); + + //Output + printf("%s startet mit '#' = %d\n",stringToCheckIsTrue, valueIsTrue); + printf("%s startet mit '#' = %d",stringToCheckIsFalse, valueIsFalse); + + /* assert */ + // Vergleichen mit Inhalt + TEST_ASSERT_TRUE(valueIsTrue); + TEST_ASSERT_FALSE(valueIsFalse); +} + +#endif // TEST \ No newline at end of file From f0bf30dc0f58cae7699e58dff3d0b2718e0ff8ec Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:21:46 +0100 Subject: [PATCH 09/51] added map with test --- src/c/map.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/c/map.h | 29 +++++++++++++++++++++++ test/c/test_map.c | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 src/c/map.c create mode 100644 src/c/map.h create mode 100644 test/c/test_map.c diff --git a/src/c/map.c b/src/c/map.c new file mode 100644 index 0000000..83c3cdc --- /dev/null +++ b/src/c/map.c @@ -0,0 +1,60 @@ +//headers +#include "map.h" + +Room *getMap(char *gameMapFile) +{ + static Room fillMap[mapMax]; + + FILE *stream; + char *line = NULL; + size_t len = 0; + ssize_t read; + + stream = fopen(gameMapFile, "r"); + if (stream == NULL) + { + printf("ERROR: couldn't open or find file: MAP!\n"); + exit(EXIT_FAILURE); // exit + } + + char delimiter[] = ";"; + + /* print line by line from file */ + int lineCounter = 0; + while ((read = getline(&line, &len, stream)) != -1) + { + + // printf("Retrieved line of length %u :\n", read); + if (startsWith(line, "#") == 0) + { + char *arr[roomAttributesMax]; + char *token = strtok(line, delimiter); + int countToken = 0; + while (token != NULL) + { + arr[countToken] = token; + token = strtok(NULL, ";"); + + countToken += 1; + } + free(token); + + Room r; + r.id = atoi(arr[0]); + strcpy(r.nameRoom, arr[1]); + strcpy(r.msgRoom, arr[2]); + r.successor = atoi(arr[3]); + r.predecessor = atoi(arr[4]); + memcpy(r.items, arr[5], sizeof arr[5]); + r.shopAvailable = atoi(arr[6]); + + fillMap[lineCounter] = r; + lineCounter += 1; + } + } + + free(line); /* Deallocate allocated memory */ + fclose(stream); /* closing file */ + + return fillMap; +}; \ No newline at end of file diff --git a/src/c/map.h b/src/c/map.h new file mode 100644 index 0000000..dd31690 --- /dev/null +++ b/src/c/map.h @@ -0,0 +1,29 @@ +#ifndef MAP_H +#define MAP_H + +//bibs +#include +#include +#include +#include + +#include "nav_helper.h" + +//defs +#define mapMax 4 // for map (adjust to txt count of rooms -> game.map) +#define roomAttributesMax 7 // for room struct (adjust to txt count of room-attributes -> game.map) + +typedef struct Room +{ + int id; + char nameRoom[20]; + char msgRoom[150]; + int successor; + int predecessor; + char items[10]; + bool shopAvailable; +} Room; + +Room *getMap(char *gameMapFile); + +#endif // MAP_H \ No newline at end of file diff --git a/test/c/test_map.c b/test/c/test_map.c new file mode 100644 index 0000000..dcda939 --- /dev/null +++ b/test/c/test_map.c @@ -0,0 +1,44 @@ +#ifdef TEST + +#include "unity.h" +#include "map.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_map(void) +{ + /* arrange */ + // Hier die Werte eingeben + Room* map; + + /* act */ + // Die Funktion wird ausgeführt + map = getMap("./src/content/game.map"); + + for(int i=0; i<4;i++){ + printf("%s\n", map[i].nameRoom); + } + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + int officeExpectedSuccessor = 1; + int officeExpectedID = 0; + + int fdExpectedSuccessor = 3; + int fdExpectedID = 2; + + TEST_ASSERT_EQUAL_INT(officeExpectedSuccessor, map[0].successor); + TEST_ASSERT_EQUAL_INT(officeExpectedID, map[0].id); + + TEST_ASSERT_EQUAL_INT(fdExpectedSuccessor, map[2].successor); + TEST_ASSERT_EQUAL_INT(fdExpectedID, map[2].id); +} + +#endif // TEST From 225282840f79b5f706f3fb14020f41aef9d51eb9 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:23:53 +0100 Subject: [PATCH 10/51] added map into main of game --- src/c/main.c | 291 +++++++++++++++++++++++++++++---------------------- 1 file changed, 168 insertions(+), 123 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index fca1071..93be7c7 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -1,123 +1,168 @@ -// BIBs -#include -#include -#include -#include - -bool gameRunning; -bool acceptedRules; - -// content -char *gameInstructionsFile = "../../src/content/game_instructions.txt"; - -// function declarations -void printInit(); -void acceptInstructions(); -void processInput(); -int checkExit(); - -int main() -{ - // define variables - char userInput[20]; // maximum defined user input length - gameRunning = 1; - - // init and instructions - printInit(); - - if (acceptedRules == 1) - { - while (gameRunning == 1) // while running - { - // User Input - printf("User Input:"); - scanf(" %s", userInput); - printf("\n"); - - // NEXT STEP: - // Processing - processInput(userInput); - } - } - return 0; -} - -// init dialogue -void printInit() -{ - FILE *stream; - char *line = NULL; - size_t len = 0; - ssize_t read; - - stream = fopen(gameInstructionsFile, "r"); - if (stream == NULL) - { - printf("ERROR: couldn't open or find file: INSTRUCTIONS !\n"); - exit(EXIT_FAILURE); // exit - } - - /* print line by line from file */ - while ((read = getline(&line, &len, stream)) != -1) - { - // printf("Retrieved line of length %u :\n", read); - printf("%s", line); - } - - free(line); /* Deallocate allocated memory */ - fclose(stream); /* closing file */ - - acceptInstructions(); -} - -// accept rules and instructions for init dialogue -void acceptInstructions() -{ - char userInput[1]; - bool inputState = 0; - int acceptCounter = 0; - while (inputState == 0) - { - scanf(" %c", userInput); - if (strcasecmp(userInput, "y") == 0) - { - acceptedRules = 1; - inputState = 1; // break while - } - else if (strcasecmp(userInput, "n") == 0) - { - printf("You didn't read our rules & instructions. The game will close now. \n\n"); - acceptedRules = 0; - inputState = 1; // break while - } - else - { - printf("Invalid Input!\n"); - } - } -} - -// process user input -void processInput(char userInput[20]) -{ - if (checkExit(userInput) == 1) - { - gameRunning = 0; - printf("!GAME EXIT!\n"); - } - else - { - printf("Wrong Input!\n"); - } -} - -//function for checking user input of exit -int checkExit(char userInput[20]) -{ - if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) - { - return 1; - } - - return 0; -} \ No newline at end of file +// BIBs +#include +#include +#include +#include + +#include "map.h" +#include "nav_helper.h" + +bool gameRunning; +bool acceptedRules; + +//declare needed variables +Room *map; + +// content +char *gameInstructionsFile = "../../src/content/game_instructions.txt"; +char *gameMapFile = "../../src/content/game.map"; + +//navigation +int playerPosition = 0; +int lastPlayerPosition = 0; + + +// function declarations +void printInit(); +void acceptInstructions(); +void processInput(); +int checkExit(); + + +int main() +{ + // define variables + char userInput[20]; // maximum defined user input length + gameRunning = 1; + + // init and instructions + printInit(); + + //get Content + map = getMap(gameMapFile); + + if (acceptedRules == 1) + { + while (gameRunning == 1) // while running + { + // User Input + printf("User Input:"); + scanf(" %s", userInput); + printf("\n"); + + // NEXT STEP: + // Processing + processInput(userInput); + } + } + return 0; +} + + +// init dialogue +void printInit() +{ + FILE *stream; + char *line = NULL; + size_t len = 0; + ssize_t read; + + stream = fopen(gameInstructionsFile, "r"); + if (stream == NULL) + { + printf("ERROR: couldn't open or find file: INSTRUCTIONS !\n"); + exit(EXIT_FAILURE); // exit + } + + /* print line by line from file */ + while ((read = getline(&line, &len, stream)) != -1) + { + // printf("Retrieved line of length %u :\n", read); + printf("%s", line); + } + + free(line); /* Deallocate allocated memory */ + fclose(stream); /* closing file */ + + acceptInstructions(); +} + +// accept rules and instructions for init dialogue +void acceptInstructions() +{ + char userInput[1]; + bool inputState = 0; + int acceptCounter = 0; + while (inputState == 0) + { + scanf(" %c", userInput); + if (strcasecmp(userInput, "y") == 0) + { + acceptedRules = 1; + inputState = 1; // break while + } + else if (strcasecmp(userInput, "n") == 0) + { + printf("You didn't read our rules & instructions. The game will close now. \n\n"); + acceptedRules = 0; + inputState = 1; // break while + } + else + { + printf("Invalid Input!\n"); + } + } +} + +// process user input +void processInput(char userInput[20]) +{ + Room r = map[playerPosition]; + if (checkExit(userInput) == 1) + { + gameRunning = 0; + printf("!GAME EXIT!\n"); + } + else if (strcmp(userInput, "north") == 0) + { + printf("->N\n"); + lastPlayerPosition = playerPosition; + if (playerPosition == (int)(mapMax - 1)) + { + printf("You have reached the border. You have to go in the other direction!\n"); + } + else + { + playerPosition = r.successor; + } + } + else if (strcmp(userInput, "south") == 0) + { + printf("->S\n"); + lastPlayerPosition = playerPosition; + if (playerPosition > 0) + { + playerPosition = r.predecessor; + } + else + { + printf("You have reached the border. You have to go in the other direction!\n"); + } + } + else + { + printf("Wrong Input!\n"); + } +} + +//function for checking user input of exit +int checkExit(char userInput[20]) +{ + if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) + { + return 1; + } + + return 0; +} + From 247bff96b6a860204b2d32b2523cd8dbe6710038 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:25:34 +0100 Subject: [PATCH 11/51] refactoring: added function checkMove for clarity --- src/c/main.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index 93be7c7..e6c8b83 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -10,24 +10,23 @@ bool gameRunning; bool acceptedRules; -//declare needed variables +// declare needed variables Room *map; // content char *gameInstructionsFile = "../../src/content/game_instructions.txt"; char *gameMapFile = "../../src/content/game.map"; -//navigation +// navigation int playerPosition = 0; int lastPlayerPosition = 0; - // function declarations void printInit(); void acceptInstructions(); void processInput(); int checkExit(); - +int checkMove(); int main() { @@ -38,7 +37,7 @@ int main() // init and instructions printInit(); - //get Content + // get Content map = getMap(gameMapFile); if (acceptedRules == 1) @@ -58,7 +57,6 @@ int main() return 0; } - // init dialogue void printInit() { @@ -117,13 +115,34 @@ void acceptInstructions() // process user input void processInput(char userInput[20]) { - Room r = map[playerPosition]; if (checkExit(userInput) == 1) { gameRunning = 0; printf("!GAME EXIT!\n"); } - else if (strcmp(userInput, "north") == 0) + else if (checkMove(userInput) == 1) + { + printf("Wrong Input!\n"); + } +} + +// function for checking user input of exit +int checkExit(char userInput[20]) +{ + if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) + { + return 1; + } + + return 0; +} + +int checkMove(char userInput[20]) +{ + + Room r = map[playerPosition]; + + if (strcmp(userInput, "north") == 0) { printf("->N\n"); lastPlayerPosition = playerPosition; @@ -135,6 +154,8 @@ void processInput(char userInput[20]) { playerPosition = r.successor; } + + return 0; } else if (strcmp(userInput, "south") == 0) { @@ -148,21 +169,11 @@ void processInput(char userInput[20]) { printf("You have reached the border. You have to go in the other direction!\n"); } + + return 0; } else - { - printf("Wrong Input!\n"); - } -} - -//function for checking user input of exit -int checkExit(char userInput[20]) -{ - if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) { return 1; } - - return 0; } - From d05c4da6c98eecdeea30d0dfbcd16df24241f552 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:27:59 +0100 Subject: [PATCH 12/51] added func printStatus for better overview in game --- src/c/main.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/c/main.c b/src/c/main.c index e6c8b83..3499360 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -12,6 +12,7 @@ bool acceptedRules; // declare needed variables Room *map; +int inputCounter = 0; // content char *gameInstructionsFile = "../../src/content/game_instructions.txt"; @@ -27,6 +28,7 @@ void acceptInstructions(); void processInput(); int checkExit(); int checkMove(); +void printStatus(); int main() { @@ -44,8 +46,10 @@ int main() { while (gameRunning == 1) // while running { + // Print current status + printStatus(); + // User Input - printf("User Input:"); scanf(" %s", userInput); printf("\n"); @@ -124,6 +128,8 @@ void processInput(char userInput[20]) { printf("Wrong Input!\n"); } + + inputCounter += 1; } // function for checking user input of exit @@ -137,6 +143,7 @@ int checkExit(char userInput[20]) return 0; } +//check is user moved int checkMove(char userInput[20]) { @@ -177,3 +184,37 @@ int checkMove(char userInput[20]) return 1; } } + +// print actual location and messages from game.map +void printStatus() +{ + Room actualRoom = map[playerPosition]; + char moveMessage[30]; + + if (lastPlayerPosition > playerPosition) + { + strcpy(moveMessage, "You went to the south!"); + } + else if (lastPlayerPosition < playerPosition) + { + strcpy(moveMessage, "You went to the north!"); + } + else if (lastPlayerPosition == playerPosition && playerPosition == 0) + { + strcpy(moveMessage, "START"); + } + else + { + strcpy(moveMessage, "You didn't move"); + } + + if (lastPlayerPosition != playerPosition || playerPosition == 0 && inputCounter == 0) + { + printf("\n\n################################################################################\n"); + + printf("--> %s <--\n", moveMessage); + printf("%s\n", actualRoom.nameRoom); + printf("%s\n", actualRoom.msgRoom); + printf("\n"); + } +} \ No newline at end of file From 12d6f1143a7038d56d2d1ad1365d836b2cfd25a3 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:31:04 +0100 Subject: [PATCH 13/51] added items with test and items.map file --- src/c/items.c | 57 +++++++++++++++++++++++++++++++++++++++++++ src/c/items.h | 20 +++++++++++++++ src/content/items.map | 8 ++++++ test/c/test_items.c | 38 +++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 src/c/items.c create mode 100644 src/c/items.h create mode 100644 src/content/items.map create mode 100644 test/c/test_items.c diff --git a/src/c/items.c b/src/c/items.c new file mode 100644 index 0000000..191051a --- /dev/null +++ b/src/c/items.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include "nav_helper.h" +#include "items.h" + +Item *getItems(char *itemsMapFile) +{ + static Item getItems[maxItems]; + + FILE *stream; + char *line = NULL; + size_t len = 0; + ssize_t read; + + stream = fopen(itemsMapFile, "r"); + if (stream == NULL) + { + printf("ERROR: couldn't open or find file: ITEMS!\n"); + exit(EXIT_FAILURE); // exit + } + + char delimiter[] = ";"; + + /* print line by line from file */ + int lineCounter = 0; + while ((read = getline(&line, &len, stream)) != -1) + { + // printf("Retrieved line of length %u :\n", read); + if (startsWith(line, "#") == 0) + { + char *arr[itemAttributesMax]; + char *token = strtok(line, delimiter); + int countToken = 0; + while (token != NULL) + { + arr[countToken] = token; + token = strtok(NULL, ";"); + + countToken += 1; + } + free(token); + + Item i; + i.id = atoi(arr[0]); + strcpy(i.itemName, arr[1]); + //printf(arr[2]); + i.price = atoi(arr[3]); + + getItems[lineCounter] = i; + lineCounter += 1; + } + } + return getItems; +} diff --git a/src/c/items.h b/src/c/items.h new file mode 100644 index 0000000..ed50446 --- /dev/null +++ b/src/c/items.h @@ -0,0 +1,20 @@ +#ifndef ITEMS_H +#define ITEMS_H + +#define itemAttributesMax 4 // for items +#define maxItems 100 // for inventory/item list + +#include + +typedef struct +{ + int id; + char itemName[50]; + bool inShopAvailable; + int price; +} Item; + +Item *getItems(char *itemsMapFile); + + +#endif \ No newline at end of file diff --git a/src/content/items.map b/src/content/items.map new file mode 100644 index 0000000..0dcc59c --- /dev/null +++ b/src/content/items.map @@ -0,0 +1,8 @@ +# LINES WITH '#' AT BEGINNING GET IGNORED +#ID;NAME;inShopAvailable;price +1;healing potion;1;20 +2;shield;1;50 +3;UV flashlight;1;80 +4;key for police station;0;9999 +5;acid;1;9999 +6;gun;0;9999 \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c new file mode 100644 index 0000000..9fc3ce3 --- /dev/null +++ b/test/c/test_items.c @@ -0,0 +1,38 @@ +#ifdef TEST + +#include "unity.h" +#include "nav_helper.h" +#include "items.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_items(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + Item* items; + int expectedItemID = 1; + int expectedSecondItemID = 2; + + /* act */ + // Die Funktion wird ausgeführt + items = getItems("./src/content/items.map"); + + /* make visible OUTPUT */ + for(int i=0; i<4;i++){ + printf("%s\n", items[i].itemName); + } + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(expectedItemID, items[0].id); + TEST_ASSERT_EQUAL_INT(expectedSecondItemID, items[1].id); +} + +#endif // TEST From 3d9394cc71a0ba315ef0ae11cc8463c8f0c1c571 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:32:22 +0100 Subject: [PATCH 14/51] added items to main and game --- src/c/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/c/main.c b/src/c/main.c index 3499360..375c150 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -6,17 +6,21 @@ #include "map.h" #include "nav_helper.h" +#include "items.h" +#include "shop.h" bool gameRunning; bool acceptedRules; // declare needed variables Room *map; +Item *availableItems; int inputCounter = 0; // content char *gameInstructionsFile = "../../src/content/game_instructions.txt"; char *gameMapFile = "../../src/content/game.map"; +char *itemsMapFile = "../../src/content/items.map"; // navigation int playerPosition = 0; @@ -41,6 +45,7 @@ int main() // get Content map = getMap(gameMapFile); + availableItems = getItems(itemsMapFile); if (acceptedRules == 1) { @@ -124,6 +129,15 @@ void processInput(char userInput[20]) gameRunning = 0; printf("!GAME EXIT!\n"); } + else if (strcmp(userInput, "shop") == 0) + { + int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel + if (result > 0) + { + // buyItem -> we need inventory for player first + } + printStatus(); + } else if (checkMove(userInput) == 1) { printf("Wrong Input!\n"); @@ -143,7 +157,7 @@ int checkExit(char userInput[20]) return 0; } -//check is user moved +// check is user moved int checkMove(char userInput[20]) { From d8c2a249303c79d4e9246c585853a352934254a0 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:35:36 +0100 Subject: [PATCH 15/51] added shop function --- src/c/shop.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/c/shop.h | 8 ++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/c/shop.c create mode 100644 src/c/shop.h diff --git a/src/c/shop.c b/src/c/shop.c new file mode 100644 index 0000000..4f871aa --- /dev/null +++ b/src/c/shop.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include "shop.h" + +int openShop(Item *availableItems) +{ + int userInput; + fflush(stdout); + bool shopIsOpen = 1; + while (shopIsOpen == 1) + { + printf("*** SHOP-Items *** \n\n"); + + // printf("%-5s %-30s %5s\n", "Index", "Name", "Price"); + for (int i = 0; i < 6; i++) + { + printf("%-5d %-40s %5d$\n", availableItems[i].id, availableItems[i].itemName, availableItems[i].price); + } + + printf("\n-> to buy items type '[index of item]' \n-> write '0' to quit the shop'\n\n"); + + while (scanf("%d", &userInput) != 1) + { + printf("Invalid [index]. Please try again: "); + fflush(stdout); + } + + if (userInput > 0) + { + return userInput; + // BUY ITEM added later -> addItemToInventory(userInput); + } + else if (userInput == 0) + { + shopIsOpen = 0; + printf("Enjoy your items, have a great day!\n"); + return 0; + } + else + { + printf("Invalid [index]. Please try again: "); + } + } + + return 0; +} \ No newline at end of file diff --git a/src/c/shop.h b/src/c/shop.h new file mode 100644 index 0000000..24a390b --- /dev/null +++ b/src/c/shop.h @@ -0,0 +1,8 @@ +#ifndef SHOP_H +#define SHOP_H + +#include "items.h" + +int openShop(Item *availableItems); + +#endif \ No newline at end of file From 2aea5ab0797100aa88c22889dd965d42d95ed7c8 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:40:58 +0100 Subject: [PATCH 16/51] added struct player & func addItemToInventory --- src/c/player.c | 17 +++++++++++++++++ src/c/player.h | 16 ++++++++++++++++ test/c/test_player.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/c/player.c create mode 100644 src/c/player.h create mode 100644 test/c/test_player.c diff --git a/src/c/player.c b/src/c/player.c new file mode 100644 index 0000000..c789fed --- /dev/null +++ b/src/c/player.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +#include "player.h" + + +// PLAYER INVENTORY +Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) +{ + int counter = actualPlayer.itemCounter; + actualPlayer.itemInventory[counter] = availableItems[itemIndex - 1]; // -1 to get right index (items begin - 1,2,3,4...) + actualPlayer.itemCounter += 1; + + return actualPlayer; +} \ No newline at end of file diff --git a/src/c/player.h b/src/c/player.h new file mode 100644 index 0000000..25a69be --- /dev/null +++ b/src/c/player.h @@ -0,0 +1,16 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include "items.h" + +typedef struct +{ + int id; + int itemCounter; + Item itemInventory[100]; + int wallet; +} Player; + +Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); + +#endif \ No newline at end of file diff --git a/test/c/test_player.c b/test/c/test_player.c new file mode 100644 index 0000000..bbdb496 --- /dev/null +++ b/test/c/test_player.c @@ -0,0 +1,33 @@ +#ifdef TEST + +#include "unity.h" +#include "player.h" +#include "items.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_addItemToInventory(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int shopItemIndex = 1; + Player actualPlayer; + Item *availableItems = getItems("./src/content/items.map"); + + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = addItemToInventory(availableItems, shopItemIndex, actualPlayer); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(shopItemIndex, actualPlayer.itemInventory[0].id); +} + +#endif // TEST From c82c5855f72438ea135a82eaffd0c911e733ddcc Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:42:18 +0100 Subject: [PATCH 17/51] add player struct + addItemToInventory into main --- src/c/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/c/main.c b/src/c/main.c index 375c150..a64da20 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -8,6 +8,7 @@ #include "nav_helper.h" #include "items.h" #include "shop.h" +#include "player.h" bool gameRunning; bool acceptedRules; @@ -15,6 +16,7 @@ bool acceptedRules; // declare needed variables Room *map; Item *availableItems; +Player actualPlayer; int inputCounter = 0; // content @@ -37,6 +39,7 @@ void printStatus(); int main() { // define variables + actualPlayer.id = 1; char userInput[20]; // maximum defined user input length gameRunning = 1; @@ -134,7 +137,7 @@ void processInput(char userInput[20]) int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel if (result > 0) { - // buyItem -> we need inventory for player first + addItemToInventory(availableItems, result, actualPlayer); } printStatus(); } From 434ef7a3e6bcefa31c212a3662d50d3f955dddb9 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:42:58 +0100 Subject: [PATCH 18/51] added showInventory --- src/c/player.c | 22 ++++++++++++++++++++++ src/c/player.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index c789fed..3b3afef 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -14,4 +14,26 @@ Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlay actualPlayer.itemCounter += 1; return actualPlayer; +} + +void showInventory(Player actualPlayer) +{ + int inventoryItemCounter = actualPlayer.itemCounter; + + if (inventoryItemCounter == 0) + { + printf("*** Inventory is empty *** \n\n"); + } + else + { + printf("*** Inventory *** \n\n"); + + for (int i = 0; i < actualPlayer.itemCounter; i++) + { + // printf("%d: %d - %s\n", i, inventory[i].id, inventory[i].itemName); + printf("> %s - %d\n", actualPlayer.itemInventory[i].itemName, i); + } + } + + printf("\n\n"); } \ No newline at end of file diff --git a/src/c/player.h b/src/c/player.h index 25a69be..fdb704a 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -13,4 +13,6 @@ typedef struct Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); +void showInventory(Player actualPlayer); + #endif \ No newline at end of file From 0ba71809f41071b0fc26402d3671435d3a8df063 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:43:40 +0100 Subject: [PATCH 19/51] added showInventory to main --- src/c/main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index a64da20..fb9bd97 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -137,16 +137,18 @@ void processInput(char userInput[20]) int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel if (result > 0) { - addItemToInventory(availableItems, result, actualPlayer); + actualPlayer = addItemToInventory(availableItems, result, actualPlayer); } - printStatus(); + } + else if (strcmp(userInput, "inventory") == 0) + { + showInventory(actualPlayer); } else if (checkMove(userInput) == 1) { printf("Wrong Input!\n"); } - inputCounter += 1; } // function for checking user input of exit @@ -163,12 +165,10 @@ int checkExit(char userInput[20]) // check is user moved int checkMove(char userInput[20]) { - Room r = map[playerPosition]; - + inputCounter += 1; if (strcmp(userInput, "north") == 0) { - printf("->N\n"); lastPlayerPosition = playerPosition; if (playerPosition == (int)(mapMax - 1)) { @@ -183,7 +183,6 @@ int checkMove(char userInput[20]) } else if (strcmp(userInput, "south") == 0) { - printf("->S\n"); lastPlayerPosition = playerPosition; if (playerPosition > 0) { From 1d863f9410de7667069691810385296ea136bb6e Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:44:31 +0100 Subject: [PATCH 20/51] added removeItemFromInventory with test --- src/c/player.c | 39 ++++++++++++++++++++++++++++++++++++++- src/c/player.h | 1 + test/c/test_player.c | 24 ++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/c/player.c b/src/c/player.c index 3b3afef..355801f 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -7,6 +7,8 @@ // PLAYER INVENTORY + +//add and remove Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) { int counter = actualPlayer.itemCounter; @@ -16,6 +18,40 @@ Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlay return actualPlayer; } +Player removeItemFromInventory(int itemIndex, Player actualPlayer) +{ + Item items[maxItems]; // actualPlayer.itemInventory + int i, index = -1; + + for (i = 0; i < maxItems; i++) + { + if (i == itemIndex) + { + // printf("%d - '%s' has been removed from inventory.\n", actualPlayer.itemInventory[i].id, actualPlayer.itemInventory[i].itemName); + index = i; + break; + } + } + + if (index != -1) + { + // shift all the element from index+1 by one position to the left + for (i = index; i < maxItems - 1; i++) + actualPlayer.itemInventory[i] = actualPlayer.itemInventory[i + 1]; + + /*printf("New Array : "); + for(i = 0; i < maxItems - 1; i++) + printf("%d ",actualPlayer.itemInventory[i].id);*/ + } + else + printf("Element Not Found\n"); + + actualPlayer.itemCounter = actualPlayer.itemCounter - 1; + + return actualPlayer; +} + +//show void showInventory(Player actualPlayer) { int inventoryItemCounter = actualPlayer.itemCounter; @@ -36,4 +72,5 @@ void showInventory(Player actualPlayer) } printf("\n\n"); -} \ No newline at end of file +} + diff --git a/src/c/player.h b/src/c/player.h index fdb704a..2bfeb06 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -12,6 +12,7 @@ typedef struct } Player; Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); +Player removeItemFromInventory(int index, Player actualPlayer); void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index bbdb496..012e4be 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -5,8 +5,11 @@ #include "items.h" #include "nav_helper.h" +Item *availableItems; +Player actualPlayer; void setUp(void) { + availableItems = getItems("./src/content/items.map"); } void tearDown(void) @@ -18,8 +21,6 @@ void test_addItemToInventory(void) /* arrange */ // Hier die Werte eingeben/deklarieren int shopItemIndex = 1; - Player actualPlayer; - Item *availableItems = getItems("./src/content/items.map"); /* act */ // Die Funktion wird ausgeführt @@ -30,4 +31,23 @@ void test_addItemToInventory(void) TEST_ASSERT_EQUAL_INT(shopItemIndex, actualPlayer.itemInventory[0].id); } +void test_removeItemFromInventory(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int itemToRemove = 0; // index to remove (we already bought it in function above) + + /* act */ + // Die Funktion wird ausgeführt + Item itemBeforeRemove = actualPlayer.itemInventory[0]; + actualPlayer = removeItemFromInventory(itemToRemove, actualPlayer); // then remove + Item itemAfterRemove = actualPlayer.itemInventory[0]; + + // OUTPUT + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id); +} + #endif // TEST From 11d7f06b92861a1c8d69ad6d7509a6abfb6bd6d2 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:45:32 +0100 Subject: [PATCH 21/51] added setTotal with test --- src/c/player.c | 7 +++++++ src/c/player.h | 5 +++++ test/c/test_player.c | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index 355801f..83596a9 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -51,6 +51,13 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer) return actualPlayer; } +//currency +Player setTotal(Player actualPlayer, int value) +{ + actualPlayer.wallet = value; + return actualPlayer; +} + //show void showInventory(Player actualPlayer) { diff --git a/src/c/player.h b/src/c/player.h index 2bfeb06..e5191fa 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -11,9 +11,14 @@ typedef struct int wallet; } Player; +//add and remove items Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); Player removeItemFromInventory(int index, Player actualPlayer); +//currency +Player setTotal(Player actualPlayer, int value); + +//show void showInventory(Player actualPlayer); #endif \ No newline at end of file diff --git a/test/c/test_player.c b/test/c/test_player.c index 012e4be..4763d43 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -44,10 +44,32 @@ void test_removeItemFromInventory(void) Item itemAfterRemove = actualPlayer.itemInventory[0]; // OUTPUT + printf("removeItem | ID_before: %d -> ID_after: %d", itemBeforeRemove.id, itemAfterRemove.id); /* assert */ // Vergleichen mit Inhalt von game.Map File TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id); } +void test_setTotal(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int setMoney = 100; + + /* act */ + // Die Funktion wird ausgeführt + int valueBefore = actualPlayer.wallet; + actualPlayer = setTotal(actualPlayer, setMoney); + int valueAfter = actualPlayer.wallet; + + // OUTPUT + printf("setTotal | before: %d -> after: %d", valueBefore, valueAfter); + + /* assert */ + // Vergleichen mit Inhalt + TEST_ASSERT_EQUAL_INT(setMoney, actualPlayer.wallet); + TEST_ASSERT_NOT_EQUAL_UINT8(valueBefore, valueAfter); +} + #endif // TEST From 5b9fa5460a13af867b6e211a04cdb5a90b0e7435 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:46:13 +0100 Subject: [PATCH 22/51] added addMoneyToPlayer with test --- src/c/player.c | 15 ++++++++++----- src/c/player.h | 1 + test/c/test_player.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/c/player.c b/src/c/player.c index 83596a9..eea802d 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -5,10 +5,9 @@ #include "player.h" - // PLAYER INVENTORY -//add and remove +// add and remove Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) { int counter = actualPlayer.itemCounter; @@ -51,14 +50,21 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer) return actualPlayer; } -//currency +// currency Player setTotal(Player actualPlayer, int value) { actualPlayer.wallet = value; return actualPlayer; } -//show +Player addMoneyToPlayer(Player actualPlayer, int money) +{ + int newTotal = money + actualPlayer.wallet; + actualPlayer = setTotal(actualPlayer, newTotal); + return actualPlayer; +} + +// show void showInventory(Player actualPlayer) { int inventoryItemCounter = actualPlayer.itemCounter; @@ -80,4 +86,3 @@ void showInventory(Player actualPlayer) printf("\n\n"); } - diff --git a/src/c/player.h b/src/c/player.h index e5191fa..5569f6c 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -17,6 +17,7 @@ Player removeItemFromInventory(int index, Player actualPlayer); //currency Player setTotal(Player actualPlayer, int value); +Player addMoneyToPlayer(Player actualPlayer, int money); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index 4763d43..e3c708d 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -72,4 +72,23 @@ void test_setTotal(void) TEST_ASSERT_NOT_EQUAL_UINT8(valueBefore, valueAfter); } +void test_addMoneyToPlayer(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + // balance = 70 + int valueToAdd = 20; + int checkSum = actualPlayer.wallet + valueToAdd; + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd); + + // OUTPUT + printf("%d$ has been added to your balance. TOTAL: %d$", valueToAdd, actualPlayer.wallet); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); +} + #endif // TEST From 35f45ee77a1ae99007fcf3368fc5c02238146317 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:46:59 +0100 Subject: [PATCH 23/51] added removeMoneyFromPlayer with test --- src/c/player.c | 7 +++++++ src/c/player.h | 1 + test/c/test_player.c | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index eea802d..f59881b 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -64,6 +64,13 @@ Player addMoneyToPlayer(Player actualPlayer, int money) return actualPlayer; } +Player removeMoneyFromPlayer(Player actualPlayer, int money) +{ + int newTotal = actualPlayer.wallet - money; + actualPlayer = setTotal(actualPlayer, newTotal); + return actualPlayer; +} + // show void showInventory(Player actualPlayer) { diff --git a/src/c/player.h b/src/c/player.h index 5569f6c..1283b70 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -18,6 +18,7 @@ Player removeItemFromInventory(int index, Player actualPlayer); //currency Player setTotal(Player actualPlayer, int value); Player addMoneyToPlayer(Player actualPlayer, int money); +Player removeMoneyFromPlayer(Player actualPlayer, int money); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index e3c708d..d0de9ef 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -79,6 +79,7 @@ void test_addMoneyToPlayer(void) // balance = 70 int valueToAdd = 20; int checkSum = actualPlayer.wallet + valueToAdd; + /* act */ // Die Funktion wird ausgeführt actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd); @@ -91,4 +92,26 @@ void test_addMoneyToPlayer(void) TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); } +void test_removeMoneyFromPlayer(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int valueToRemove = 20; + int checkSum = actualPlayer.wallet - valueToRemove; + + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = removeMoneyFromPlayer(actualPlayer, valueToRemove); + + // OUTPUT + printf("%d$ has been removed from your balance. TOTAL: %d$", valueToRemove, actualPlayer.wallet); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); +} + + + + #endif // TEST From a18aca76d7403207b9c800d60d7ca482780519ba Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:48:32 +0100 Subject: [PATCH 24/51] added buyItem with test --- src/c/player.c | 19 +++++++++++++++++++ src/c/player.h | 3 +++ test/c/test_player.c | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index f59881b..fea8f91 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -71,6 +71,25 @@ Player removeMoneyFromPlayer(Player actualPlayer, int money) return actualPlayer; } +//add and remove items with currency +Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) +{ + int itemPrice = availableItems[itemIndex - 1].price; + if (actualPlayer.wallet >= itemPrice) + { + actualPlayer = addItemToInventory(availableItems, itemIndex, actualPlayer); + actualPlayer = removeMoneyFromPlayer(actualPlayer, itemPrice); + printf("You bought item for %d$! Your balance is now: %d$\n", itemPrice, actualPlayer.wallet); + return actualPlayer; + } + else + { + printf("You don't have enough money.\n\n"); + return actualPlayer; + } +} + + // show void showInventory(Player actualPlayer) { diff --git a/src/c/player.h b/src/c/player.h index 1283b70..411c2cf 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -20,6 +20,9 @@ Player setTotal(Player actualPlayer, int value); Player addMoneyToPlayer(Player actualPlayer, int money); Player removeMoneyFromPlayer(Player actualPlayer, int money); +//add and remove items with currency +Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer); + //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index d0de9ef..2bd5683 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -111,7 +111,23 @@ void test_removeMoneyFromPlayer(void) TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); } +void test_buyItem(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int itemIndex = 2; // price = 50 + int checkSum = actualPlayer.wallet - availableItems[itemIndex-1].price; + + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = buyItem(availableItems, itemIndex, actualPlayer); + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(itemIndex, actualPlayer.itemInventory[0].id); //check if item has right ID + TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); //check money after transfer + +} #endif // TEST From 2c18f05b05f38f64909aeacb9499d18cd5ef0b00 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:49:05 +0100 Subject: [PATCH 25/51] added sellItem with test --- src/c/player.c | 7 +++++++ src/c/player.h | 1 + test/c/test_player.c | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index fea8f91..85602bf 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -89,6 +89,13 @@ Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) } } +Player sellItem(int itemIndex, Player actualPlayer) +{ + actualPlayer = addMoneyToPlayer(actualPlayer, actualPlayer.itemInventory[itemIndex].price / 2); + actualPlayer = removeItemFromInventory(itemIndex, actualPlayer); + printf("Item has been sold! Your balance is now: %d$\n", actualPlayer.wallet); + return actualPlayer; +} // show void showInventory(Player actualPlayer) diff --git a/src/c/player.h b/src/c/player.h index 411c2cf..4518f70 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -22,6 +22,7 @@ Player removeMoneyFromPlayer(Player actualPlayer, int money); //add and remove items with currency Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer); +Player sellItem(int itemIndex, Player actualPlayer); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index 2bd5683..5e86752 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -129,5 +129,27 @@ void test_buyItem(void) } +void test_sellItem(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int buyItemID = 1; // prepare sell + actualPlayer = addItemToInventory(availableItems, buyItemID, actualPlayer); // prepare sell + + int itemToRemove = 0; // index to remove (we already bought it in function above) + + /* act */ + // Die Funktion wird ausgeführt + Item itemBeforeRemove = actualPlayer.itemInventory[0]; + actualPlayer = sellItem(itemToRemove, actualPlayer); // then remove + Item itemAfterRemove = actualPlayer.itemInventory[0]; + + // OUTPUT + //printf("sellItem | before: %d -> after: %d", itemBeforeRemove.id, itemAfterRemove.id); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id); +} #endif // TEST From 22fd94352fe3ff638b8b884995c7cde0b429afe9 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:51:08 +0100 Subject: [PATCH 26/51] add commands (make it visible for user) with test --- src/c/commands.c | 30 ++++++++++++++++++++++++++++++ src/c/commands.h | 8 ++++++++ test/c/test_commands.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/c/commands.c create mode 100644 src/c/commands.h create mode 100644 test/c/test_commands.c diff --git a/src/c/commands.c b/src/c/commands.c new file mode 100644 index 0000000..7b7eeff --- /dev/null +++ b/src/c/commands.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include "map.h" + +char* getPossibleCommands(Room r, int playerPosition) +{ + char commands[][20] = {}; + + char *msg = malloc(sizeof(char) * (500)); + strcpy(msg, ""); //assign char (string) that no leading zero result + if (playerPosition > 0) + { + strcat(msg, "You can move south from here\n"); + } + + if (playerPosition < mapMax - 1) + { + strcat(msg, "You can move north from here\n"); + } + + if (r.shopAvailable == 1) + { + strcat(msg, "You can call 'shop' to buy items.\n"); + } + + return msg; +} diff --git a/src/c/commands.h b/src/c/commands.h new file mode 100644 index 0000000..22bc63d --- /dev/null +++ b/src/c/commands.h @@ -0,0 +1,8 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + +#include "map.h" + +char* getPossibleCommands(Room r, int playerPosition); + +#endif // COMMANDS_H \ No newline at end of file diff --git a/test/c/test_commands.c b/test/c/test_commands.c new file mode 100644 index 0000000..aa20fa0 --- /dev/null +++ b/test/c/test_commands.c @@ -0,0 +1,37 @@ +#ifdef TEST + +#include "unity.h" +#include "commands.h" +#include "map.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_commands(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + Room* mapData; + mapData = getMap("./src/content/game.map"); + int playerPosition = 3; //last player position in north - so you can only move to south + char* expectedString = "You can move south from here\n"; + + /* act */ + // Die Funktion wird ausgeführt + char* msg = getPossibleCommands(mapData[playerPosition], playerPosition); + + /* TEST AUSGABE zur Kontrolle */ + printf("%s", msg); + + /* assert */ + // Vergleichen mit Inhalt + TEST_ASSERT_EQUAL_STRING(expectedString, msg); +} + +#endif // TEST \ No newline at end of file From fb1f9cdd22b56ce393b05a1211306bb12a10cae5 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:52:10 +0100 Subject: [PATCH 27/51] commands now visible in game for user --- src/c/main.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index fb9bd97..a82e827 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -9,6 +9,7 @@ #include "items.h" #include "shop.h" #include "player.h" +#include "commands.h" bool gameRunning; bool acceptedRules; @@ -134,21 +135,28 @@ void processInput(char userInput[20]) } else if (strcmp(userInput, "shop") == 0) { - int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel - if (result > 0) + Room actualRoom = map[playerPosition]; + if (actualRoom.shopAvailable == 1) { - actualPlayer = addItemToInventory(availableItems, result, actualPlayer); + int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel + if (result > 0) + { + actualPlayer = addItemToInventory(availableItems, result, actualPlayer); + } + } + else + { + printf("You can't access the shop from here."); } } else if (strcmp(userInput, "inventory") == 0) { - showInventory(actualPlayer); + showInventory(actualPlayer); } else if (checkMove(userInput) == 1) { printf("Wrong Input!\n"); } - } // function for checking user input of exit @@ -232,5 +240,10 @@ void printStatus() printf("%s\n", actualRoom.nameRoom); printf("%s\n", actualRoom.msgRoom); printf("\n"); + + char *possibleCommands = malloc(sizeof(char) * (500)); + possibleCommands = getPossibleCommands(map[playerPosition], playerPosition); + printf("%s", possibleCommands); + free(possibleCommands); } } \ No newline at end of file From a926b7aec1b3f943b5c1b1e6e4164b3f7f9fba6c Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:54:19 +0100 Subject: [PATCH 28/51] added sellItem to shop in game (main) --- src/c/main.c | 12 +++-- src/c/player.c | 6 ++- src/c/shop.c | 143 ++++++++++++++++++++++++++++++++++++++++--------- src/c/shop.h | 3 +- 4 files changed, 134 insertions(+), 30 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index a82e827..613cd06 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -41,6 +41,7 @@ int main() { // define variables actualPlayer.id = 1; + actualPlayer.wallet = 100; char userInput[20]; // maximum defined user input length gameRunning = 1; @@ -138,10 +139,15 @@ void processInput(char userInput[20]) Room actualRoom = map[playerPosition]; if (actualRoom.shopAvailable == 1) { - int result = openShop(availableItems); // result > 0 -> integer = index of item OR result = 0 -> cancel - if (result > 0) + int *result = malloc (sizeof (int) * 2); + result = openShop(availableItems, actualPlayer); // result > 0 -> integer = index of item OR result = 0 -> cancel + if (result[0] == 0) { - actualPlayer = addItemToInventory(availableItems, result, actualPlayer); + actualPlayer = buyItem(availableItems, result[1], actualPlayer); + } + else if (result[0] == 1) + { + actualPlayer = sellItem(result[1], actualPlayer); } } else diff --git a/src/c/player.c b/src/c/player.c index 85602bf..0e3fedd 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -79,7 +79,7 @@ Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) { actualPlayer = addItemToInventory(availableItems, itemIndex, actualPlayer); actualPlayer = removeMoneyFromPlayer(actualPlayer, itemPrice); - printf("You bought item for %d$! Your balance is now: %d$\n", itemPrice, actualPlayer.wallet); + printf("You bought item[%d] for %d$! \nYour balance is now: %d$\n", itemIndex, itemPrice, actualPlayer.wallet); return actualPlayer; } else @@ -91,9 +91,11 @@ Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) Player sellItem(int itemIndex, Player actualPlayer) { + int priceItemSell = actualPlayer.itemInventory[itemIndex].price; actualPlayer = addMoneyToPlayer(actualPlayer, actualPlayer.itemInventory[itemIndex].price / 2); + printf("Item has been sold for 50%% of the purchase price (purchase price: %d$)! \nYour balance is now: %d$\n", priceItemSell, actualPlayer.wallet); + actualPlayer = removeItemFromInventory(itemIndex, actualPlayer); - printf("Item has been sold! Your balance is now: %d$\n", actualPlayer.wallet); return actualPlayer; } diff --git a/src/c/shop.c b/src/c/shop.c index 4f871aa..88e0659 100644 --- a/src/c/shop.c +++ b/src/c/shop.c @@ -2,48 +2,143 @@ #include #include #include +#include #include "shop.h" +#include "player.h" -int openShop(Item *availableItems) +int *openShop(Item *availableItems, Player actualPlayer) { - int userInput; + int mode = 0; + int *x = malloc(sizeof(int) * 2); + + int userModeInput; fflush(stdout); - bool shopIsOpen = 1; - while (shopIsOpen == 1) + bool selectMode = 1; + while (selectMode == 1) { - printf("*** SHOP-Items *** \n\n"); - - // printf("%-5s %-30s %5s\n", "Index", "Name", "Price"); - for (int i = 0; i < 6; i++) + printf("Please type '0' for buy or '1' to sell items!\n"); + while (scanf(" %d", &userModeInput) != 1) { - printf("%-5d %-40s %5d$\n", availableItems[i].id, availableItems[i].itemName, availableItems[i].price); + printf("Invalid [index]. Please try again: "); + fflush(stdout); } - printf("\n-> to buy items type '[index of item]' \n-> write '0' to quit the shop'\n\n"); - - while (scanf("%d", &userInput) != 1) + if (userModeInput > 1 || userModeInput < 0) { printf("Invalid [index]. Please try again: "); - fflush(stdout); } - - if (userInput > 0) + else if (userModeInput == 0) + { + mode = 0; + selectMode = 0; + } + else if (userModeInput == 1) { - return userInput; - // BUY ITEM added later -> addItemToInventory(userInput); + mode = 1; + selectMode = 0; } - else if (userInput == 0) + } + + int userInput; + fflush(stdout); + bool shopIsOpen = 1; + + if (mode == 0) + { + + while (shopIsOpen == 1) { - shopIsOpen = 0; - printf("Enjoy your items, have a great day!\n"); - return 0; + printf("*** SHOP-Items *** \n\n"); + + // printf("%-5s %-30s %5s\n", "Index", "Name", "Price"); + for (int i = 0; i < 6; i++) + { + printf("%-5d %-40s %5d$\n", availableItems[i].id, availableItems[i].itemName, availableItems[i].price); + } + + printf("\n-> to buy items type '[index of item]' \n-> write '0' to quit the shop'\n\n"); + + while (scanf(" %d", &userInput) != 1) + { + printf("Invalid [index]. Please try again: "); + fflush(stdout); + } + + if (userInput > 0) + { + x[0] = mode; + x[1] = userInput; + return x; + // BUY ITEM added later -> addItemToInventory(userInput); + } + else if (userInput == 0) + { + shopIsOpen = 0; + printf("Enjoy your items, have a great day!\n"); + x[0] = -1; + x[1] = -1; + return x; + } + else + { + printf("Invalid [index]. Please try again: "); + } } - else + } + else if (mode == 1) + { + while (shopIsOpen == 1) { - printf("Invalid [index]. Please try again: "); + if (actualPlayer.itemCounter > 0) + { + printf("*** Your inventory *** \n\n"); + + // printf("%-5s %-30s %5s\n", "Index", "Name", "Price"); + for (int i = 0; i < actualPlayer.itemCounter; i++) + { + printf("%-5d %-40s %5d$\n", i+1, actualPlayer.itemInventory[i].itemName, actualPlayer.itemInventory[i].price); + } + + printf("\n-> to sell items type '[index of item]' \n-> write '0' to quit the shop'\n\n"); + + while (scanf(" %d", &userInput) != 1) + { + printf("Invalid [index]. Please try again: "); + fflush(stdout); + } + + if (userInput > 0) + { + x[0] = mode; + x[1] = userInput-1; //index begin on 1 because we will cancel with 0 + return x; + // BUY ITEM added later -> addItemToInventory(userInput); + } + else if (userInput == 0) + { + shopIsOpen = 0; + printf("Enjoy your money, have a great day!\n"); + x[0] = -1; + x[1] = -1; + return x; + } + else + { + printf("Invalid [index]. Please try again: "); + } + } + else + { + shopIsOpen = 0; + printf("*** Your inventory is empty *** \n\n"); + x[0] = -1; + x[1] = -1; + return x; + } } } - return 0; + x[0] = -1; + return x; } \ No newline at end of file diff --git a/src/c/shop.h b/src/c/shop.h index 24a390b..bb41f3b 100644 --- a/src/c/shop.h +++ b/src/c/shop.h @@ -2,7 +2,8 @@ #define SHOP_H #include "items.h" +#include "player.h" -int openShop(Item *availableItems); +int *openShop(Item *availableItems, Player actualPlayer); #endif \ No newline at end of file From 218a01068dd47a2a19dd9f00a3518ba1042d5dea Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:55:09 +0100 Subject: [PATCH 29/51] added setItemPrice with test --- src/c/items.c | 6 ++++++ src/c/items.h | 2 ++ test/c/test_items.c | 22 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/c/items.c b/src/c/items.c index 191051a..7f09bd5 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -55,3 +55,9 @@ Item *getItems(char *itemsMapFile) } return getItems; } + + +void setItemPrice(Item* item, int price) +{ + item->price = price; +} \ No newline at end of file diff --git a/src/c/items.h b/src/c/items.h index ed50446..143006f 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -17,4 +17,6 @@ typedef struct Item *getItems(char *itemsMapFile); +void setItemPrice(Item* item, int price); + #endif \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c index 9fc3ce3..f9bf002 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -16,7 +16,7 @@ void test_items(void) { /* arrange */ // Hier die Werte eingeben/deklarieren - Item* items; + Item *items; int expectedItemID = 1; int expectedSecondItemID = 2; @@ -25,7 +25,8 @@ void test_items(void) items = getItems("./src/content/items.map"); /* make visible OUTPUT */ - for(int i=0; i<4;i++){ + for (int i = 0; i < 4; i++) + { printf("%s\n", items[i].itemName); } @@ -35,4 +36,21 @@ void test_items(void) TEST_ASSERT_EQUAL_INT(expectedSecondItemID, items[1].id); } +void test_setItemPrice(void) +{ + + // arrange + int price = 50, result; + // act + Item test; + setItemPrice(&test, price); + result = test.price; + + printf("---------------------------------------------------\n"); + printf("setItemPrice | price to set: %d -> item.price: %d", price, result); + + // assert + TEST_ASSERT_EQUAL(price, result); +} + #endif // TEST From 05dca15a6454e4cf3bce8745c396805842336491 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:55:57 +0100 Subject: [PATCH 30/51] added getItemPrice with test --- src/c/items.c | 6 +++++- src/c/items.h | 7 +++++-- test/c/test_items.c | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/c/items.c b/src/c/items.c index 7f09bd5..1b223fa 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -56,8 +56,12 @@ Item *getItems(char *itemsMapFile) return getItems; } +int getItemPrice(Item *item) +{ + return item->price; +} void setItemPrice(Item* item, int price) { item->price = price; -} \ No newline at end of file +} diff --git a/src/c/items.h b/src/c/items.h index 143006f..0fa3740 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -2,7 +2,7 @@ #define ITEMS_H #define itemAttributesMax 4 // for items -#define maxItems 100 // for inventory/item list +#define maxItems 100 // for inventory/item list #include @@ -17,6 +17,9 @@ typedef struct Item *getItems(char *itemsMapFile); -void setItemPrice(Item* item, int price); +int getItemPrice(Item *item); +void setItemPrice(Item *item, int price); + + #endif \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c index f9bf002..bfd4439 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -38,14 +38,15 @@ void test_items(void) void test_setItemPrice(void) { - // arrange int price = 50, result; + // act Item test; setItemPrice(&test, price); result = test.price; + //output printf("---------------------------------------------------\n"); printf("setItemPrice | price to set: %d -> item.price: %d", price, result); @@ -53,4 +54,22 @@ void test_setItemPrice(void) TEST_ASSERT_EQUAL(price, result); } + +void test_getItemPrice(void) +{ + // arrange + int price = 50, result; + + // act + Item test; + test.price = price; + result = getItemPrice(&test); + + //output + printf("getItemPrice | price should be: %d -> price is: %d", price, result); + + // assert + TEST_ASSERT_EQUAL(price, result); +} + #endif // TEST From 6ce6fced5a7e7263e0c250f43aaa8df11ad54fe0 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:56:34 +0100 Subject: [PATCH 31/51] added getItemShopAvailable with test --- src/c/items.c | 11 ++++++++--- src/c/items.h | 2 +- test/c/test_items.c | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/c/items.c b/src/c/items.c index 1b223fa..801c49b 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -46,7 +46,7 @@ Item *getItems(char *itemsMapFile) Item i; i.id = atoi(arr[0]); strcpy(i.itemName, arr[1]); - //printf(arr[2]); + // printf(arr[2]); i.price = atoi(arr[3]); getItems[lineCounter] = i; @@ -61,7 +61,12 @@ int getItemPrice(Item *item) return item->price; } -void setItemPrice(Item* item, int price) +void setItemPrice(Item *item, int price) { - item->price = price; + item->price = price; +} + +int getItemShopAvailable(Item *item) +{ + return item->inShopAvailable; } diff --git a/src/c/items.h b/src/c/items.h index 0fa3740..68fa410 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -20,6 +20,6 @@ Item *getItems(char *itemsMapFile); int getItemPrice(Item *item); void setItemPrice(Item *item, int price); - +int getItemShopAvailable(Item *item); #endif \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c index bfd4439..8904fe1 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -72,4 +72,23 @@ void test_getItemPrice(void) TEST_ASSERT_EQUAL(price, result); } +void test_getItemShopAvailable(void) +{ + // arrange + bool value = true, result; + + // act + Item test; + test.inShopAvailable = value; + result = getItemShopAvailable(&test); + + //output + printf("getItemShopAvailable | value should be: %d -> is: %d", value, result); + + // assert + TEST_ASSERT_EQUAL(value, result); +} + + + #endif // TEST From e294af735da1120724adf656f0e2504b34e1b0bf Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:57:26 +0100 Subject: [PATCH 32/51] added setItemShopAvailable with test --- src/c/items.c | 5 +++++ src/c/items.h | 2 +- test/c/test_items.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/c/items.c b/src/c/items.c index 801c49b..e44fdbc 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -70,3 +70,8 @@ int getItemShopAvailable(Item *item) { return item->inShopAvailable; } + +void setItemShopAvailable(Item *item, bool value) +{ + item->inShopAvailable = value; +} \ No newline at end of file diff --git a/src/c/items.h b/src/c/items.h index 68fa410..3d56b65 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -16,10 +16,10 @@ typedef struct Item *getItems(char *itemsMapFile); - int getItemPrice(Item *item); void setItemPrice(Item *item, int price); int getItemShopAvailable(Item *item); +void setItemShopAvailable(Item *item, bool value); #endif \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c index 8904fe1..8083d3b 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -89,6 +89,21 @@ void test_getItemShopAvailable(void) TEST_ASSERT_EQUAL(value, result); } +void test_setItemShopAvailable(void) +{ + // arrange + bool value = true, result; + + // act + Item test; + setItemShopAvailable(&test, value); + result = test.inShopAvailable; + //output + printf("setItemShopAvailable | value should be: %d -> is: %d", value, result); + + // assert + TEST_ASSERT_EQUAL(value, result); +} #endif // TEST From 3e9fd7d7e883a4379bc28667bd0bdcf153383303 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:57:53 +0100 Subject: [PATCH 33/51] updated game instructions --- src/content/game_instructions.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/content/game_instructions.txt b/src/content/game_instructions.txt index bfd0945..e089751 100644 --- a/src/content/game_instructions.txt +++ b/src/content/game_instructions.txt @@ -20,13 +20,30 @@ INSTRUCTIONS: -***** +how to move on the map +enter "north" to go north +enter "south" to go south +alltime commands: +- 'inventory' -> will show your items that you have bought or found () +special commands (not available at any time during the game): +- 'shop' -> opens the shop where you can buy or sell items +CURRENTLY NOT AVAILABLE FEATURES (will be available soon): +- "use [item]" +- "find [item]" +WARNING: Pickups are always hidden, find them with "find [item]" and take them with "take [item]" + +How to leave the game: +use "esc", "exit" or "quit" to leave the game + + +And remember, EVERY point/room has something you can do. Have fun! + ///////////////////////////////////////////////////////////////////////////////////////////// From 332949bc09c4b6e80ad251311c6d66a3367f630a Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:59:38 +0100 Subject: [PATCH 34/51] refactoring: added setUp to clean up a bit --- src/c/main.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index 613cd06..0396155 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -31,6 +31,7 @@ int lastPlayerPosition = 0; // function declarations void printInit(); +void setUp(); void acceptInstructions(); void processInput(); int checkExit(); @@ -39,21 +40,14 @@ void printStatus(); int main() { - // define variables - actualPlayer.id = 1; - actualPlayer.wallet = 100; - char userInput[20]; // maximum defined user input length - gameRunning = 1; - // init and instructions printInit(); - // get Content - map = getMap(gameMapFile); - availableItems = getItems(itemsMapFile); - if (acceptedRules == 1) { + setUp(); + + char userInput[20]; // maximum defined user input length while (gameRunning == 1) // while running { // Print current status @@ -99,6 +93,19 @@ void printInit() acceptInstructions(); } +// setUp +void setUp() +{ + // define variables + actualPlayer.id = 1; + actualPlayer.wallet = 100; + gameRunning = 1; + + // get Content + map = getMap(gameMapFile); + availableItems = getItems(itemsMapFile); +} + // accept rules and instructions for init dialogue void acceptInstructions() { @@ -139,7 +146,7 @@ void processInput(char userInput[20]) Room actualRoom = map[playerPosition]; if (actualRoom.shopAvailable == 1) { - int *result = malloc (sizeof (int) * 2); + int *result = malloc(sizeof(int) * 2); result = openShop(availableItems, actualPlayer); // result > 0 -> integer = index of item OR result = 0 -> cancel if (result[0] == 0) { From 573504153cd31a977c3b833019655e34e124193f Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:00:33 +0100 Subject: [PATCH 35/51] added getRoomSuccessor with test --- src/c/map.c | 6 +++++- src/c/map.h | 6 ++++++ test/c/test_map.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/c/map.c b/src/c/map.c index 83c3cdc..fef25b3 100644 --- a/src/c/map.c +++ b/src/c/map.c @@ -57,4 +57,8 @@ Room *getMap(char *gameMapFile) fclose(stream); /* closing file */ return fillMap; -}; \ No newline at end of file +}; + +int getRoomSuccessor(Room *room){ + return room->successor; +} diff --git a/src/c/map.h b/src/c/map.h index dd31690..d91b417 100644 --- a/src/c/map.h +++ b/src/c/map.h @@ -26,4 +26,10 @@ typedef struct Room Room *getMap(char *gameMapFile); + +int getRoomSuccessor(Room *room); + + + + #endif // MAP_H \ No newline at end of file diff --git a/test/c/test_map.c b/test/c/test_map.c index dcda939..5db052e 100644 --- a/test/c/test_map.c +++ b/test/c/test_map.c @@ -4,8 +4,10 @@ #include "map.h" #include "nav_helper.h" + void setUp(void) { + } void tearDown(void) @@ -16,13 +18,14 @@ void test_map(void) { /* arrange */ // Hier die Werte eingeben - Room* map; + Room *map; /* act */ // Die Funktion wird ausgeführt map = getMap("./src/content/game.map"); - for(int i=0; i<4;i++){ + for (int i = 0; i < 4; i++) + { printf("%s\n", map[i].nameRoom); } @@ -41,4 +44,25 @@ void test_map(void) TEST_ASSERT_EQUAL_INT(fdExpectedID, map[2].id); } +void test_getRoomSuccessor(void) +{ + // arrange + int successor = 1, result; + Room test; + test.successor = successor; + + /* act */ + // Die Funktion wird ausgeführt + result = getRoomSuccessor(&test); + + // output + printf("---------------------------------------------------------\n"); + printf("getRoomSuccessor | Successor should be: %d -> is: %d", successor, result); + + // assert + TEST_ASSERT_EQUAL(successor, result); +} + + + #endif // TEST From ebbe703493be84a50a2dfab4777b1bd59d41065b Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:01:01 +0100 Subject: [PATCH 36/51] added setRoomSuccessor with test --- src/c/map.c | 4 ++++ src/c/map.h | 2 +- test/c/test_map.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/c/map.c b/src/c/map.c index fef25b3..eb67707 100644 --- a/src/c/map.c +++ b/src/c/map.c @@ -62,3 +62,7 @@ Room *getMap(char *gameMapFile) int getRoomSuccessor(Room *room){ return room->successor; } + +void setRoomSuccessor(Room *room, int successorSet){ + room->successor = successorSet; +} diff --git a/src/c/map.h b/src/c/map.h index d91b417..e26284b 100644 --- a/src/c/map.h +++ b/src/c/map.h @@ -28,7 +28,7 @@ Room *getMap(char *gameMapFile); int getRoomSuccessor(Room *room); - +void setRoomSuccessor(Room *room, int successorSet); diff --git a/test/c/test_map.c b/test/c/test_map.c index 5db052e..337a247 100644 --- a/test/c/test_map.c +++ b/test/c/test_map.c @@ -63,6 +63,23 @@ void test_getRoomSuccessor(void) TEST_ASSERT_EQUAL(successor, result); } +void test_setRoomSuccessor(void) +{ + // arrange + int successor = 2, result; + + // act + Room test; + setRoomSuccessor(&test, successor); + result = test.successor; + + //output + printf("setRoomSuccessor | successor to set: %d -> is: %d", successor, result); + + // assert + TEST_ASSERT_EQUAL(successor, result); +} + #endif // TEST From 2b6449f2a43c96efc7bb259467574cdc6c51fdc9 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:01:54 +0100 Subject: [PATCH 37/51] added setRoomPredecessor with test --- src/c/map.c | 18 +++++++++++++++--- src/c/map.h | 3 ++- test/c/test_map.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/c/map.c b/src/c/map.c index eb67707..5e0c8c4 100644 --- a/src/c/map.c +++ b/src/c/map.c @@ -1,4 +1,4 @@ -//headers +// headers #include "map.h" Room *getMap(char *gameMapFile) @@ -59,10 +59,22 @@ Room *getMap(char *gameMapFile) return fillMap; }; -int getRoomSuccessor(Room *room){ +int getRoomSuccessor(Room *room) +{ return room->successor; } -void setRoomSuccessor(Room *room, int successorSet){ +void setRoomSuccessor(Room *room, int successorSet) +{ room->successor = successorSet; } + +int getRoomPredecessor(Room *room) +{ + return room->predecessor; +} + +void setRoomPredecessor(Room *room, int predecessorSet) +{ + room->predecessor = predecessorSet; +} diff --git a/src/c/map.h b/src/c/map.h index e26284b..966a89c 100644 --- a/src/c/map.h +++ b/src/c/map.h @@ -30,6 +30,7 @@ Room *getMap(char *gameMapFile); int getRoomSuccessor(Room *room); void setRoomSuccessor(Room *room, int successorSet); - +int getRoomPredecessor(Room *room); +void setRoomPredecessor(Room *room, int predecessorSet); #endif // MAP_H \ No newline at end of file diff --git a/test/c/test_map.c b/test/c/test_map.c index 337a247..9cb774f 100644 --- a/test/c/test_map.c +++ b/test/c/test_map.c @@ -80,6 +80,40 @@ void test_setRoomSuccessor(void) TEST_ASSERT_EQUAL(successor, result); } +void test_getRoomPredecessor(void) +{ + // arrange + int predecessor = 1, result; + Room test; + test.predecessor = predecessor; + + /* act */ + // Die Funktion wird ausgeführt + result = getRoomPredecessor(&test); + + // output + printf("getRoomPredecessor | Successor should be: %d -> is: %d", predecessor, result); + + // assert + TEST_ASSERT_EQUAL(predecessor, result); +} + +void test_setRoomPredecessor(void) +{ + // arrange + int predecessor = 3, result; + + // act + Room test; + setRoomPredecessor(&test, predecessor); + result = test.predecessor; + + //output + printf("setRoomPredecessor | successor to set: %d -> is: %d", predecessor, result); + + // assert + TEST_ASSERT_EQUAL(predecessor, result); +} #endif // TEST From fc09c340654e7bb4547baab82fc80254c171c601 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:03:00 +0100 Subject: [PATCH 38/51] added setRoomShopAvailable with test --- src/c/map.c | 10 ++++++++++ src/c/map.h | 3 +++ test/c/test_map.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/c/map.c b/src/c/map.c index 5e0c8c4..1221b8f 100644 --- a/src/c/map.c +++ b/src/c/map.c @@ -78,3 +78,13 @@ void setRoomPredecessor(Room *room, int predecessorSet) { room->predecessor = predecessorSet; } + +bool getRoomShopAvailable(Room *room) +{ + return room->shopAvailable; +} + +void setRoomShopAvailable(Room *room, bool shopAvailableSet) +{ + room->shopAvailable = shopAvailableSet; +} \ No newline at end of file diff --git a/src/c/map.h b/src/c/map.h index 966a89c..1cff482 100644 --- a/src/c/map.h +++ b/src/c/map.h @@ -33,4 +33,7 @@ void setRoomSuccessor(Room *room, int successorSet); int getRoomPredecessor(Room *room); void setRoomPredecessor(Room *room, int predecessorSet); +bool getRoomShopAvailable(Room *room); +void setRoomShopAvailable(Room *room, bool shopAvailableSet); + #endif // MAP_H \ No newline at end of file diff --git a/test/c/test_map.c b/test/c/test_map.c index 9cb774f..fce9775 100644 --- a/test/c/test_map.c +++ b/test/c/test_map.c @@ -115,5 +115,39 @@ void test_setRoomPredecessor(void) TEST_ASSERT_EQUAL(predecessor, result); } +void test_getRoomShopAvailable(void) +{ + // arrange + bool available = true, result; + Room test; + test.shopAvailable = available; + + /* act */ + // Die Funktion wird ausgeführt + result = getRoomShopAvailable(&test); + + // output + printf("getRoomShopAvailable | shopAvailable should be: %d -> is: %d", available, result); + + // assert + TEST_ASSERT_EQUAL(available, result); +} + +void test_setRoomShopAvailable(void) +{ + // arrange + bool available = true, result; + + // act + Room test; + setRoomShopAvailable(&test, available); + result = test.shopAvailable; + + //output + printf("setRoomShopAvailable | shopAvailable set to: %d -> after set: %d", available, result); + + // assert + TEST_ASSERT_EQUAL(available, result); +} #endif // TEST From 5742861b08305c70b14e9e93a00013196d0a5fab Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:04:41 +0100 Subject: [PATCH 39/51] added weapon with struct & getName with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 21 +++++++++++++++++++++ test/c/test_weapon.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/c/weapon.c create mode 100644 src/c/weapon.h create mode 100644 test/c/test_weapon.c diff --git a/src/c/weapon.c b/src/c/weapon.c new file mode 100644 index 0000000..3524f59 --- /dev/null +++ b/src/c/weapon.c @@ -0,0 +1,5 @@ +#include "weapon.h" + +char *getName(Weapon *weapon){ + return weapon->name; +} \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h new file mode 100644 index 0000000..895dac2 --- /dev/null +++ b/src/c/weapon.h @@ -0,0 +1,21 @@ +#ifndef WEAPON_H +#define WEAPON_H + +#include +#include +#include +#include + +typedef struct +{ + int id; + char *fullName; + char *name; + int damageModifier; + int baseDamage; + bool canBeUsed; +} Weapon; + +char *getName(Weapon *weapon); + +#endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c new file mode 100644 index 0000000..4280c9c --- /dev/null +++ b/test/c/test_weapon.c @@ -0,0 +1,34 @@ +#ifdef TEST + +#include "unity.h" +#include "weapon.h" + +void setUp(void) +{ + +} + +void tearDown(void) +{ +} + + +void test_getName(void) +{ + // arrange + char *nameOfWeapon = "Kukri", *result; + Weapon test; + test.name = nameOfWeapon; + + /* act */ + // Die Funktion wird ausgeführt + result = getName(&test); + + // output + printf("getName | name should be: %s -> is: %s", nameOfWeapon, result); + + // assert + TEST_ASSERT_EQUAL(nameOfWeapon, result); +} + +#endif // TEST From ff33db459dc533a7044a1ea78bd0b2ee5ca16a1a Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:05:29 +0100 Subject: [PATCH 40/51] added setName with test --- src/c/weapon.c | 4 ++++ src/c/weapon.h | 4 ++++ test/c/test_weapon.c | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/c/weapon.c b/src/c/weapon.c index 3524f59..5c7caba 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -2,4 +2,8 @@ char *getName(Weapon *weapon){ return weapon->name; +} + +void setName(Weapon *weapon, char *nameToSet){ + weapon->name = nameToSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 895dac2..c978816 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -11,11 +11,15 @@ typedef struct int id; char *fullName; char *name; + int typeID; + char *typeName; int damageModifier; int baseDamage; bool canBeUsed; } Weapon; char *getName(Weapon *weapon); +void setName(Weapon *weapon, char *nameToSet); + #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 4280c9c..145d98f 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -5,14 +5,12 @@ void setUp(void) { - } void tearDown(void) { } - void test_getName(void) { // arrange @@ -31,4 +29,21 @@ void test_getName(void) TEST_ASSERT_EQUAL(nameOfWeapon, result); } +void test_setName(void) +{ + // arrange + char *nameWeapon = "switchblade", *result; + + // act + Weapon test; + setName(&test, nameWeapon); + result = test.name; + + // output + printf("setName | name set to: %s -> after set: %s", nameWeapon, result); + + // assert + TEST_ASSERT_EQUAL(nameWeapon, result); +} + #endif // TEST From 72ea0de711353db98d54bf01c2c513f5edb66d4b Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:06:09 +0100 Subject: [PATCH 41/51] added getFullname with test --- src/c/weapon.c | 4 ++++ src/c/weapon.h | 1 + test/c/test_weapon.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index 5c7caba..50d8692 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -6,4 +6,8 @@ char *getName(Weapon *weapon){ void setName(Weapon *weapon, char *nameToSet){ weapon->name = nameToSet; +} + +char *getFullName(Weapon *weapon){ + return weapon->fullName; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index c978816..9f1febc 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -21,5 +21,6 @@ typedef struct char *getName(Weapon *weapon); void setName(Weapon *weapon, char *nameToSet); +char *getFullName(Weapon *weapon); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 145d98f..bb24bd3 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -46,4 +46,22 @@ void test_setName(void) TEST_ASSERT_EQUAL(nameWeapon, result); } +void test_getFullName(void) +{ + // arrange + char *nameOfWeapon = "Kukri v2", *result; + Weapon test; + test.fullName = nameOfWeapon; + + /* act */ + // Die Funktion wird ausgeführt + result = getFullName(&test); + + // output + printf("getFullName | fullName should be: %s -> is: %s", nameOfWeapon, result); + + // assert + TEST_ASSERT_EQUAL(nameOfWeapon, result); +} + #endif // TEST From 517f0cfafe1233c82e2aac4ac7ee8989c04ac7f4 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:06:38 +0100 Subject: [PATCH 42/51] added setFullName with test --- src/c/weapon.c | 14 +++++++++++--- src/c/weapon.h | 1 + test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/c/weapon.c b/src/c/weapon.c index 50d8692..a506bb9 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -1,13 +1,21 @@ #include "weapon.h" -char *getName(Weapon *weapon){ +char *getName(Weapon *weapon) +{ return weapon->name; } -void setName(Weapon *weapon, char *nameToSet){ +void setName(Weapon *weapon, char *nameToSet) +{ weapon->name = nameToSet; } -char *getFullName(Weapon *weapon){ +char *getFullName(Weapon *weapon) +{ return weapon->fullName; +} + +void setFullName(Weapon *weapon, char *fullNameToSet) +{ + weapon->fullName = fullNameToSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 9f1febc..86d4209 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -22,5 +22,6 @@ char *getName(Weapon *weapon); void setName(Weapon *weapon, char *nameToSet); char *getFullName(Weapon *weapon); +void setFullName(Weapon *weapon, char *fullNameToSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index bb24bd3..0998f6f 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -64,4 +64,21 @@ void test_getFullName(void) TEST_ASSERT_EQUAL(nameOfWeapon, result); } +void test_setFullName(void) +{ + // arrange + char *fullNameWeapon = "switchblade v2", *result; + + // act + Weapon test; + setFullName(&test, fullNameWeapon); + result = test.fullName; + + // output + printf("setFullName | fullName set to: %s -> after set: %s", fullNameWeapon, result); + + // assert + TEST_ASSERT_EQUAL(fullNameWeapon, result); +} + #endif // TEST From 584b48ee4eee0f737ef1c64dd5196dab976abb38 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:07:18 +0100 Subject: [PATCH 43/51] added getTypeID with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 2 ++ test/c/test_weapon.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index a506bb9..ccc980d 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -18,4 +18,9 @@ char *getFullName(Weapon *weapon) void setFullName(Weapon *weapon, char *fullNameToSet) { weapon->fullName = fullNameToSet; +} + +int getTypeID(Weapon *weapon) +{ + return weapon->typeID; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 86d4209..54110b4 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -24,4 +24,6 @@ void setName(Weapon *weapon, char *nameToSet); char *getFullName(Weapon *weapon); void setFullName(Weapon *weapon, char *fullNameToSet); +int getTypeID(Weapon *weapon); + #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 0998f6f..9599e3b 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -81,4 +81,22 @@ void test_setFullName(void) TEST_ASSERT_EQUAL(fullNameWeapon, result); } +void test_getTypeID(void) +{ + // arrange + int type = 1, result; + Weapon test; + test.typeID = type; + + /* act */ + // Die Funktion wird ausgeführt + result = getTypeID(&test); + + // output + printf("getTypeID | typeID should be: %d -> is: %d", type, result); + + // assert + TEST_ASSERT_EQUAL(type, result); +} + #endif // TEST From 9410e3395eb7680dda7c6e8b0fc9c6871117cc06 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:07:45 +0100 Subject: [PATCH 44/51] added setTypeID with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 1 + test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index ccc980d..adfb91e 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -23,4 +23,9 @@ void setFullName(Weapon *weapon, char *fullNameToSet) int getTypeID(Weapon *weapon) { return weapon->typeID; +} + +void setTypeID(Weapon *weapon, int typeToSet) +{ + weapon->typeID = typeToSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 54110b4..32172df 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -25,5 +25,6 @@ char *getFullName(Weapon *weapon); void setFullName(Weapon *weapon, char *fullNameToSet); int getTypeID(Weapon *weapon); +void setTypeID(Weapon *weapon, int typeToSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 9599e3b..2643f7b 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -99,4 +99,21 @@ void test_getTypeID(void) TEST_ASSERT_EQUAL(type, result); } +void test_setTypeID(void) +{ + // arrange + int type = 2, result; + + // act + Weapon test; + setTypeID(&test, type); + result = test.typeID; + + // output + printf("setTypeID | typeID set to: %d -> after set: %d", type, result); + + // assert + TEST_ASSERT_EQUAL(type, result); +} + #endif // TEST From 8615b3e13647f7a4946d6cfd97345925101b53bb Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:08:32 +0100 Subject: [PATCH 45/51] added getDamageModifier with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 4 ++++ test/c/test_weapon.c | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index adfb91e..8d34e27 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -28,4 +28,9 @@ int getTypeID(Weapon *weapon) void setTypeID(Weapon *weapon, int typeToSet) { weapon->typeID = typeToSet; +} + +int getDamageModifier(Weapon *weapon) +{ + return weapon->damageModifier; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 32172df..4693398 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -27,4 +27,8 @@ void setFullName(Weapon *weapon, char *fullNameToSet); int getTypeID(Weapon *weapon); void setTypeID(Weapon *weapon, int typeToSet); +//typeName placeholder + +int getDamageModifier(Weapon *weapon); + #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 2643f7b..db8830e 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -116,4 +116,22 @@ void test_setTypeID(void) TEST_ASSERT_EQUAL(type, result); } +void test_getDamageModifier(void) +{ + // arrange + int damageModifier = 2, result; + Weapon test; + test.damageModifier = damageModifier; + + /* act */ + // Die Funktion wird ausgeführt + result = getDamageModifier(&test); + + // output + printf("getDamageModifier | damageModifier should be: %d -> is: %d", damageModifier, result); + + // assert + TEST_ASSERT_EQUAL(damageModifier, result); +} + #endif // TEST From 242188e5ada28a268bb1c6aa457ac99faff9476a Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:09:08 +0100 Subject: [PATCH 46/51] added setDamageModifier with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 1 + test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index 8d34e27..a2f7add 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -33,4 +33,9 @@ void setTypeID(Weapon *weapon, int typeToSet) int getDamageModifier(Weapon *weapon) { return weapon->damageModifier; +} + +void setDamageModifier(Weapon *weapon, int modifierSet) +{ + weapon->damageModifier = modifierSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 4693398..ff6e1de 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -30,5 +30,6 @@ void setTypeID(Weapon *weapon, int typeToSet); //typeName placeholder int getDamageModifier(Weapon *weapon); +void setDamageModifier(Weapon *weapon, int modifierSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index db8830e..56e0cb4 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -134,4 +134,21 @@ void test_getDamageModifier(void) TEST_ASSERT_EQUAL(damageModifier, result); } +void test_setDamageModifier(void) +{ + // arrange + int damageModifier = 5, result; + + // act + Weapon test; + setDamageModifier(&test, damageModifier); + result = test.damageModifier; + + // output + printf("setDamageModifier | damageModifier set to: %d -> after set: %d", damageModifier, result); + + // assert + TEST_ASSERT_EQUAL(damageModifier, result); +} + #endif // TEST From 66206804a302420e27428b7dc0b5bf96229124bc Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:09:38 +0100 Subject: [PATCH 47/51] added getBaseDamage with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 2 ++ test/c/test_weapon.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index a2f7add..c3f5cfc 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -38,4 +38,9 @@ int getDamageModifier(Weapon *weapon) void setDamageModifier(Weapon *weapon, int modifierSet) { weapon->damageModifier = modifierSet; +} + +int getBaseDamage(Weapon *weapon) +{ + return weapon->baseDamage; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index ff6e1de..0e11197 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -32,4 +32,6 @@ void setTypeID(Weapon *weapon, int typeToSet); int getDamageModifier(Weapon *weapon); void setDamageModifier(Weapon *weapon, int modifierSet); +int getBaseDamage(Weapon *weapon); + #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 56e0cb4..4984557 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -151,4 +151,22 @@ void test_setDamageModifier(void) TEST_ASSERT_EQUAL(damageModifier, result); } +void test_getBaseDamage(void) +{ + // arrange + int baseDamage = 10, result; + Weapon test; + test.baseDamage = baseDamage; + + /* act */ + // Die Funktion wird ausgeführt + result = getBaseDamage(&test); + + // output + printf("getBaseDamage | baseDamage should be: %d -> is: %d", baseDamage, result); + + // assert + TEST_ASSERT_EQUAL(baseDamage, result); +} + #endif // TEST From ea62efd46138f0552394b691f361906e49817c9a Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:10:16 +0100 Subject: [PATCH 48/51] added setBaseDamage with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 3 ++- test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/c/weapon.c b/src/c/weapon.c index c3f5cfc..99c6fce 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -43,4 +43,9 @@ void setDamageModifier(Weapon *weapon, int modifierSet) int getBaseDamage(Weapon *weapon) { return weapon->baseDamage; +} + +void setBaseDamage(Weapon *weapon, int baseDmgSet) +{ + weapon->baseDamage = baseDmgSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 0e11197..4149a10 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -27,11 +27,12 @@ void setFullName(Weapon *weapon, char *fullNameToSet); int getTypeID(Weapon *weapon); void setTypeID(Weapon *weapon, int typeToSet); -//typeName placeholder +// typeName placeholder int getDamageModifier(Weapon *weapon); void setDamageModifier(Weapon *weapon, int modifierSet); int getBaseDamage(Weapon *weapon); +void setBaseDamage(Weapon *weapon, int baseDmgSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 4984557..241c481 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -169,4 +169,21 @@ void test_getBaseDamage(void) TEST_ASSERT_EQUAL(baseDamage, result); } +void test_setBaseDamage(void) +{ + // arrange + int baseDamage = 43, result; + + // act + Weapon test; + setBaseDamage(&test, baseDamage); + result = test.baseDamage; + + // output + printf("setBaseDamage | baseDamage set to: %d -> after set: %d", baseDamage, result); + + // assert + TEST_ASSERT_EQUAL(baseDamage, result); +} + #endif // TEST From 766ac86c7e847c6e170baccafb07c0e2fddae43b Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:11:00 +0100 Subject: [PATCH 49/51] added getAvailable (canBeUsed) with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 3 +++ test/c/test_weapon.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/c/weapon.c b/src/c/weapon.c index 99c6fce..ddb66e8 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -48,4 +48,9 @@ int getBaseDamage(Weapon *weapon) void setBaseDamage(Weapon *weapon, int baseDmgSet) { weapon->baseDamage = baseDmgSet; +} + +bool getAvailable(Weapon *weapon) +{ + return weapon->canBeUsed; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 4149a10..cbc0661 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -35,4 +35,7 @@ void setDamageModifier(Weapon *weapon, int modifierSet); int getBaseDamage(Weapon *weapon); void setBaseDamage(Weapon *weapon, int baseDmgSet); +bool getAvailable(Weapon *weapon); + + #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 241c481..8f23f5b 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -186,4 +186,22 @@ void test_setBaseDamage(void) TEST_ASSERT_EQUAL(baseDamage, result); } +void test_getAvailable(void) +{ + // arrange + bool canBeUsed = true, result; + Weapon test; + test.canBeUsed = canBeUsed; + + /* act */ + // Die Funktion wird ausgeführt + result = getAvailable(&test); + + // output + printf("getAvailable | canBeUsed should be: %d -> is: %d", canBeUsed, result); + + // assert + TEST_ASSERT_EQUAL(canBeUsed, result); +} + #endif // TEST From 7617bb7f51399396e21563e4b1cb550277a29ac5 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:11:47 +0100 Subject: [PATCH 50/51] added setAvailable (canBeUsed) with test --- src/c/weapon.c | 5 +++++ src/c/weapon.h | 2 +- test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/c/weapon.c b/src/c/weapon.c index ddb66e8..a29d223 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -53,4 +53,9 @@ void setBaseDamage(Weapon *weapon, int baseDmgSet) bool getAvailable(Weapon *weapon) { return weapon->canBeUsed; +} + +void setAvailable(Weapon *weapon, bool availableSet) +{ + weapon->canBeUsed = availableSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index cbc0661..d016ec9 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -36,6 +36,6 @@ int getBaseDamage(Weapon *weapon); void setBaseDamage(Weapon *weapon, int baseDmgSet); bool getAvailable(Weapon *weapon); - +void setAvailable(Weapon *weapon, bool availableSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index 8f23f5b..609aa62 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -204,4 +204,21 @@ void test_getAvailable(void) TEST_ASSERT_EQUAL(canBeUsed, result); } +void test_setAvailable(void) +{ + // arrange + bool canBeUsed = false, result; + + // act + Weapon test; + setAvailable(&test, canBeUsed); + result = test.canBeUsed; + + // output + printf("setAvailable | canBeUsed set to: %d -> after set: %d", canBeUsed, result); + + // assert + TEST_ASSERT_EQUAL(canBeUsed, result); +} + #endif // TEST From ad46f8aadf23b56a32ff52d261e847cba6a859a4 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:17:02 +0100 Subject: [PATCH 51/51] updated --- run_test_display_gcov.sh | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 run_test_display_gcov.sh diff --git a/run_test_display_gcov.sh b/run_test_display_gcov.sh old mode 100644 new mode 100755 index 3926413..1a2bfb2 --- a/run_test_display_gcov.sh +++ b/run_test_display_gcov.sh @@ -1,3 +1,4 @@ +ls #Small scirpt to run the tests and generate the coverage report #cleans artifacts before building date