modification newGame

origin/fixingSettings
Mathis RIBEMONT 4 years ago
parent d71beabbd7
commit 42636bca6e

@ -10,11 +10,12 @@
#include "../test/testConnectionMenu.c"*/ #include "../test/testConnectionMenu.c"*/
//#include "../test/testDrawMainMenu.c //#include "../test/testDrawMainMenu.c
//#include "../test/testSettingsView.c" //#include "../test/testSettingsView.c"
#include "../test/oldMain__ThisCanBeGameMain.c"
/* /*
This file is meant to be modified (used only to called other tests functions) This file is meant to be modified (used only to called other tests functions)
*/ */
int main(int argc, char *argv[]) { /*int main(int argc, char *argv[]) {
//testTextureLoader(); //testTextureLoader();
//testAudioHandler(); //testAudioHandler();
//testFontLoader(); //testFontLoader();
@ -22,11 +23,11 @@ int main(int argc, char *argv[]) {
//testTextInput(); //testTextInput();
//testButtonTextureLoader(); //testButtonTextureLoader();
//testConnectionMenu(); //testConnectionMenu();
testMenuEndGame(); //testMenuEndGame();
//testGameInterface(); //testGameInterface();
//testConnectionMenu(); //testConnectionMenu();
//testDrawMainMenu(); //testDrawMainMenu();
//testSettingsView(); //testSettingsView();
return 0; return 0;
} }*/

@ -15,7 +15,7 @@
#include "model/Coord.h" #include "model/Coord.h"
#include "model/arrayCoord.h" #include "model/arrayCoord.h"
#include <SDL2/SDL_pixels.h> #include <SDL2/SDL_pixels.h>
#include <stdbool.h> #include <stdbool.h>
/** /**
* \enum Phase * \enum Phase
@ -38,7 +38,7 @@ typedef struct {
//TODO duree //TODO duree
Phase phase; ///< The current state of the game Phase phase; ///< The current state of the game
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
} Game; } Game;
@ -47,19 +47,19 @@ typedef struct {
* \param[in] nbPlayers The number of players for this game * \param[in] nbPlayers The number of players for this game
* \return A struct representing the game * \return A struct representing the game
*/ */
Game newGame(const size_t nbPlayers, const char* pseudos[]); Game newGame(const size_t nbPlayers, const Player player[]);
/** /**
* \brief (Should not be called outside Game.c) Used to change phase or player (or both) after an action * \brief (Should not be called outside Game.c) Used to change phase or player (or both) after an action
* *
* \param [in, out] game The game to mutate * \param [in, out] game The game to mutate
*/ */
void changePhaseOrPlayerTurn(Game* game); void changePhaseOrPlayerTurn(Game* game);
/** /**
* \brief Place a piece into the board * \brief Place a piece into the board
* *
* \param [in, out] p The piece to place * \param [in, out] p The piece to place
* \param [in] island The island where the piece is placed * \param [in] island The island where the piece is placed
* \param [in] b The board in which the piece is placed * \param [in] b The board in which the piece is placed
@ -78,20 +78,20 @@ bool movePiece(Piece* p, const Island i, const Board* b);
/** /**
* \brief Test if a movement is possible for a piece to a destination island * \brief Test if a movement is possible for a piece to a destination island
* *
* \param p The piece to test * \param p The piece to test
* \param i The destination island * \param i The destination island
* \param b The board * \param b The board
* \return true if the piece p can move to the island i * \return true if the piece p can move to the island i
*/ */
bool pieceCanMoveTo(const Piece* p, const Island i, const Board* b); bool pieceCanMoveTo(const Piece* p, const Island i, const Board* b);
/** /**
* \brief Check if an island is empty * \brief Check if an island is empty
* *
* \param [in] island The island to check * \param [in] island The island to check
* \param [in] arrPieces the array of piece from the board * \param [in] arrPieces the array of piece from the board
* \param [in] nbPieces number of pieces * \param [in] nbPieces number of pieces
* \return true if none of the pieces is on th island, false otherwise * \return true if none of the pieces is on th island, false otherwise
*/ */
bool isIslandEmpty(const Island island, const Piece arrPieces[], const size_t nbPieces); bool isIslandEmpty(const Island island, const Piece arrPieces[], const size_t nbPieces);
@ -107,16 +107,16 @@ bool isPieceAdjacentToIsland(const Piece p, const Island i);
/** /**
* \brief test if a piece is isolated * \brief test if a piece is isolated
* *
* \param [in] piece The piece which is checked * \param [in] piece The piece which is checked
* \param [in] board The board were the piece is * \param [in] board The board were the piece is
* \return true if no bridge go from piece's island to another island, false otherwise * \return true if no bridge go from piece's island to another island, false otherwise
*/ */
bool isPieceIsolated(const Piece* piece, const Board* board); bool isPieceIsolated(const Piece* piece, const Board* board);
/** /**
* \brief test if all pieces from a player are stucked * \brief test if all pieces from a player are stucked
* *
* \param idJ Player id * \param idJ Player id
* \param arrPieces All pieces from board * \param arrPieces All pieces from board
* \param nbPieces Number of pieces * \param nbPieces Number of pieces
@ -126,10 +126,10 @@ bool areAllPlayerPiecesStucked(const size_t idJ, const Piece arrPieces[], const
/** /**
* \brief Test if one piece of a player can move * \brief Test if one piece of a player can move
* *
* \param playerID The player to check * \param playerID The player to check
* \param board The board * \param board The board
* \return true if at least one of player's piece can move * \return true if at least one of player's piece can move
*/ */
bool anyOfPlayersPiecesCanMove(const size_t playerID, const Board* board); bool anyOfPlayersPiecesCanMove(const size_t playerID, const Board* board);
@ -154,7 +154,7 @@ Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Is
/** /**
* \brief Handle global game action move * \brief Handle global game action move
* *
* \param start Board coord were the move started * \param start Board coord were the move started
* \param end Board coord were the move ended * \param end Board coord were the move ended
* \param game Game's state * \param game Game's state
@ -164,7 +164,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game);
/** /**
* \brief Handle global game action click * \brief Handle global game action click
* *
* \param [in] coord Board coord were the click is * \param [in] coord Board coord were the click is
* \param [in, out] game Game's state * \param [in, out] game Game's state
* \return true if an action was realised, false otherwise * \return true if an action was realised, false otherwise
@ -181,7 +181,7 @@ bool rmBridge(Bridge bridge, Board* board);
/** /**
* \brief List cases that can be interacted with for movement * \brief List cases that can be interacted with for movement
* *
* \param[in] game The game * \param[in] game The game
* \param[in] selectedCase The selected case * \param[in] selectedCase The selected case
* \return struct array_Coord An array of coord /!\ Care to free this array with array_Coord_Free * \return struct array_Coord An array of coord /!\ Care to free this array with array_Coord_Free
@ -189,4 +189,3 @@ bool rmBridge(Bridge bridge, Board* board);
struct array_Coord getInteractiveCases(const Game* const game, const Coord selectedCase); struct array_Coord getInteractiveCases(const Game* const game, const Coord selectedCase);
#endif //GAME_H #endif //GAME_H

@ -30,7 +30,7 @@ void applySpecificRulesFor2PlayersGame(Game* g)
} }
} }
Game newGame(const size_t nbPlayers, const char* pseudos[]) Game newGame(const size_t nbPlayers, const Player player[])
{ {
Game g = { // In Placement phase, the last player initialized is the 1st to play Game g = { // In Placement phase, the last player initialized is the 1st to play
.currentPlayerID = nbPlayers - 1, .currentPlayerID = nbPlayers - 1,
@ -40,13 +40,9 @@ Game newGame(const size_t nbPlayers, const char* pseudos[])
.nbPlayers = nbPlayers .nbPlayers = nbPlayers
}; };
// red, green, blue, yellow
// TODO meilleures couleurs (?)
SDL_Color colors[4] = { { 255, 0, 0, 255 }, { 0, 255, 0, 255 }, { 0, 0, 255, 255 }, { 255, 255, 0, 255 } };
for (size_t player_i = 0; player_i < nbPlayers; player_i++) for (size_t player_i = 0; player_i < nbPlayers; player_i++)
{ {
g.arrPlayers[player_i] = newPlayer(pseudos[player_i], colors[player_i]); g.arrPlayers[player_i] = player[player_i];
} }
if (nbPlayers == 2) if (nbPlayers == 2)
@ -72,8 +68,8 @@ void changePhaseOrPlayerTurn(Game* game)
game->currentPlayerID--; game->currentPlayerID--;
} }
break; break;
case MOVE_PIECE: case MOVE_PIECE:
game->phase = RM_BRIDGE; game->phase = RM_BRIDGE;
break; break;
case RM_BRIDGE: case RM_BRIDGE:
{ {
@ -93,7 +89,7 @@ void changePhaseOrPlayerTurn(Game* game)
} while (areAllPlayerPiecesStucked(game->currentPlayerID, game->board.arrPieces, } while (areAllPlayerPiecesStucked(game->currentPlayerID, game->board.arrPieces,
game->board.nbPieces)); game->board.nbPieces));
fprintf(stderr, "Player n°%ld turn\n", game->currentPlayerID); fprintf(stderr, "Player n°%ld turn\n", game->currentPlayerID);
fflush(stderr); fflush(stderr);
@ -103,7 +99,7 @@ void changePhaseOrPlayerTurn(Game* game)
} }
break; break;
} }
default: default:
break; break;
} }
} }
@ -243,7 +239,7 @@ bool anyOfPlayersPiecesCanMove(const size_t playerID, const Board* board) {
size_t nbNeighbors; size_t nbNeighbors;
Island* neighbors = islandsAround(board->arrPieces[i].island, &nbNeighbors); Island* neighbors = islandsAround(board->arrPieces[i].island, &nbNeighbors);
for (size_t n = 0; n < nbNeighbors; ++n) for (size_t n = 0; n < nbNeighbors; ++n)
{ {
if (board->arrPieces[i].idJ == playerID && pieceCanMoveTo(&board->arrPieces[i], neighbors[n], board)) { if (board->arrPieces[i].idJ == playerID && pieceCanMoveTo(&board->arrPieces[i], neighbors[n], board)) {
return true; return true;
} }
@ -304,7 +300,7 @@ bool clickOnBoard(const Coord coord, Game* game)
} }
} }
break; break;
default: default:
break; break;
} }
@ -348,7 +344,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game)
} }
} }
break; break;
default: default:
break; break;
} }
@ -385,7 +381,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec
case PLACEMENT: { case PLACEMENT: {
struct array_Coord retVal = array_Coord_Create(); struct array_Coord retVal = array_Coord_Create();
array_Coord_Reserve(&retVal, 25); array_Coord_Reserve(&retVal, 25);
for (int y = 0; y<5; y+=2) { for (int y = 0; y<5; y+=2) {
for (int x = 0; x<5; x+=2) { for (int x = 0; x<5; x+=2) {
array_Coord_AddElement(&retVal, newCoord(x,y)); array_Coord_AddElement(&retVal, newCoord(x,y));
@ -398,7 +394,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec
array_Coord_RemoveElement(&retVal, islandToCoord(&game->board.arrPieces[i].island), &coordEqual); array_Coord_RemoveElement(&retVal, islandToCoord(&game->board.arrPieces[i].island), &coordEqual);
} }
} }
array_Coord_FitToSize(&retVal); array_Coord_FitToSize(&retVal);
return retVal; return retVal;
@ -412,7 +408,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec
if (game->board.arrPieces[i].idJ == game->currentPlayerID && !game->board.arrPieces[i].stuck) { if (game->board.arrPieces[i].idJ == game->currentPlayerID && !game->board.arrPieces[i].stuck) {
size_t nbIsland; size_t nbIsland;
Island* islands = islandsAround(game->board.arrPieces[i].island, &nbIsland); Island* islands = islandsAround(game->board.arrPieces[i].island, &nbIsland);
if (nbIsland != 0) { if (nbIsland != 0) {
Coord pieceCoord = islandToCoord(&game->board.arrPieces[i].island); Coord pieceCoord = islandToCoord(&game->board.arrPieces[i].island);
if (!coordValid(selectedCase)) { if (!coordValid(selectedCase)) {
@ -442,7 +438,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec
case RM_BRIDGE: { case RM_BRIDGE: {
struct array_Coord retVal = array_Coord_Create(); struct array_Coord retVal = array_Coord_Create();
array_Coord_Reserve(&retVal, 40); array_Coord_Reserve(&retVal, 40);
for (size_t y = 0; y<5; ++y) { for (size_t y = 0; y<5; ++y) {
for (size_t x = 0; x<4; ++x) { for (size_t x = 0; x<4; ++x) {
if (game->board.hBridges[y][x]) { if (game->board.hBridges[y][x]) {
@ -459,7 +455,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec
} }
} }
} }
return retVal; return retVal;
} }
default: default:

@ -26,7 +26,7 @@ int main(int argc, char* argv[])
if (!window) if (!window)
{ {
fprintf(stderr, "Error : %s\n", SDL_GetError()); fprintf(stderr, "Error : %s\n", SDL_GetError());
goto Quit; goto Quit;
} }
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED); renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
@ -42,6 +42,7 @@ int main(int argc, char* argv[])
int wBoardRect=99*3, hBoardRect=99*3; int wBoardRect=99*3, hBoardRect=99*3;
SDL_Rect boardRect = {.x=windowSize.w/2 - wBoardRect/2, .y=windowSize.h/2 - hBoardRect/2, .w=wBoardRect, .h=99*3}; SDL_Rect boardRect = {.x=windowSize.w/2 - wBoardRect/2, .y=windowSize.h/2 - hBoardRect/2, .w=wBoardRect, .h=99*3};
const char* pseudos[] = {"Azerty","Bépo"}; const char* pseudos[] = {"Azerty","Bépo"};
const Player [2];
Game game = newGame(2, pseudos); Game game = newGame(2, pseudos);
TextureHandler textureHandler = newTextureHandler(renderer); TextureHandler textureHandler = newTextureHandler(renderer);
@ -73,7 +74,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "Move on board\n"); fprintf(stderr, "Move on board\n");
fprintf(stderr, "From (%d; %d)\n", inputElement.data.move.start.x, inputElement.data.move.start.y); fprintf(stderr, "From (%d; %d)\n", inputElement.data.move.start.x, inputElement.data.move.start.y);
fprintf(stderr, "To (%d; %d)\n", inputElement.data.move.end.x, inputElement.data.move.end.y); fprintf(stderr, "To (%d; %d)\n", inputElement.data.move.end.x, inputElement.data.move.end.y);
moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game); moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game);
break; break;
case InputType_ClickGame: case InputType_ClickGame:
@ -89,21 +90,21 @@ int main(int argc, char* argv[])
fprintf(stderr, "\tselected case reset\n"); fprintf(stderr, "\tselected case reset\n");
inputProcessor.selectedCase = newCoord(-1,-1); inputProcessor.selectedCase = newCoord(-1,-1);
} }
break; break;
case InputType_None: case InputType_None:
default: default:
break; break;
} }
array_Coord_Free(&interactiveCases); array_Coord_Free(&interactiveCases);
interactiveCases = getInteractiveCases(&game, inputProcessor.selectedCase); interactiveCases = getInteractiveCases(&game, inputProcessor.selectedCase);
fprintf(stderr, "Interactive cases : {"); fprintf(stderr, "Interactive cases : {");
array_Coord_Foreach(&interactiveCases, *printCoord); array_Coord_Foreach(&interactiveCases, *printCoord);
fprintf(stderr, "}\n"); fprintf(stderr, "}\n");
} }
fflush(stderr); fflush(stderr);
// Drawing // Drawing
@ -125,7 +126,7 @@ Quit:
if(window != NULL) { if(window != NULL) {
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
} }
SDL_Quit(); SDL_Quit();
return statut; return statut;
} }

Loading…
Cancel
Save