parent
419e51867a
commit
e27357cadd
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* \file IslandOrBridge.h
|
||||||
|
* \brief Used to convert board coordinates into usable ones
|
||||||
|
* \author Théotime Maillarbaux
|
||||||
|
* \date 06/12/2021
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ISLANDORBRIDGE_H
|
||||||
|
#define ISLANDORBRIDGE_H
|
||||||
|
|
||||||
|
#include "model/Coord.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum EntityType
|
||||||
|
* \brief Indicates which entity was clicked.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
WATER, ///< Nothing in particular was clicked
|
||||||
|
ISLAND, ///< An Island was clicked
|
||||||
|
VBRIDGE, ///< A vertical bridge was clicked
|
||||||
|
HBRIDGE ///< A horizontal bridge was clicked
|
||||||
|
} EntityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \struct IslandOrBridge
|
||||||
|
* \brief Represents a set of coordinates coherent with the CoordType.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int x; ///< The coordinate on the X-axis.
|
||||||
|
int y; ///< The coordinate on the Y-axis.
|
||||||
|
EntityType type; ///< The type of the entity clicked.
|
||||||
|
} IslandOrBridge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Converts a set of board coordinates into a usable set of coordinates.
|
||||||
|
* \param[in] c The set of board coordinates.
|
||||||
|
* \return An IslandOrBridge struct with coherent coordinates with the type of entity.
|
||||||
|
*/
|
||||||
|
IslandOrBridge coordToEntity(Coord c);
|
||||||
|
|
||||||
|
#endif // ISLANDORBRIDGE_H
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
#include "model/IslandOrBridge.h"
|
||||||
|
|
||||||
|
IslandOrBridge(Coord c) {
|
||||||
|
IslandOrBridge res;
|
||||||
|
|
||||||
|
if (c.x % 2 == 0) {
|
||||||
|
if (c.y % 2 == 0) {
|
||||||
|
// Island
|
||||||
|
res.x = c.x/2;
|
||||||
|
res.y = c.y/2;
|
||||||
|
res.type = ISLAND;
|
||||||
|
} else { // c.y % 2 != 0
|
||||||
|
// Vertical bridge
|
||||||
|
res.x = c.x/2;
|
||||||
|
res.y = c.y - 1;
|
||||||
|
res.type = VBRIDGE;
|
||||||
|
}
|
||||||
|
} else { // c.x % 2 != 0
|
||||||
|
if (c.y % 2 == 0) {
|
||||||
|
// Horizontal bridge
|
||||||
|
res.x = c.x - 1;
|
||||||
|
res.y = c.y / 2;
|
||||||
|
res.type = HBRIDGE;
|
||||||
|
} else { // c.y % 2 != 0
|
||||||
|
// Nothing in particular
|
||||||
|
res.type = WATER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue