0% found this document useful (0 votes)
21 views2 pages

Position H

The document defines a Position class to represent positions on a two-dimensional grid with x and y coordinates. The Position class has methods to get/set the coordinates, rotate the position, add/subtract positions, and check for equality between positions.

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Position H

The document defines a Position class to represent positions on a two-dimensional grid with x and y coordinates. The Position class has methods to get/set the coordinates, rotate the position, add/subtract positions, and check for equality between positions.

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#ifndef 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);

bool operator==(const Position& pos1, const Position& pos2);


}
#endif //POSISTION_H

You might also like