Documented Coord.h, completed and renamed coordValid

merge-requests/1/merge
marouault 4 years ago
parent 3966a612d6
commit c3b43c4f32

@ -1,7 +1,7 @@
/**
* \file Bridge.h
* \brief Bridge
* \autor Martin Roualt, Jacques Thomas
* \autor Martin Rouault, Jacques Thomas
* \date 13/12/2021
*/

@ -10,14 +10,40 @@
#include <stdbool.h>
/**
* \struct Coord
* \brief From (0,0) to (8,8), represent a global coordinates in a board
*/
typedef struct {
int x; ///< Coordinate on the X-axis
int y; ///< Coordinate on the Y-axis
} Coord;
/**
* \brief Create a new Coord (x,y)
*
* \param [in] x
* \param [in] y
* \return new Coord
*/
Coord newCoord(const int x, const int y);
bool coordValide(const Coord coord);
/**
* \brief Test if a coord is valide (ie x and y between 0 and 8)
*
* \param [in] coord The coord to test
* \return true if coord is valid, false otherwise
*/
bool coordValid(const Coord coord);
/**
* \brief test if two coord are equal
*
* \param [in] a One coord
* \param [in] b One other coord
* \return true if (a.x==b.x and a.y==b.y), false otherwise
*/
bool coordEqual(const Coord a, const Coord b);
#endif //COORD_INCLUDED

@ -38,7 +38,7 @@ InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* board
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
if (SDL_PointInRect(&mousePoint, boardRect))
{
if (coordValide(inputProcessor->selectedCase))
if (coordValid(inputProcessor->selectedCase))
{
Coord newCoord = screenCoordToGameCoord(&mousePoint, boardRect);
if (coordEqual(inputProcessor->selectedCase, newCoord)) {

@ -5,9 +5,10 @@ Coord newCoord(const int x, const int y) {
return c;
}
bool coordValide(const Coord coord)
bool coordValid(const Coord coord)
{
return coord.x >= 0 && coord.y >= 0;
return coord.x >= 0 && coord.y >= 0
&& coord.x < 9 && coord.y < 9;
}
bool coordEqual(const Coord a, const Coord b)

Loading…
Cancel
Save