diff --git a/build/artifacts/release/Paper-Bin.out b/build/artifacts/release/Paper-Bin.out index 0dfb638..68629c5 100644 Binary files a/build/artifacts/release/Paper-Bin.out and b/build/artifacts/release/Paper-Bin.out differ diff --git a/build/release/Paper-Bin.out b/build/release/Paper-Bin.out index 0dfb638..68629c5 100755 Binary files a/build/release/Paper-Bin.out and b/build/release/Paper-Bin.out differ diff --git a/build/release/dependencies/Modules.d b/build/release/dependencies/Modules.d new file mode 100644 index 0000000..ee9ad08 --- /dev/null +++ b/build/release/dependencies/Modules.d @@ -0,0 +1 @@ +build/release/out/c/Modules.o: src/Modules.c src/Modules.h diff --git a/build/release/dependencies/Paper-Bin.d b/build/release/dependencies/Paper-Bin.d index fcf9657..f75fa1b 100644 --- a/build/release/dependencies/Paper-Bin.d +++ b/build/release/dependencies/Paper-Bin.d @@ -1 +1 @@ -build/release/out/c/Paper-Bin.o: src/Paper-Bin.c src/Paper-Bin.h +build/release/out/c/Paper-Bin.o: src/Paper-Bin.c diff --git a/build/release/out/c/Modules.o b/build/release/out/c/Modules.o new file mode 100644 index 0000000..48b49dd Binary files /dev/null and b/build/release/out/c/Modules.o differ diff --git a/build/release/out/c/Paper-Bin.o b/build/release/out/c/Paper-Bin.o index a3a5e70..aa3ab9d 100644 Binary files a/build/release/out/c/Paper-Bin.o and b/build/release/out/c/Paper-Bin.o differ diff --git a/build/test/cache/defines_dependency.yml b/build/test/cache/defines_dependency.yml index e0af8f0..b8b55c1 100644 --- a/build/test/cache/defines_dependency.yml +++ b/build/test/cache/defines_dependency.yml @@ -1,3 +1,5 @@ --- src/Paper-Bin.c: - TEST +src/Modules.c: +- TEST diff --git a/build/test/cache/test_Modules.c b/build/test/cache/test_Modules.c new file mode 100644 index 0000000..9b147a2 --- /dev/null +++ b/build/test/cache/test_Modules.c @@ -0,0 +1,53 @@ +#include "src/Modules.c" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_checkBallPosition_output(void) + +{ + + binX = 1; + + binY = 1; + + + + ballX = 1; + + ballY = 3; + + + + int output = checkBallPosition(); + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((output)), ( + + ((void *)0) + + ), (UNITY_UINT)(25), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/dependencies/test_Modules.d b/build/test/dependencies/test_Modules.d new file mode 100644 index 0000000..f50dfb8 --- /dev/null +++ b/build/test/dependencies/test_Modules.d @@ -0,0 +1,4 @@ +build/test/out/c/test_Modules.o: test/test_Modules.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/Modules.c src/Modules.h diff --git a/build/test/dependencies/test_Modules_runner.d b/build/test/dependencies/test_Modules_runner.d new file mode 100644 index 0000000..627119f --- /dev/null +++ b/build/test/dependencies/test_Modules_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_Modules_runner.o: \ + build/test/runners/test_Modules_runner.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/out/c/test_Modules.o b/build/test/out/c/test_Modules.o new file mode 100644 index 0000000..4ab2f72 Binary files /dev/null and b/build/test/out/c/test_Modules.o differ diff --git a/build/test/out/c/test_Modules_runner.o b/build/test/out/c/test_Modules_runner.o new file mode 100644 index 0000000..e3200a7 Binary files /dev/null and b/build/test/out/c/test_Modules_runner.o differ diff --git a/build/test/out/test_Modules.out b/build/test/out/test_Modules.out new file mode 100755 index 0000000..b839f08 Binary files /dev/null and b/build/test/out/test_Modules.out differ diff --git a/build/test/preprocess/files/test_Modules.c b/build/test/preprocess/files/test_Modules.c new file mode 100644 index 0000000..9b147a2 --- /dev/null +++ b/build/test/preprocess/files/test_Modules.c @@ -0,0 +1,53 @@ +#include "src/Modules.c" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_checkBallPosition_output(void) + +{ + + binX = 1; + + binY = 1; + + + + ballX = 1; + + ballY = 3; + + + + int output = checkBallPosition(); + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((output)), ( + + ((void *)0) + + ), (UNITY_UINT)(25), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/includes/test_Modules.c b/build/test/preprocess/includes/test_Modules.c new file mode 100644 index 0000000..892d7b6 --- /dev/null +++ b/build/test/preprocess/includes/test_Modules.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/Modules.c diff --git a/build/test/results/test_Modules.pass b/build/test/results/test_Modules.pass new file mode 100644 index 0000000..f0fb63a --- /dev/null +++ b/build/test/results/test_Modules.pass @@ -0,0 +1,18 @@ +--- +:source: + :path: test + :file: test_Modules.c +:successes: +- :test: test_checkBallPosition_output + :line: 15 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0006377379995683441 diff --git a/build/test/runners/test_Modules_runner.c b/build/test/runners/test_Modules_runner.c new file mode 100644 index 0000000..21a9be4 --- /dev/null +++ b/build/test/runners/test_Modules_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_checkBallPosition_output(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +void verifyTest(void) +{ + CMock_Verify(); +} + +/*=======Test Runner Used To Run Each Test=====*/ +static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num) +{ + Unity.CurrentTestName = name; + Unity.CurrentTestLineNumber = line_num; +#ifdef UNITY_USE_COMMAND_LINE_ARGS + if (!UnityTestMatches()) + return; +#endif + Unity.NumberOfTests++; + UNITY_CLR_DETAILS(); + UNITY_EXEC_TIME_START(); + CMock_Init(); + if (TEST_PROTECT()) + { + setUp(); + func(); + } + if (TEST_PROTECT()) + { + tearDown(); + CMock_Verify(); + } + CMock_Destroy(); + UNITY_EXEC_TIME_STOP(); + UnityConcludeTest(); +} + +/*=======MAIN=====*/ +int main(void) +{ + UnityBegin("test_Modules.c"); + run_test(test_checkBallPosition_output, "test_checkBallPosition_output", 15); + + return UnityEnd(); +} diff --git a/src/Modules.c b/src/Modules.c new file mode 100644 index 0000000..17f5cc2 --- /dev/null +++ b/src/Modules.c @@ -0,0 +1,334 @@ +#include +#include +#include "Modules.h" + + +// Methode, die den Eimer erstellt +void buildBin(int width, int heigth) +{ + field[width][heigth] = 'V'; + field[width + 1][heigth + 1] = '\\'; + field[width + 2][heigth + 2] = '\\'; + field[width - 1][heigth + 1] = '/'; + field[width - 2][heigth + 2] = '/'; + field[width][heigth + 1] = ' '; +} + +void loadLevel(int lvlNum) +{ + clearField(); + ballX = -1; + ballY = 27; + + int tmpX; + int tmpY; + + switch (lvlNum) + { + // Level 1: Nur der Korb wird erstellt + case (1): + binX = 12; + binY = 10; + break; + + // Level 2-6: Zufällige Positionen für den Korb hinzugefügt + case (2): + case (3): + case (4): + case (5): + case (6): + tmpX = rand() % 19; + tmpY = rand() % 12; + while (5 > tmpX) + { + tmpX = rand() % 19; + } + while (5 > tmpY) + { + tmpY = rand() % 12; + } + binX = tmpX; + binY = tmpY; + break; + + // Wind wird dem Level 7 & 8 hinzugefügt + case (7): + binX = 2; + binY = 7; + windForce = -2; + printf("Ein Sturm zieht auf!\n"); + sleep(3); + break; + + case (8): + binX = 19; + binY = 7; + windForce = 1; + break; + + // Wände erscheinen jetzt in den Leveln 9 & 10 + case (9): + windForce = -1; + binX = 8; + binY = 9; + wallX = 7; + wallLength = 4; + wallY = 17; + break; + + case (10): + windForce = 2; + binX = 16; + binY = 12; + wallX = 11; + wallLength = 4; + wallY = 19; + break; + // Abschluss aller Level + case (11): + system("clear"); + generateField(); + addScoreboard(); + sortScoreboard(); + exit(0); + break; + + default: + exit(0); + } + + getStartPosition(); + printf("Der Ball wird geworfen!!!"); + sleep(1); +} + +int start() +{ + loadLevel(lvlNumber); + while (1) + { + clearField(); + field[ballX][ballY -= 1] = 'O'; + generateField(); + int ball_In_Bin = checkBallPosition(); + + switch (ball_In_Bin) + { + case (1): + scorePoints += 50; + loadLevel(++lvlNumber); + break; + + case (2): + scorePoints -= 5; + lifeCount--; + if (lifeCount < 1) + { + if (lvlNumber == 1) + { + char choice = ' '; + printf("Scheint so, als wäre das Spiel eine Nummer zu groß für dich!\n"); + printf("Willst du einen leichteren Modus starten?\n[J]a/[N]ein\n"); + scanf(" %c", &choice); + system("start \"\" \"https://youtu.be/dQw4w9WgXcQ\""); + return 0; + } + addScoreboard(); + sortScoreboard(); + return 0; + } + loadLevel(lvlNumber); + break; + } + ball_In_Bin = 0; + sleep(1); + } +} + +void getStartPosition() +{ + while (ballX == -1) + { + for (int i = 2, j = 0; i <= 20; i += 2, j++) + { + field[i][ballY] = j + '0'; + } + generateField(); + + printf("Wähle die Position des Balls (0-9):\n"); + + scanf("%d", &ballX); + + if (ballX < 0 || 9 < ballX) + { + ballX = -1; + continue; + } + ballX = (ballX + 1) * 2; + } +} + +void clearField() +{ + for (int i = 0; i < fieldWidth; i++) + { + for (int j = 0; j < fieldHeigth; j++) + { + field[i][j] = ' '; + } + } +} + +void generateField() +{ + system("clear"); + buildBin(binX, binY); + + if (scorePoints < 0) + scorePoints = 0; + + // Hier wird Stück für Stück die Zahl aufgeteilt, um alle + // einzelnen Stellen in das Feld einzutragen + int tmp = scorePoints; + field[12][1] = '0' + tmp % 10; + + tmp /= 10; + field[11][1] = '0' + tmp % 10; + + tmp /= 10; + field[10][1] = '0' + tmp % 10; + + field[1][1] = lifeCount < 1 ? 'X' : 'O'; + field[2][1] = lifeCount < 2 ? 'X' : 'O'; + field[3][1] = lifeCount < 3 ? 'X' : 'O'; + + if (windForce != 0) + { + field[19][1] = windForce < 0 ? '<' : '>'; + field[20][1] = windForce < 0 ? (windForce * -1 + '0') : (windForce + '0'); + } + + if (wallX > 0 && wallY > 0 && wallLength > 0) + { + for (int i = wallX; i < +wallX + wallLength; i++) + { + field[i][wallY] = '_'; + } + } + + if (lvlNumber > 6 && windIntervall % 2 == 0) + { + windForce < 0 ? (ballX -= windForce * -1) : (ballX += windForce); + } + windIntervall++; + + for (int i = 0; i < fieldHeigth; i++) + { + printf("|"); + for (int j = 0; j < fieldWidth; j++) + { + if (i == 0 || i == fieldHeigth - 1 || i == 2) + printf("="); + else + printf("%c", field[j][i]); + } + printf("|"); + printf("\n"); + } +} + +void addScoreboard() +{ + // Die .txt wird geöffnet + FILE *fp = fopen("ScoreBoard.txt", "a+"); + char name[255]; + + // Liest den eingegebenen Namen ein + printf("Bitte gib deinen Namen ein:\n"); + scanf("%s", name); + + // Schreibt den Namen und die erreichten Punkte in die Textdatei + fprintf(fp, "%s %d\n", name, scorePoints); + fclose(fp); +} +// Checkt Position vom Ball +int checkBallPosition() +{ + // Bei einem Tor gibt es eine 1 zurück + if (binY + 2 == ballY && (ballX == binX || ballX == binX + 1 || ballX == binX - 1)) + { + return 1; + } + // Wenn der Ball daneben fliegt, gibt es eine 2 zurück + else if (binY + 1 >= ballY || field[ballX][ballY - 1] == '_' || ballX >= fieldWidth || ballX <= 0) + { + return 2; + } + return 0; +} + +void sortScoreboard() +{ + // Öffnet die Textdatei oder erstellt sie, wenn keine existiert + FILE *fp; + fp = fopen("ScoreBoard.txt", "a+"); + // Gibt eine Fehlermeldung, falls die Textdatei nicht existiert + if (fp == NULL) + { + printf("Datei konnte nicht geöffnet werden.\n"); + } + else + { + system("clear"); + // Öffnet die Textdatei + FILE *file = fopen("ScoreBoard.txt", "r"); + char line[1000]; + int numberOfLines = 0; + // Die Textdatei wird Zeile für Zeile eingelesen und in die Strukturliste eingefügt + for (int j = 0; fgets(line, sizeof line, file) != NULL && j <= 10; j++) + { + char *playerTmp = strtok(line, " "); + strcpy(playerList[j].name, playerTmp); + + playerTmp = strtok(NULL, " "); + int playerPoints = atoi(playerTmp); + + playerList[j].points = playerPoints; + + numberOfLines = j; + sleep(0.1); + } + + // Spielerliste mithilfe einer Hilfsveriable sortieren, um sie danach direkt ausgeben zu können + struct Player tmp; + for (int i = 0; i < numberOfLines; i++) + { + for (int j = 0; j < (numberOfLines - i); j++) + { + if (playerList[i].points < playerList[i + 1].points) + { + tmp = playerList[i]; + playerList[i] = playerList[i + 1]; + playerList[i + 1] = tmp; + } + } + } + + fclose(fp); + // Listet die höchsten Scores in der Konsole auf + printf(" Scoreboard:\n\n"); + for (int j = 0; j < numberOfLines; j++) + { + printf("%d. %s %s %d\n", j + 1, (j < 9) ? " " : " ", playerList[j].name, playerList[j].points); + sleep(0.5); + } + + FILE *fp = fopen("ScoreBoard.txt", "w"); + for (int i = 0; i < numberOfLines; i++) + { + fprintf(fp, "%s %d\n", playerList[i].name, playerList[i].points); + } + + fclose(fp); + } +} \ No newline at end of file diff --git a/src/Modules.h b/src/Modules.h new file mode 100644 index 0000000..4d9533d --- /dev/null +++ b/src/Modules.h @@ -0,0 +1,48 @@ +#ifndef PAPER_BIN_H +#define PAPER_BIN_H + +// Spielfeldbreite und Spielfeldhöhe werden definiert +#define fieldWidth 23 +#define fieldHeigth 29 + +#pragma region VarDeclaration + +// Vertikale Startposition der Wand im Array +int wallX = 0; +// Horizontale Startposition der Wand im Array +int wallY = 0; +// Wandlänge, um Wände von der Startposition aus in das Array für das Spielfeld eintragen zu können +int wallLength = 0; +int binX; +int binY = 10; + +char field[fieldWidth][fieldHeigth]; +int windForce = 0; +int scorePoints = 0; + +int lifeCount = 3; +// Die Variablen, die die Positionierung des Balls festlegen +int ballX = -1; +int ballY = 27; +int windIntervall = 0; +int lvlNumber = 1; + +void addScoreboard(); +void clearField(); +void generateField(); +void sortScoreboard(); +void buildBin(int width, int height); +void getStartPosition(); +int checkBallPosition(); + + + +// Ein struct für den Spieler erstellt, um +// jedem Spieler seinen Score zuweisen zu können +struct Player +{ + char name[50]; + int points; +} playerList[11]; + +#endif // PAPER_BIN_H diff --git a/src/Paper-Bin.c b/src/Paper-Bin.c index a3080d8..e9503cc 100644 --- a/src/Paper-Bin.c +++ b/src/Paper-Bin.c @@ -1,381 +1,7 @@ #include -#include -#include "Paper-Bin.h" -//Spielfeldbreite und Spielfeldhöhe werden definiert -#define fieldWidth 23 -#define fieldHeigth 29 - -#pragma region VarDeclaration - -//Vertikale Startposition der Wand im Array -int wallX = 0; -//Horizontale Startposition der Wand im Array -int wallY = 0; -//Wandlänge, um Wände von der Startposition aus in das Array für das Spielfeld eintragen zu können -int wallLength = 0; -int binX; -int binY = 10; - -char field[fieldWidth][fieldHeigth]; -int windForce = 0; -int scorePoints = 0; - -int lifeCount = 3; -//Die Variablen, die die Positionierung des Balls festlegen -int ballX = -1; -int ballY = 27; -int windIntervall = 0; -int lvlNumber = 1; - -#pragma endregion - -#pragma region FunctionDeclaration - -void addScoreboard(); -void clearField(); -void generateField(); -void sortScoreboard(); -void buildBin(int width, int height); -void getStartPosition(); -int checkBallPosition(); - -#pragma endregion - -//Ein struct für den Spieler erstellt, um -//jedem Spieler seinen Score zuweisen zu können -struct Player -{ - char name[50]; - int points; -} playerList[11]; - -//Methode, die den Eimer erstellt -void buildBin(int width, int heigth) -{ - field[width][heigth] = 'V'; - field[width + 1][heigth + 1] = '\\'; - field[width + 2][heigth + 2] = '\\'; - field[width - 1][heigth + 1] = '/'; - field[width - 2][heigth + 2] = '/'; - field[width][heigth + 1] = ' '; -} - -void loadLevel(int lvlNum) -{ - clearField(); - ballX = -1; - ballY = 27; - - int tmpX; - int tmpY; - - switch (lvlNum) - { - //Level 1: Nur der Korb wird erstellt - case (1): - binX = 12; - binY = 10; - break; - - //Level 2-6: Zufällige Positionen für den Korb hinzugefügt - case (2): - case (3): - case (4): - case (5): - case (6): - tmpX = rand() % 19; - tmpY = rand() % 12; - while (5 > tmpX) - { - tmpX = rand() % 19; - } - while (5 > tmpY) - { - tmpY = rand() % 12; - } - binX = tmpX; - binY = tmpY; - break; - - //Wind wird dem Level 7 & 8 hinzugefügt - case (7): - binX = 2; - binY = 7; - windForce = -2; - printf("Ein Sturm zieht auf!\n"); - sleep(3); - break; - - case (8): - binX = 19; - binY = 7; - windForce = 1; - break; - - //Wände erscheinen jetzt in den Leveln 9 & 10 - case (9): - windForce = -1; - binX = 8; - binY = 9; - wallX = 7; - wallLength = 4; - wallY = 17; - break; - - case (10): - windForce = 2; - binX = 16; - binY = 12; - wallX = 11; - wallLength = 4; - wallY = 19; - break; - //Abschluss aller Level - case (11): - system("clear"); - generateField(); - addScoreboard(); - sortScoreboard(); - exit(0); - break; - - default: - exit(0); - } - - getStartPosition(); - printf("Der Ball wird geworfen!!!"); - sleep(1); -} int main() { - loadLevel(lvlNumber); - while (1) - { - clearField(); - field[ballX][ballY -= 1] = 'O'; - generateField(); - int ball_In_Bin = checkBallPosition(); - - switch (ball_In_Bin) - { - case (1): - scorePoints += 50; - loadLevel(++lvlNumber); - break; - - case (2): - scorePoints -= 5; - lifeCount--; - if (lifeCount < 1) - { - if (lvlNumber == 1) - { - char choice = ' '; - printf("Scheint so, als wäre das Spiel eine Nummer zu groß für dich!\n"); - printf("Willst du einen leichteren Modus starten?\n[J]a/[N]ein\n"); - scanf(" %c", &choice); - system("start \"\" \"https://youtu.be/dQw4w9WgXcQ\""); - return 0; - } - addScoreboard(); - sortScoreboard(); - return 0; - } - loadLevel(lvlNumber); - break; - } - ball_In_Bin = 0; - sleep(1); - } -} - -void getStartPosition() -{ - while (ballX == -1) - { - for (int i = 2, j = 0; i <= 20; i += 2, j++) - { - field[i][ballY] = j + '0'; - } - generateField(); - - printf("Wähle die Position des Balls (0-9):\n"); - - scanf("%d", &ballX); - - if (ballX < 0 || 9 < ballX) - { - ballX = -1; - continue; - } - ballX = (ballX + 1) * 2; - } + start(); } - -void clearField() -{ - for (int i = 0; i < fieldWidth; i++) - { - for (int j = 0; j < fieldHeigth; j++) - { - field[i][j] = ' '; - } - } -} - -void generateField() -{ - system("clear"); - buildBin(binX, binY); - - if (scorePoints < 0) - scorePoints = 0; - - //Hier wird Stück für Stück die Zahl aufgeteilt, um alle - //einzelnen Stellen in das Feld einzutragen - int tmp = scorePoints; - field[12][1] = '0' + tmp % 10; - - tmp /= 10; - field[11][1] = '0' + tmp % 10; - - tmp /= 10; - field[10][1] = '0' + tmp % 10; - - field[1][1] = lifeCount < 1 ? 'X' : 'O'; - field[2][1] = lifeCount < 2 ? 'X' : 'O'; - field[3][1] = lifeCount < 3 ? 'X' : 'O'; - - if (windForce != 0) - { - field[19][1] = windForce < 0 ? '<' : '>'; - field[20][1] = windForce < 0 ? (windForce * -1 + '0') : (windForce + '0'); - } - - if (wallX > 0 && wallY > 0 && wallLength > 0) - { - for (int i = wallX; i < +wallX + wallLength; i++) - { - field[i][wallY] = '_'; - } - } - - if (lvlNumber > 6 && windIntervall % 2 == 0) - { - windForce < 0 ? (ballX -= windForce * -1) : (ballX += windForce); - } - windIntervall++; - - for (int i = 0; i < fieldHeigth; i++) - { - printf("|"); - for (int j = 0; j < fieldWidth; j++) - { - if (i == 0 || i == fieldHeigth - 1 || i == 2) - printf("="); - else - printf("%c", field[j][i]); - } - printf("|"); - printf("\n"); - } -} - -void addScoreboard() -{ - //Die .txt wird geöffnet - FILE *fp = fopen("ScoreBoard.txt", "a+"); - char name[255]; - - //Liest den eingegebenen Namen ein - printf("Bitte gib deinen Namen ein:\n"); - scanf("%s", name); - - //Schreibt den Namen und die erreichten Punkte in die Textdatei - fprintf(fp, "%s %d\n", name, scorePoints); - fclose(fp); -} -//Checkt Position vom Ball -int checkBallPosition() -{ - //Bei einem Tor gibt es eine 1 zurück - if (binY + 2 == ballY && (ballX == binX || ballX == binX + 1 || ballX == binX - 1)) - { - return 1; - } - //Wenn der Ball daneben fliegt, gibt es eine 2 zurück - else if (binY + 1 >= ballY || field[ballX][ballY - 1] == '_' || ballX >= fieldWidth || ballX <= 0) - { - return 2; - } - return 0; -} - -void sortScoreboard() -{ - //Öffnet die Textdatei oder erstellt sie, wenn keine existiert - FILE *fp; - fp = fopen("ScoreBoard.txt", "a+"); - //Gibt eine Fehlermeldung, falls die Textdatei nicht existiert - if (fp == NULL) - { - printf("Datei konnte nicht geöffnet werden.\n"); - } - else - { - system("clear"); - //Öffnet die Textdatei - FILE *file = fopen("ScoreBoard.txt", "r"); - char line[1000]; - int numberOfLines = 0; - //Die Textdatei wird Zeile für Zeile eingelesen und in die Strukturliste eingefügt - for (int j = 0; fgets(line, sizeof line, file) != NULL && j <= 10; j++) - { - char* playerTmp = strtok(line, " "); - strcpy(playerList[j].name, playerTmp); - - playerTmp = strtok(NULL, " "); - int playerPoints = atoi(playerTmp); - - playerList[j].points = playerPoints; - - numberOfLines = j; - sleep(0.1); - } - - //Spielerliste mithilfe einer Hilfsveriable sortieren, um sie danach direkt ausgeben zu können - struct Player tmp; - for (int i = 0; i < numberOfLines; i++) - { - for (int j = 0; j < (numberOfLines - i); j++) - { - if (playerList[i].points < playerList[i + 1].points) - { - tmp = playerList[i]; - playerList[i] = playerList[i + 1]; - playerList[i + 1] = tmp; - } - } - } - - fclose(fp); - //Listet die höchsten Scores in der Konsole auf - printf(" Scoreboard:\n\n"); - for (int j = 0; j < numberOfLines; j++) - { - printf("%d. %s %s %d\n", j + 1, (j < 9) ? " " : " ", playerList[j].name, playerList[j].points); - sleep(0.5); - } - - FILE *fp = fopen("ScoreBoard.txt", "w"); - for (int i = 0; i < numberOfLines; i++) - { - fprintf(fp, "%s %d\n", playerList[i].name, playerList[i].points); - } - - fclose(fp); - } -} \ No newline at end of file diff --git a/src/Paper-Bin.h b/src/Paper-Bin.h deleted file mode 100644 index ee9ef8f..0000000 --- a/src/Paper-Bin.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef PAPER_BIN_H -#define PAPER_BIN_H - - -#endif // PAPER_BIN_H diff --git a/test/test_Modules.c b/test/test_Modules.c new file mode 100644 index 0000000..88d7524 --- /dev/null +++ b/test/test_Modules.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "Modules.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_dsadsa_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement dsadsa"); +} + +#endif // TEST diff --git a/test/test_Paper-Bin.c b/test/test_Paper-Bin.c deleted file mode 100644 index bd530d3..0000000 --- a/test/test_Paper-Bin.c +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef TEST - -#include "unity.h" - -#include "Paper-Bin.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_Paper_Bin_NeedToImplement(void) -{ - TEST_IGNORE_MESSAGE("Need to Implement Paper-Bin"); -} - -#endif // TEST