End game modified but not totally fixed

origin/fixingSettings
marouault 3 years ago
parent 8cb3ccef1b
commit 930719ce7d

@ -47,6 +47,7 @@ typedef struct {
Player arrPlayers[4]; ///< The array of all the players in this game Player arrPlayers[4]; ///< The array of all the players in this game
size_t nbPlayers; size_t nbPlayers;
Board board; ///< The board for this game Board board; ///< The board for this game
int lastRank;
} Game; } Game;
/** /**

@ -37,7 +37,8 @@ Game newGame(const size_t nbPlayers, const Player player[])
.nb_rounds = 0, .nb_rounds = 0,
.phase = PLACEMENT, .phase = PLACEMENT,
.board = newBoard(nbPlayers), .board = newBoard(nbPlayers),
.nbPlayers = nbPlayers .nbPlayers = nbPlayers,
.lastRank = 0
}; };
for (size_t player_i = 0; player_i < nbPlayers; player_i++) for (size_t player_i = 0; player_i < nbPlayers; player_i++)
@ -53,6 +54,16 @@ Game newGame(const size_t nbPlayers, const Player player[])
return g; return g;
} }
void eliminatePlayer(Game* game, const size_t playerId) {
game->arrPlayers[playerId].eliminationTurn = game->nb_rounds;
++game->lastRank;
game->arrPlayers[playerId].rank = game->lastRank;
fprintf(stderr, "Rank : %d\n", game->lastRank);
}
void endGame(Game* game) {
game->phase = GAME_ENDED;
}
void changePhaseOrPlayerTurn(Game* game) void changePhaseOrPlayerTurn(Game* game)
{ {
@ -74,6 +85,14 @@ void changePhaseOrPlayerTurn(Game* game)
case RM_BRIDGE: case RM_BRIDGE:
{ {
const size_t lastPlayerId = game->currentPlayerID; const size_t lastPlayerId = game->currentPlayerID;
if (areAllPlayerPiecesStucked(lastPlayerId, game->board.arrPieces, game->board.nbPieces)) {
eliminatePlayer(game, lastPlayerId);
if (game->nbPlayers-1 == game->lastRank) {
endGame(game);
return;
}
}
do do
{ {
game->currentPlayerID++; game->currentPlayerID++;
@ -81,13 +100,20 @@ void changePhaseOrPlayerTurn(Game* game)
{ {
game->currentPlayerID = 0; game->currentPlayerID = 0;
} }
if (lastPlayerId == game->currentPlayerID) { /*if (lastPlayerId == game->currentPlayerID) {
game->phase = GAME_ENDED; game->phase = GAME_ENDED;
return; return;
}*/
if (game->arrPlayers[game->currentPlayerID].rank != 0 && areAllPlayerPiecesStucked(game->currentPlayerID, game->board.arrPieces, game->board.nbPieces)) {
eliminatePlayer(game, game->currentPlayerID);
if (game->nbPlayers-1 == game->lastRank) {
endGame(game);
return;
}
} }
} while (areAllPlayerPiecesStucked(game->currentPlayerID, game->board.arrPieces, } while (game->arrPlayers[game->currentPlayerID].rank != 0);
game->board.nbPieces));
fflush(stderr); fflush(stderr);

@ -73,6 +73,9 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
case GameAction_MovePiece: case GameAction_MovePiece:
drawMovePiece(renderer, &boardRect, &inputElement.data.move.start, &inputElement.data.move.end, textureHandler.textures[TEXTURE_PieceRed], textureHandler.textures[TEXTURE_Island]); drawMovePiece(renderer, &boardRect, &inputElement.data.move.start, &inputElement.data.move.end, textureHandler.textures[TEXTURE_PieceRed], textureHandler.textures[TEXTURE_Island]);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
if (game.phase == GAME_ENDED) {
*generalState = GS_EndOfGameMenu;
}
break; break;
} }
@ -98,6 +101,9 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
if (actionRealized != GameAction_None) { if (actionRealized != GameAction_None) {
inputProcessor.selectedCase = newCoord(-1,-1); inputProcessor.selectedCase = newCoord(-1,-1);
if (game.phase == GAME_ENDED) {
*generalState = GS_EndOfGameMenu;
}
} }
break; break;
@ -116,6 +122,7 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
freeTextureHandler(&textureHandler); freeTextureHandler(&textureHandler);
array_Coord_Free(&interactiveCases); array_Coord_Free(&interactiveCases);
freeGameInputProcessor(&inputProcessor);
SDL_Quit(); SDL_Quit();
} }

Loading…
Cancel
Save