Corrected some coordinate transformation errors (we can clic to remove bridges if we set game's phase to RM_BRDIGE)

merge-requests/1/merge
marouault 4 years ago
parent 718fdee338
commit e11fbb01b4

@ -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:

@ -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);

@ -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

@ -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;
}

@ -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)
{

@ -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;
}
}

@ -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}
}
};

Loading…
Cancel
Save