Position H
Position H
#define POSITION_H
#include <vector>
#include "Enums.h"
namespace Tetris
{
// définition / déclaration
/**
* @brief Represents a position on a two-dimensional grid.
*/
class Position
{
//private:
int x_ { 0 }; ///< The x-coordinate of the position.
int y_ { 0 }; ///< The y-coordinate of the position.
public:
/**
* @brief Default constructor for Position.
*/
constexpr Position() = default;
/**
* @brief Constructs a Position with specified x and y coordinates.
* @param x The x-coordinate of the position.
* @param y The y-coordinate of the position.
*/
constexpr Position(int x, int y): x_(x),y_(y){}
/**
* @brief Constructs a Position from a Direction enum value.
* @param dir The Direction enum value.
*/
Position(const Direction &);
/**
* @brief Constructs a Position object by copying another Position object.
* @param pos The Position object to copy.
*/
Position(const Position& pos) : x_(pos.x_), y_(pos.y_){}
/**
* @brief Retrieves the x-coordinate of the position.
* @return The x-coordinate of the position.
*/
constexpr int x() const { return x_; }
/**
* @brief Sets the x-coordinate of the position.
* @param x The new x-coordinate value.
*/
constexpr void x(int x) { x_ = x; }
/**
* @brief Retrieves the y-coordinate of the position.
* @return The y-coordinate of the position.
*/
constexpr int y() const { return y_; }
/**
* @brief Sets the y-coordinate of the position.
* @param x The new y-coordinate value.
*/
constexpr void y(int y) { y_ = y; }
/**
* @brief Rotates the position in the specified direction.
* @param dir The direction in which to rotate the position.
* @return The rotated position.
*/
Position rotate(const Direction& dir) const ;
/**
* @brief Adds another position to this position.
* @param pos The position to add.
*/
void operator+=(const Position& pos);
/**
* @brief Assignment operator for Position.
* @param pos The Position object to copy values from.
* @return Reference to this Position object after assignment.
*/
Position& operator=(const Position& pos);
};
/**
* @brief Adds two positions together and returns the resulting position.
* @param pos The first position.
* @param pos2 The second position.
* @return The sum of the two positions.
*/
Position operator+(const Position& pos, const Position& pos2);
/**
* @brief Subtracts one position from another and returns the resulting
position.
* @param pos The position to subtract from.
* @param pos2 The position to subtract.
* @return The difference between the two positions.
*/
Position operator-(const Position& pos, const Position& pos2);