KaffeeMaus
11 months ago
7 changed files with 444 additions and 12 deletions
-
257src/main/c/Tim/SchereSteinPapier.c
-
3src/main/c/Tim/SchereSteinPapier.h
-
7src/main/c/Tim/hangman.c
-
6src/main/c/Tim/hangman.h
-
14src/main/c/main.c
-
145src/test/c/Tim/test_SchereSteinPapier.c
-
24src/test/c/Tim/test_hangman.c
@ -1,9 +1,260 @@ |
|||
#include "SchereSteinPapier.h" |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <time.h> |
|||
#include <string.h> |
|||
|
|||
void gameLoop(); |
|||
char* getWelcomeMessageSSP(); |
|||
int selectCOMChoice(); |
|||
void printResult(int, int, int); |
|||
int getuserSelection(); |
|||
|
|||
int schereSteinPapier() |
|||
|
|||
|
|||
void schereSteinPapier() |
|||
{ |
|||
srand(time(NULL)); |
|||
printf("%s", getWelcomeMessageSSP()); |
|||
gameLoop(); |
|||
} |
|||
|
|||
void gameLoop() |
|||
{ |
|||
printf("Test"); |
|||
return 1; |
|||
while(1) |
|||
{ |
|||
int comChoice, userChoice; |
|||
userChoice = getuserSelection(); |
|||
if(userChoice == 0) |
|||
{ |
|||
printf("Vielen Dank fuers Spielen! Tschau!\n"); |
|||
break; |
|||
} |
|||
else if(userChoice == 1 || userChoice == 2 || userChoice == 3) |
|||
{ |
|||
comChoice = selectCOMChoice(); |
|||
int winNum = calculateWinner(userChoice, comChoice); |
|||
printResult(winNum, comChoice, userChoice); |
|||
} |
|||
else |
|||
{ |
|||
printf("Deine eingegebene Wahl ist ungueltig\n"); |
|||
} |
|||
} |
|||
} |
|||
//Berechnung,welche Auswahl gewinnt. |
|||
//@return: 0 = unentschieden; 1 = gewonnen; -1 = verloren; 3 = Fehler bei der Wertuebergabe |
|||
//@param userSelection = UserChoice; comSelection = COMChoice |
|||
int calculateWinner(int userSelection, int comSelection) |
|||
{ |
|||
switch (userSelection) |
|||
{ |
|||
case(1): |
|||
switch (comSelection) { |
|||
case(1): return 0; |
|||
|
|||
case(2): return -1; |
|||
|
|||
case(3): return 1; |
|||
|
|||
default: return 3; |
|||
} |
|||
case(2): |
|||
switch (comSelection) { |
|||
case(1): return 1; |
|||
|
|||
case(2): return 0; |
|||
|
|||
case(3): return -1; |
|||
|
|||
default: return 3; |
|||
} |
|||
case(3): |
|||
switch (comSelection) { |
|||
case(1): return -1; |
|||
|
|||
case(2): return 1; |
|||
|
|||
case(3): return 0; |
|||
|
|||
default: return 3; |
|||
} |
|||
default: return 3; |
|||
} |
|||
|
|||
} |
|||
|
|||
int selectCOMChoice() |
|||
{ |
|||
return rand() % 3 + 1; |
|||
} |
|||
|
|||
int getuserSelection() |
|||
{ |
|||
int userSelect; |
|||
printf("Bitte treffe deine Wahl!\n" |
|||
"1: Schere \n2: Stein \n3: Papier\n0: Spiel verlassen\n"); |
|||
scanf("%d", &userSelect); |
|||
|
|||
return userSelect; |
|||
} |
|||
|
|||
char* getWelcomeMessageSSP() |
|||
{ |
|||
return "\nHallo und Willkommen zu\n\n" |
|||
" _____ _ _____ _____ _ \r\n" |
|||
" | __ \\ | | | __ \\ / ____| (_) \r\n" |
|||
" | |__) |___ ___| | __ | |__) |_ _ _ __ ___ _ __ | (___ ___ _ ___ ___ ___ _ __ ___ \r\n" |
|||
" | _ // _ \\ / __| |/ / | ___/ _` | '_ \\ / _ \\ '__| \\___ \\ / __| / __/ __|/ _ \\| '__/ __|\r\n" |
|||
" | | \\ \\ (_) | (__| < | | | (_| | |_) | __/ | ____) | (__| \\__ \\__ \\ (_) | | \\__ \\\r\n" |
|||
" |_| \\_\\___/ \\___|_|\\_\\ |_| \\__,_| .__/ \\___|_| |_____/ \\___|_|___/___/\\___/|_| |___/ \r\n" |
|||
" | | \r\n" |
|||
" |_| \n" |
|||
"credits to wynand1004\n\n" |
|||
"In diesem Spiel spielst du gegen einen COM Schere-Stein-Papier!\n" |
|||
"Waehle, sobald dich die Konsole dazu auffordert, deine 'Waffe' aus, indem du die entsprechende Zahl eintippst.\n" |
|||
"Gibst du bei der Aufforderung 0 ein, gelangst du zurueck ins Hauptmenue!\n\n"; |
|||
} |
|||
|
|||
void printResult(int winNumb, int comSelect, int userSelect) |
|||
{ |
|||
char comWeapon[10]; |
|||
switch(comSelect) |
|||
{ |
|||
case(1): |
|||
strcpy(comWeapon, "Schere"); |
|||
break; |
|||
case(2): |
|||
strcpy(comWeapon,"Stein"); |
|||
break; |
|||
case(3): |
|||
strcpy(comWeapon,"Papier"); |
|||
break; |
|||
default: |
|||
strcpy(comWeapon, "Not found"); |
|||
break; |
|||
} |
|||
if(userSelect == 1) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '---\n" |
|||
" ______) (______\n" |
|||
" __________) (__________\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Scissor vs Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ (____ '---\n" |
|||
" ______) (_____)\n" |
|||
" __________) (_____)\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Scissor vs Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '----\n" |
|||
" ______) (______\n" |
|||
" __________) (_______\n" |
|||
" (____) (_______\n" |
|||
"---.__(___) (_________.---\n" |
|||
" Scissor vs Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else if(userSelect ==2) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____) ____(____ '---\n" |
|||
" (_____) (______\n" |
|||
" (_____) (__________\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Rock VS Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____) (____ '---\n" |
|||
" (_____) (_____)\n" |
|||
" (_____) (_____)\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Rock VS Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____) ____(____ '----\n" |
|||
" (_____) (______\n" |
|||
" (_____) (_______\n" |
|||
" (____) (_______\n" |
|||
"---.__(___) (_________.---\n" |
|||
" Rock VS Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else if(userSelect ==3) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '---\n" |
|||
" ______) (______\n" |
|||
" _______) (__________\n" |
|||
" _______) (____)\n" |
|||
"---.__________) (___)__.---\n" |
|||
" Paper VS Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ (____ '---\n" |
|||
" ______) (_____)\n" |
|||
" _______) (_____)\n" |
|||
" _______) (____)\n" |
|||
"---.__________) (___)__.---\n" |
|||
" Paper VS Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '----\n" |
|||
" ______) (______\n" |
|||
" _______) (_______\n" |
|||
" _______) (_______\n" |
|||
"---.__________) (_________.---\n" |
|||
" Paper VS Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
printf("ungültige Eingabe"); |
|||
} |
|||
switch (winNumb) |
|||
{ |
|||
case(-1):printf("Der Computer hat %s gewaehlt, Du hast verloren!!!\n\n", comWeapon); |
|||
break; |
|||
case(0): printf("Der Computer hat %s gewaehlt, Es steht unentschieden!!!\n\n", comWeapon); |
|||
break; |
|||
case(1): printf("Der Computer hat %s gewaehlt, Du hast gewonnen!!!\n\n", comWeapon); |
|||
break; |
|||
default: printf("Error!"); |
|||
break; |
|||
} |
|||
} |
@ -1,6 +1,7 @@ |
|||
#ifndef SCHERESTEINPAPIER_H |
|||
#define SCHERESTEINPAPIER_H |
|||
|
|||
int schereSteinPapier(); |
|||
void schereSteinPapier(); |
|||
int calculateWinner(int, int); |
|||
|
|||
#endif |
@ -0,0 +1,7 @@ |
|||
#include "hangman.h" |
|||
#include <stdio.h> |
|||
|
|||
void hangman() |
|||
{ |
|||
printf("Hello World!"); |
|||
} |
@ -0,0 +1,6 @@ |
|||
#ifndef HANGMAN_H |
|||
#define HANGMAN_H |
|||
|
|||
void hangman(); |
|||
|
|||
#endif |
@ -0,0 +1,24 @@ |
|||
#include "hangman.h" |
|||
#include "unity.h" |
|||
|
|||
|
|||
|
|||
void setUp(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void tearDown(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void test_ceedling_functionality() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 0; |
|||
//act |
|||
int actualResult = 0; |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue