Skip to content

Commit da03ec3

Browse files
committed
misc: alte chestii debug
@eduard214 te rog ajutor vere
1 parent 5736fee commit da03ec3

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

include/GameModes/Antrenament.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <GameComponents/Board.h>
99
#include <GameModes/Game.h>
1010

11-
class Antrenament : public Game {
11+
class Antrenament final : public Game {
1212
public:
1313
Antrenament(const std::string &nameOne, const std::string &nameTwo);
1414

include/Interface/AntrenamentWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class AntrenamentWidget final : public QWidget {
1515
QStackedWidget *m_StackedWidget;
1616
QWidget *m_Parent;
1717

18-
std::unique_ptr<Antrenament> m_CurrentGame;
19-
std::optional<Card> m_SelectedCard;
18+
Antrenament m_CurrentGame;
19+
std::optional<Card> m_SelectedCard;
2020

2121
int m_GamesPlayed = 0;
2222
int m_Player1Score = 0;

src/Interface/AntrenamentWidget.cpp

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
AntrenamentWidget::AntrenamentWidget(const std::string &nameOne, const std::string &nameTwo,
66
QStackedWidget *stackedWidget, QWidget *parent) :
77
m_AntrenamentWidget(new QWidget(parent)), m_Layout(new QVBoxLayout(m_AntrenamentWidget)),
8-
m_StackedWidget(stackedWidget), m_Parent(parent),
9-
m_CurrentGame(std::make_unique<Antrenament>(nameOne, nameTwo)) {
8+
m_StackedWidget(stackedWidget), m_Parent(parent), m_CurrentGame{nameOne, nameTwo} {
109
m_ScoreLabel = new QLabel(m_AntrenamentWidget);
1110
DrawGame();
1211
}
@@ -37,12 +36,11 @@ AntrenamentWidget::GenerateBoard(const Board &board,
3736
auto down = board.GetDown();
3837

3938
if (!board.IsBoardLocked()) {
40-
++right.first;
41-
++down.second;
42-
--left.first;
43-
--up.second;
39+
right = std::make_pair(right.first + 1, right.second);
40+
down = std::make_pair(down.first, down.second + 1);
41+
left = std::make_pair(left.first - 1, left.second);
42+
up = std::make_pair(up.first, up.second - 1);
4443
}
45-
4644
const auto boardElement = board.GetGameBoard();
4745

4846
for (int j = up.second; j <= down.second; ++j) {
@@ -150,14 +148,9 @@ QHBoxLayout *AntrenamentWidget::GenerateHand(const Hand &ha
150148
}
151149

152150
void AntrenamentWidget::DrawGame() {
153-
m_AntrenamentWidget = new QWidget(this);
154-
m_Layout = new QVBoxLayout(m_AntrenamentWidget);
155-
156-
std::cout << "here\n";
157-
158-
const auto currentTurn = m_CurrentGame->GetCurrentPlayer();
159-
const auto currentPlayer = currentTurn == PlayerTurn::Player1 ? m_CurrentGame->GetPlayer1()
160-
: m_CurrentGame->GetPlayer2();
151+
const auto currentTurn = m_CurrentGame.GetCurrentPlayer();
152+
const auto currentPlayer = currentTurn == PlayerTurn::Player1 ? m_CurrentGame.GetPlayer1()
153+
: m_CurrentGame.GetPlayer2();
161154
const auto &currentHand = currentPlayer.GetHand();
162155

163156
const auto turnLabel = new QLabel(this);
@@ -175,38 +168,34 @@ void AntrenamentWidget::DrawGame() {
175168

176169
auto selectedCard = std::make_shared<std::optional<Card>>(std::nullopt);
177170

171+
const auto leftOne = m_CurrentGame.GetBoard().GetLeft();
172+
173+
std::cout << "First: " << leftOne.first << " " << leftOne.second << '\n';
174+
178175
const auto boardLayout =
179-
GenerateBoard(m_CurrentGame->GetBoard(), [this, selectedCard, currentTurn,
180-
currentPlayer](const auto &pos) {
176+
GenerateBoard(m_CurrentGame.GetBoard(), [this, selectedCard, currentTurn,
177+
currentPlayer](const auto &pos) {
181178
if (!selectedCard->has_value()) {
182179
std::cout << "No card selected!\n";
180+
const auto left = m_CurrentGame.GetBoard().GetLeft();
181+
std::cout << "In Lambda: " << left.first << " " << left.second << '\n';
183182
return;
184183
}
185184

186-
std::cout << selectedCard->value().GetValue();
187-
188-
std::cout << "here1";
189-
190-
std::cout << "here2";
191185
auto properCard = selectedCard->value();
192-
std::cout << "here3";
193-
if (m_CurrentGame->GetBoard().InsertCard(properCard, pos, currentTurn)) {
186+
187+
if (m_CurrentGame.GetBoard().InsertCard(properCard, pos, currentTurn)) {
194188
std::cout << "here4";
195-
if (m_CurrentGame->CheckWinningConditions()) {
196-
std::cout << "here5";
189+
if (m_CurrentGame.CheckWinningConditions()) {
197190
ShowWinningMessage(QString::fromStdString(currentPlayer.GetUserName()));
198191
return;
199192
}
200193

201-
std::cout << "here6";
202-
203-
m_CurrentGame->SetNextPlayerTurn(currentTurn == PlayerTurn::Player1
204-
? PlayerTurn::Player2
205-
: PlayerTurn::Player1);
194+
m_CurrentGame.SetNextPlayerTurn(currentTurn == PlayerTurn::Player1
195+
? PlayerTurn::Player2
196+
: PlayerTurn::Player1);
206197

207-
std::cout << "here7";
208198
DrawGame();
209-
// m_StackedWidget->repaint();
210199
} else {
211200
std::cout << std::format("Card {} could not be inserted at ({}, {})\n",
212201
properCard.GetValue(), pos.first, pos.second);
@@ -252,28 +241,26 @@ void AntrenamentWidget::ShowWinningMessage(const QString &winnerName) {
252241
layout->addWidget(okButton);
253242
connect(okButton, &QPushButton::clicked, this, [this, winningWidget, winnerName] {
254243
m_StackedWidget->removeWidget(winningWidget);
255-
if (winnerName == QString::fromStdString(m_CurrentGame->GetPlayer1().GetUserName())) {
244+
if (winnerName == QString::fromStdString(m_CurrentGame.GetPlayer1().GetUserName())) {
256245
++m_Player1Score;
257246
} else {
258247
++m_Player2Score;
259248
}
260-
UpdateScoreLabel(m_CurrentGame->GetPlayer1().GetUserName(),
261-
m_CurrentGame->GetPlayer2().GetUserName());
249+
UpdateScoreLabel(m_CurrentGame.GetPlayer1().GetUserName(),
250+
m_CurrentGame.GetPlayer2().GetUserName());
262251
if (++m_GamesPlayed < 3) {
263-
m_CurrentGame = nullptr;
264-
m_CurrentGame =
265-
std::make_unique<Antrenament>(m_CurrentGame->GetPlayer1().GetUserName(),
266-
m_CurrentGame->GetPlayer2().GetUserName());
252+
m_CurrentGame = {m_CurrentGame.GetPlayer1().GetUserName(),
253+
m_CurrentGame.GetPlayer2().GetUserName()};
267254
DrawGame();
268255
} else {
269256
const auto finalScoreWidget = new QWidget(this);
270257
const auto finalLayout = new QVBoxLayout(finalScoreWidget);
271258

272259
const auto finalScoreLabel = new QLabel(
273260
QString("Final Score:\n%1: %2\n%3: %4")
274-
.arg(QString::fromStdString(m_CurrentGame->GetPlayer1().GetUserName()))
261+
.arg(QString::fromStdString(m_CurrentGame.GetPlayer1().GetUserName()))
275262
.arg(m_Player1Score)
276-
.arg(QString::fromStdString(m_CurrentGame->GetPlayer2().GetUserName()))
263+
.arg(QString::fromStdString(m_CurrentGame.GetPlayer2().GetUserName()))
277264
.arg(m_Player2Score),
278265
this);
279266
QFont finalScoreFont = finalScoreLabel->font();
@@ -291,7 +278,6 @@ void AntrenamentWidget::ShowWinningMessage(const QString &winnerName) {
291278
m_GamesPlayed = 0;
292279
m_Player1Score = 0;
293280
m_Player2Score = 0;
294-
m_CurrentGame = nullptr;
295281
DrawGame();
296282
});
297283

src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <Interface/MainWindow.h>
44

5+
#include "GameModes/Antrenament.h"
6+
57
int main(int argc, char *argv[]) {
68
QApplication app(argc, argv);
79

@@ -10,4 +12,13 @@ int main(int argc, char *argv[]) {
1012
MainWindow mainWindow;
1113
mainWindow.show();
1214
return QApplication::exec();
15+
16+
// Antrenament antrenament("Player 1", "Player 2");
17+
//
18+
// auto cardOne = antrenament.GetPlayer1().GetHand()[0];
19+
// const auto success = antrenament.GetBoard().InsertCard(cardOne, {0, 0}, PlayerTurn::Player1);
20+
//
21+
// std::cout << "Card inserted: " << success << '\n';
22+
//
23+
// return 0;
1324
}

tests/BoardTests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
//
44

55
#define CATCH_CONFIG_MAIN
6+
67
#include <catch2/catch_all.hpp>
78
#include <iostream>
89

9-
#include "../src/Card/Card.h"
10-
#include "../src/GameBoard/Board.h"
10+
#include "../include/GameComponents/Board.h"
11+
#include "../include/GameComponents/Card.h"
1112

1213
TEST_CASE("Card should be inserted successfully", "[Board]") {
1314
Board board{3};

0 commit comments

Comments
 (0)