From 3a0e4ff19527afb8ab7152da07f278683d10cca0 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 12:06:26 +0100 Subject: [PATCH] added a game handler function --- src/main/c/Georg/tictactoe.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index fbee1de..1c602df 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -162,6 +162,30 @@ int* getMarkerParameters( char* input ){ return array; } +void handleGame(){ + char* input = getUserInput(); + int nextState = handleCommand( input ); + + // check commands, if no command found return for new Input + // gameCommands are saved and processed after this block + int gameCommand = -1; + if( nextState == -1 ){ // no stateCommand + gameCommand = handleGameInput( input ); + if( gameCommand == -1 ){ + printf("command not found!"); + return; + } + }else{ + GAME.currentState = nextState; + return; + } + + // gameCommand processing + if( gameCommand == 1 ) { // set marker in field + + } +} + int startGame( int code ){ if( code == -1 ){ // command test return 1; @@ -172,16 +196,7 @@ int startGame( int code ){ initializeBoard( board ); while( GAME.currentState == 1 ){ - char* input = getUserInput(); - int nextState = handleCommand( input ); - - if( nextState == -1 ){ // no stateCommand - int gameCommand = handleGameInput( input ); - - printf("command not found!"); - }else{ - GAME.currentState = nextState; - } + handleGame(); } return 0;