fdai7103
2 years ago
23 changed files with 623 additions and 401 deletions
-
BINbuild/artifacts/release/Paper-Bin.out
-
BINbuild/release/Paper-Bin.out
-
1build/release/dependencies/Modules.d
-
2build/release/dependencies/Paper-Bin.d
-
BINbuild/release/out/c/Modules.o
-
BINbuild/release/out/c/Paper-Bin.o
-
2build/test/cache/defines_dependency.yml
-
53build/test/cache/test_Modules.c
-
4build/test/dependencies/test_Modules.d
-
4build/test/dependencies/test_Modules_runner.d
-
BINbuild/test/out/c/test_Modules.o
-
BINbuild/test/out/c/test_Modules_runner.o
-
BINbuild/test/out/test_Modules.out
-
53build/test/preprocess/files/test_Modules.c
-
3build/test/preprocess/includes/test_Modules.c
-
18build/test/results/test_Modules.pass
-
81build/test/runners/test_Modules_runner.c
-
334src/Modules.c
-
48src/Modules.h
-
376src/Paper-Bin.c
-
5src/Paper-Bin.h
-
20test/test_Modules.c
-
20test/test_Paper-Bin.c
@ -0,0 +1 @@ |
|||
build/release/out/c/Modules.o: src/Modules.c src/Modules.h |
@ -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 |
@ -1,3 +1,5 @@ |
|||
--- |
|||
src/Paper-Bin.c: |
|||
- TEST |
|||
src/Modules.c: |
|||
- TEST |
@ -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); |
|||
|
|||
} |
@ -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 |
@ -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 |
@ -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); |
|||
|
|||
} |
@ -0,0 +1,3 @@ |
|||
--- |
|||
- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
- src/Modules.c |
@ -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 |
@ -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(); |
|||
} |
@ -0,0 +1,334 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#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); |
|||
} |
|||
} |
@ -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 |
@ -1,381 +1,7 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
} |
|||
|
|||
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); |
|||
} |
|||
start(); |
|||
} |
@ -1,5 +0,0 @@ |
|||
#ifndef PAPER_BIN_H |
|||
#define PAPER_BIN_H |
|||
|
|||
|
|||
#endif // PAPER_BIN_H |
@ -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 |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue