From e11fbb01b4fdcd27bd505c0c2f885d4559c92cf9 Mon Sep 17 00:00:00 2001 From: marouault Date: Thu, 16 Dec 2021 09:48:28 +0100 Subject: [PATCH] Corrected some coordinate transformation errors (we can clic to remove bridges if we set game's phase to RM_BRDIGE) --- Pontu/entryPoints/main.c | 9 +++++++-- Pontu/include/model/Coord.h | 1 + Pontu/include/model/Game.h | 2 ++ Pontu/src/engine/InputProcessor.c | 2 +- Pontu/src/model/Coord.c | 4 ++++ Pontu/src/model/Game.c | 12 ++++++------ Pontu/src/model/IslandOrBridge.c | 8 ++++---- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index fe745d8..bee7f3a 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -39,7 +39,6 @@ int main(int argc, char* argv[]) Game game = newGame(2, pseudos); TextureHandler textureHandler = newTextureHandler(renderer); - bool quit = false; while(!quit) { @@ -64,9 +63,15 @@ int main(int argc, char* argv[]) } break; case InputType_MoveGame: - + fprintf(stderr, "Move on board\n"); + moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game); break; case InputType_ClickGame: + fprintf(stderr, "Clic on board (%d; %d)\n", inputElement.data.coord.x, inputElement.data.coord.y); + fflush(stderr); + if (cliqueOnBoard(inputElement.data.coord, &game)) { + inputProcessor.selectedCase = newCoord(-1,-1); + } break; case InputType_None: default: diff --git a/Pontu/include/model/Coord.h b/Pontu/include/model/Coord.h index 4598cbe..e889449 100644 --- a/Pontu/include/model/Coord.h +++ b/Pontu/include/model/Coord.h @@ -16,6 +16,7 @@ typedef struct { } Coord; +Coord newCoord(const int x, const int y); bool coordValide(const Coord coord); bool coordEqual(const Coord a, const Coord b); diff --git a/Pontu/include/model/Game.h b/Pontu/include/model/Game.h index b666f0a..68b0d36 100644 --- a/Pontu/include/model/Game.h +++ b/Pontu/include/model/Game.h @@ -109,6 +109,8 @@ Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Is bool moveOnBoard(const Coord start, const Coord end, Game* game); +bool cliqueOnBoard(const Coord coord, Game* game); + /** * \brief Remove bridge from board at (coord->x; coord->y) * \param[in] coords Bridge to remove diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index 96bf6db..1a859a2 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -3,7 +3,7 @@ Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect){ Coord coord = { coord.x = (point->x-boardRect->x)*9/boardRect->w, - coord.x = (point->y-boardRect->y)*9/boardRect->h + coord.y = (point->y-boardRect->y)*9/boardRect->h }; return coord; } diff --git a/Pontu/src/model/Coord.c b/Pontu/src/model/Coord.c index 7d50ead..f8e4911 100644 --- a/Pontu/src/model/Coord.c +++ b/Pontu/src/model/Coord.c @@ -1,5 +1,9 @@ #include "model/Coord.h" +Coord newCoord(const int x, const int y) { + Coord c = {.x = x, .y = y}; + return c; +} bool coordValide(const Coord coord) { diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index 6b767e7..338c7d6 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -217,16 +217,16 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game) { bool rmBridge(Bridge bridge, Board* board) { - if(bridge.islandA.x==bridge.islandB.x) //Horizontal bridge + if(bridge.islandA.x==bridge.islandB.x) //Vertical bridge { - if(board->hBridges[bridge.islandA.y][bridge.islandA.x]) { - board->hBridges[bridge.islandA.y][bridge.islandA.x] = false; //bridge coordinates equals to the islandA + if(board->vBridges[bridge.islandA.y][bridge.islandA.x]) { + board->vBridges[bridge.islandA.y][bridge.islandA.x] = false; return true; } } - else if(bridge.islandA.y==bridge.islandB.y){ //Vertical bridge - if(board->vBridges[bridge.islandA.y][bridge.islandA.x]) { - board->vBridges[bridge.islandA.y][bridge.islandA.x] = false; + else if(bridge.islandA.y==bridge.islandB.y){ //Horizontal bridge + if(board->hBridges[bridge.islandA.y][bridge.islandA.x]) { + board->hBridges[bridge.islandA.y][bridge.islandA.x] = false; //bridge coordinates equals to the islandA return true; } } diff --git a/Pontu/src/model/IslandOrBridge.c b/Pontu/src/model/IslandOrBridge.c index 8c0659b..15eaccc 100644 --- a/Pontu/src/model/IslandOrBridge.c +++ b/Pontu/src/model/IslandOrBridge.c @@ -1,7 +1,7 @@ #include "model/IslandOrBridge.h" IslandOrBridge coordToEntity(const Coord c) { - if (c.x % 2 == 0) { + if (c.x % 2 == 0) { // even columns if (c.y % 2 == 0) { // Island IslandOrBridge res = { @@ -17,7 +17,7 @@ IslandOrBridge coordToEntity(const Coord c) { IslandOrBridge res = { .type = BRIDGE, .data.bridge = { - .islandA={.x=c.x/2, .y = (c.y - 1)/2}, + .islandA= {.x = c.x/2, .y = (c.y - 1)/2}, .islandB= {.x = c.x/2, .y = 1+(c.y - 1)/2} } }; @@ -31,8 +31,8 @@ IslandOrBridge coordToEntity(const Coord c) { IslandOrBridge res = { .type = BRIDGE, .data.bridge = { - .islandA = {.x = (c.x-1)/2, .y = (c.y - 1)/2}, - .islandB = {.x = 1+(c.x-1)/2, .y = 1+(c.y - 1)/2} + .islandA = {.x = (c.x-1)/2, .y = c.y/2}, + .islandB = {.x = 1+(c.x-1)/2, .y = c.y/2} } };