33//
44
55#include " Interface/DisplayBoard.h"
6- #include " GameComponents/Board.h"
7- #include < QPainter>
86#include < QMouseEvent>
7+ #include < QPainter>
8+ #include " GameComponents/Board.h"
99
10- DisplayBoard::DisplayBoard (QWidget *parent, int lines, int columns)
11- : QWidget(parent), m_Board(10 ), m_Lines(lines), m_Columns(columns), m_SelectedCard(1 ), m_CardSelected(false ) {}
10+ DisplayBoard::DisplayBoard (QWidget *parent, const int lines, const int columns) :
11+ QWidget(parent), m_Board(10 ), m_Lines(lines), m_Columns(columns), m_SelectedCard(1 ),
12+ m_CardSelected(false ) {}
1213
13- void DisplayBoard::setBoard (const Board& board) {
14+ void DisplayBoard::SetBoard (const Board & board) {
1415 m_Board = board;
1516 update ();
1617}
1718
18- void DisplayBoard::onDraw () {
19- update ();
20- }
19+ void DisplayBoard::OnDraw () { update (); }
2120
22- void DisplayBoard::insertCard (const Card& card, const std::pair<int , int >& position, PlayerTurn turn) {
21+ void DisplayBoard::InsertCard (const Card &card, const std::pair<int , int > &position,
22+ const PlayerTurn &turn) {
2323 m_Board.InsertCard (card, position, turn);
2424 update ();
2525}
2626
27- void DisplayBoard::placeCard (const Card& card) {
27+ void DisplayBoard::PlaceCard (const Card & card) {
2828 m_SelectedCard = card;
2929 m_CardSelected = true ;
3030}
3131
3232void DisplayBoard::paintEvent (QPaintEvent *event) {
3333 Q_UNUSED (event);
3434
35- QPainter painter (this );
36- int cellSize = 50 ;
37- int xOffset = 10 ;
38- int yOffset = 10 ;
35+ QPainter painter (this );
36+ constexpr int cellSize = 50 ;
37+ constexpr int xOffset = 10 ;
38+ constexpr int yOffset = 10 ;
3939
4040 for (int row = 0 ; row < m_Lines; ++row) {
4141 for (int col = 0 ; col < m_Columns; ++col) {
42- int x = xOffset + col * cellSize;
43- int y = yOffset + row * cellSize;
42+ const int x = xOffset + col * cellSize;
43+ const int y = yOffset + row * cellSize;
4444
4545 painter.drawRect (x, y, cellSize, cellSize);
4646
4747 Position pos{col, row};
48- if (m_Board.GetGameBoard ().count (pos) && !m_Board.GetGameBoard ().at (pos).empty ()) {
49- painter.drawText (x + 10 , y + 20 , QString::number (m_Board.GetGameBoard ().at (pos).top ().GetValue ()));
48+ if (m_Board.GetGameBoard ().contains (pos) && !m_Board.GetGameBoard ().at (pos).empty ()) {
49+ painter.drawText (x + 10 , y + 20 ,
50+ QString::number (m_Board.GetGameBoard ().at (pos).top ().GetValue ()));
5051 }
5152 }
5253 }
5354}
5455
5556void DisplayBoard::mousePressEvent (QMouseEvent *event) {
5657 if (m_CardSelected) {
57- int cellSize = 50 ;
58- int xOffset = 10 ;
59- int yOffset = 10 ;
58+ constexpr int cellSize = 50 ;
59+ constexpr int xOffset = 10 ;
60+ constexpr int yOffset = 10 ;
6061
61- int col = (event->x () - xOffset) / cellSize;
62- int row = (event->y () - yOffset) / cellSize;
62+ const int col = (event->position (). x () - xOffset) / cellSize;
63+ const int row = (event->position (). y () - yOffset) / cellSize;
6364
6465 if (col >= 0 && col < m_Columns && row >= 0 && row < m_Lines) {
65- insertCard (m_SelectedCard, {col, row}, PlayerTurn::Player1); // Assuming Player1 for simplicity
66+ InsertCard (m_SelectedCard, {col, row},
67+ PlayerTurn::Player1); // Assuming Player1 for simplicity
6668 m_CardSelected = false ;
6769 }
6870 }
69- }
71+ }
0 commit comments