New Drawing system in place -> going to test it on guacamole

origin/fixingSettings
marouault 4 years ago
parent 33191714c1
commit 9eb65816df

@ -28,6 +28,13 @@ typedef enum {
GAME_ENDED
} Phase;
typedef enum {
GameAction_None,
GameAction_PlacePiece,
GameAction_MovePiece,
GameAction_RemoveBridge,
} GameAction;
/**
* \struct Game
* \brief Represents a game
@ -158,18 +165,18 @@ Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Is
* \param start Board coord were the move started
* \param end Board coord were the move ended
* \param game Game's state
* \return true if an action was realised, false otherwise
* \return The action realised, GameAction_None if no action was realized
*/
bool moveOnBoard(const Coord start, const Coord end, Game* game);
GameAction moveOnBoard(const Coord start, const Coord end, Game* game);
/**
* \brief Handle global game action click
*
* \param [in] coord Board coord were the click is
* \param [in, out] game Game's state
* \return true if an action was realised, false otherwise
* \return The action realised, GameAction_None if no action was realized
*/
bool clickOnBoard(const Coord coord, Game* game);
GameAction clickOnBoard(const Coord coord, Game* game);
/**
* \brief Remove bridge from board at (coord->x; coord->y)

@ -10,5 +10,8 @@ void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const P
void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Coord* startMove, const Coord* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture);
void drawPlacePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* pieceTexture, const Coord* coordPlace);
#endif //PIECES_DRAWER_INCLUDED

@ -268,7 +268,7 @@ void updatePieceIsolated(Game* game, const Island* island)
}
}
bool clickOnBoard(const Coord coord, Game* game)
GameAction clickOnBoard(const Coord coord, Game* game)
{
const IslandOrBridge islandOrBridge = coordToEntity(coord);
@ -281,7 +281,7 @@ bool clickOnBoard(const Coord coord, Game* game)
if (piece != NULL) {
if (placePiece(piece, islandOrBridge.data.island, &game->board)) {
changePhaseOrPlayerTurn(game);
return true;
return GameAction_PlacePiece;
}
}
}
@ -296,7 +296,7 @@ bool clickOnBoard(const Coord coord, Game* game)
changePhaseOrPlayerTurn(game);
return true;
return GameAction_RemoveBridge;
}
}
break;
@ -304,7 +304,7 @@ bool clickOnBoard(const Coord coord, Game* game)
break;
}
return false;
return GameAction_None;
}
Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Island island)
@ -319,7 +319,7 @@ Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Is
return NULL;
}
bool moveOnBoard(const Coord start, const Coord end, Game* game)
GameAction moveOnBoard(const Coord start, const Coord end, Game* game)
{
const IslandOrBridge islandOrBridgeStart = coordToEntity(start);
const IslandOrBridge islandOrBridgeEnd = coordToEntity(end);
@ -340,7 +340,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game)
{
changePhaseOrPlayerTurn(game);
}
return pieceMoved;
return pieceMoved ? GameAction_MovePiece : GameAction_None;
}
}
break;
@ -348,7 +348,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game)
break;
}
return false;
return GameAction_None;
}
bool rmBridge(Bridge bridge, Board* board)

@ -3,7 +3,8 @@
void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge) {
const SDL_Rect destRect = coordToRect(boardRect, coordBridge);
SDL_RenderCopy(renderer, water, &destRect, boardRect);
SDL_RenderCopy(renderer, water, NULL, &destRect);
fprintf(stderr, "RedrawWater\n"); fflush(stderr);
}
bool drawFullBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water)

@ -65,18 +65,23 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
break;
}
break;
case InputType_MoveGame:
case InputType_MoveGame: {
fprintf(stderr, "Move on board\n");
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);
moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game);
drawMovePiece(renderer, &boardRect, &inputElement.data.move.start, &inputElement.data.move.end, textureHandler.textures[TEXTURE_PieceRed], textureHandler.textures[TEXTURE_Island]);
const GameAction actionRealized = moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game);
switch (actionRealized)
{
case GameAction_MovePiece:
drawMovePiece(renderer, &boardRect, &inputElement.data.move.start, &inputElement.data.move.end, textureHandler.textures[TEXTURE_PieceRed], textureHandler.textures[TEXTURE_Island]);
SDL_RenderPresent(renderer);
break;
}
SDL_RenderPresent(renderer);
break;
case InputType_ClickGame:
}
case InputType_ClickGame: {
fprintf(stderr, "Clic on board (%d; %d)\n", inputElement.data.coord.x, inputElement.data.coord.y);
fprintf(stderr, "\tSelected case : (%d; %d)\n", inputProcessor.selectedCase.x, inputProcessor.selectedCase.y);
@ -85,13 +90,26 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
inputProcessor.selectedCase = newCoord(-1,-1);
}
if (clickOnBoard(inputElement.data.coord, &game)) {
const GameAction actionRealized = clickOnBoard(inputElement.data.coord, &game);
switch (actionRealized)
{
case GameAction_PlacePiece:
drawPlacePiece(renderer, &boardRect, textureHandler.textures[TEXTURE_PieceViolet], &inputElement.data.coord);
SDL_RenderPresent(renderer);
break;
case GameAction_RemoveBridge:
drawRemoveBridge(renderer, &boardRect, textureHandler.textures[TEXTURE_Water], &inputElement.data.coord);
SDL_RenderPresent(renderer);
break;
}
if (actionRealized != GameAction_None) {
fprintf(stderr, "\tselected case reset\n");
inputProcessor.selectedCase = newCoord(-1,-1);
}
break;
}
case InputType_None:
default:
break;

@ -21,3 +21,11 @@ void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Coor
rDest = coordToRect(boardRect, endMove);
SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest);
}
void drawPlacePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* pieceTexture, const Coord* coordPlace) {
SDL_Rect rDest = coordToRect(boardRect, coordPlace);
SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest);
}

Loading…
Cancel
Save