From 4340d64ed35beec428641229b8fc8a445484a848 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:35:40 +0100 Subject: [PATCH] some bugfix and add global vars --- src/main/c/Georg/tictactoe.c | 24 +++++++++++++++++++----- src/main/c/Georg/tictactoe.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index d01ae9f..195a85e 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -4,7 +4,9 @@ #include "tictactoe.h" -struct ticTacToe TICTACTOE; +struct ticTacToe GAME; +struct command* COMMANDS; + char* getWelcomeMessage(){ return "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; @@ -29,6 +31,8 @@ int handleCommand( char* input ){ return 0; }else if( strcmp(input, "start game") == 0 ){ return 1; + }else{ + return -1; } } @@ -68,10 +72,20 @@ int startMenu( int code ){ return 1; } - printf("Welcome to the menu!\n"); - char userInput[50]; - printf( ":" ); - scanf( "%s", userInput ); + while( GAME.currentState == 0 ){ + char userInput[50]; + printf( ":" ); + scanf( "%s", &userInput ); + + int nextState = 0; + nextState = handleCommand(userInput); + + if( nextState == -1 ){ + printf("command not found!"); + }else{ + GAME.currentState = nextState; + } + } return 0; } diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 3fa6555..f957f9c 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -14,6 +14,9 @@ struct command{ commandFunction fun; }; +extern struct ticTacToe GAME; +extern struct command* COMMANDS; + char* getWelcomeMessage(); char* getRulesMessage(); struct ticTacToe createTicTacToe();