Add a bridge struct (two islands) and modify of rmBridge due to this new struct

merge-requests/1/merge
Jacques THOMAS 4 years ago
parent fe6a5016b6
commit ccc8f7ac0a

@ -16,7 +16,7 @@
* \struct Board
* \brief Represents a board for a Game.
*
* The bridges are represented by 2D-arrays of SDL_Bools.
* The bridges are represented by 2D-arrays of bools.
* For a given set of coordinates, the value is TRUE if the bridge is there,
* else false.
*/

@ -1,13 +1,22 @@
/**
* \file Bridge.h
* \brief Bridge
* \autor Martin Roualt, Jacques Thomas
* \date 13/12/2021
*/
#ifndef BRIDGE_INCLUDED
#define BRIDGE_INCLUDED
#include "model/Island.h"
struct {
Island a;
Island b;
bool vertical;
/**
* \struct Bridge
* \brief Represents a bridge which is two island
*/
typedef struct {
Island islandA;///< Horizontal : left to islandB, Vertical : up to islandB
Island islandB;///< Horizontal : right to islandA, Vertical : down to islandA
} Bridge;
#endif //BRIDGE_INCLUDED

@ -94,11 +94,11 @@ bool checkBridge(const Island start, const Island target, const Board* b);
/**
* \brief Remove bridge from board at (coord->x; coord->y)
* \param[in] coords Bridge's coords to remove
* \param[in] coords Bridge to remove
* \param[in] board Actual game board
* \return True on success. Else return false.
*/
bool rmBridge(Coord coords, Board* board);
bool rmBridge(Bridge bridge, Board* board);
#endif //PARTIE_H

@ -137,20 +137,23 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game) {
}
bool rmBridge(Coord coord, Board* board) {
bool rmBridge(Bridge bridge, Board* board) {
if (bridge.type == HBRIDGE) {
if (board->hBridges[bridge.y][bridge.x]) {
board->hBridges[bridge.y][bridge.x] = false;
return true;
}
}
else if (bridge.type == VBRIDGE) {
if (board->vBridges[bridge.y][bridge.x]) {
board->vBridges[bridge.y][bridge.x] = false;
return true;
if(brige.islandA.x==bridge.islandB.x) //Horizontal bridge
{
if(board->hBridges[bridge.islandA.y][bridge.islandA.x])
board->hBridges[bridge.islandA.y][bridge.islandA.x] = false; //Brige coordinates equals to the islandA
return true;
}
else if(brige.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;
return true;
}
}
return false;
}

Loading…
Cancel
Save