diff --git a/Chinczyk188/Board.cpp b/Chinczyk188/Board.cpp index 063a6e8..ca69324 100644 --- a/Chinczyk188/Board.cpp +++ b/Chinczyk188/Board.cpp @@ -288,9 +288,11 @@ void Board::drawPawn(short color, short field, short howMany) { if (howMany > 1) { sf::Text number(std::to_string(howMany), Ubuntu); - number.setCharacterSize(30); - number.setFillColor(sf::Color::Black); - number.setPosition(XY.x, XY.y); + number.setCharacterSize(48); + number.setFillColor(sf::Color::White); + number.setPosition(XY.x - 12, XY.y - 30); // wartości dobrane empirycznie :) + number.setOutlineColor (sf::Color::Black); + number.setOutlineThickness(2); this->piecesText.push_back(number); } @@ -299,8 +301,8 @@ void Board::drawPawn(short color, short field, short howMany) { } void Board::drawPawns() { - /*this->pieces.clear(); - this->piecesText.clear();*/ + this->pieces.clear(); + this->piecesText.clear(); for (int i = 0; i < 121; i++) { // Wyznacz kolor i zlicz pionki short color = -1; diff --git a/Chinczyk188/Engine.cpp b/Chinczyk188/Engine.cpp index 2578dae..d1c8730 100644 --- a/Chinczyk188/Engine.cpp +++ b/Chinczyk188/Engine.cpp @@ -39,7 +39,7 @@ void Engine::initializeGame() { // 3. najmniej znaczący bit informuje o zajęciu pola // Ponadto przyjmujemy, że jeśli tylko 0 miejsce jest // zajęte, to możemy wyświetlić - this->board.fields[getPawnInitialPosition(playerColor, i)][0] = playerColor + 4; + this->board.fields[getPawnInitialPosition(playerColor, i)][i] = playerColor + 4; } } } @@ -107,7 +107,8 @@ void Engine::nextTurn() { pickAPlace = false; std::cout << currentPlayer.getName() << " wychodzi " << currentPlayer.pawnsActive + 1 << ". pionkiem z bazy.\n"; - this->spawnPiece(currentPlayer.getColor(), currentPlayer.pawnsActive + 1); + // Rusz pierwszy możliwy pionek w bazie: + this->spawnPiece(currentPlayer.getColor(), this->getFirstPawnAtBase(currentPlayer.getColor())); this->pawnmoveBuffer.play(); this->board.smartSleep(2000); break; @@ -160,6 +161,11 @@ void Engine::nextTurn() { // TODO: znajdź ten pionek i ustaw selectedField na niego!!! std::cout << currentPlayer.getName() << " rusza jedyny pionek " << diceRoll << " pol do przodu.\n"; + for (int i = 0; i < 4; i++) { + short* relativePawns = currentPlayer.getRelativePawns(); + if (relativePawns[i] >= 0) + this->movePiece(currentPlayer.getColor(), relPosToField(currentPlayer.getColor(), relativePawns[i]), diceRoll); + } this->pawnmoveBuffer.play(); this->board.smartSleep(2000); break; @@ -245,6 +251,42 @@ void Engine::nextTurn() { return; } +/** + * @brief Returns the first pawn at a player's base. + * + * @param[in] color Player's color + * + * @return The first pawn at base, or -1 if no pawns at base. + */ + +short Engine::getFirstPawnAtBase(short color) { + for (int i = 0; i < 4; i++) { + if (players[color].getRelativePawns()[i] == -1) { + // -1 => pionek jest w bazie + return i; + } + } + return -1; +} + +/** + * @brief Returns the first pawn at a player's base. + * + * @param[in] color Player's color + * + * @return The first pawn at base, or -1 if no pawns at base. + */ + +short Engine::getFirstPawnNotAtBase(short color) { + for (int i = 0; i < 4; i++) { + if (players[color].getRelativePawns()[i] != -1) { + // -1 => pionek jest w bazie + return i; + } + } + return -1; +} + /** * @brief Put the piece onto the board * @@ -259,6 +301,7 @@ short Engine::spawnPiece(short color, short pawnId) { if (relativePieces[pawnId] == -1) { players[color].sendToBoard(pawnId); this->board.fields[relPosToField(color, relativePieces[pawnId])][pawnId] = color + 4; + this->board.fields[getPawnInitialPosition(color, pawnId)][pawnId] = 0; return true; } return false; @@ -335,8 +378,10 @@ bool Engine::movePiece(short color, short field, short steps) { // podajemy colo // - jeśli ma, musimy go (/je) zbić if (isNewFieldOccupied) takePawns(occupyingColor, newField); // - w końcu, dopisujemy pionek bieżącego gracza - this->board.fields[field][i] = color + 4; + this->board.fields[newField][i] = color + 4; this->players[this->currentPlayerIndex].unsafeMovePiece(i, steps); + // oraz usuwamy z bieżącego pola + this->board.fields[field][i] = 0; // - po przesunięciu jednego z pionków kończymy pętlę, ponieważ // nie chcemy przesuwać kolejnych pionków return true; diff --git a/Chinczyk188/Engine.hpp b/Chinczyk188/Engine.hpp index f5e05a2..ca3064c 100644 --- a/Chinczyk188/Engine.hpp +++ b/Chinczyk188/Engine.hpp @@ -27,6 +27,8 @@ class Engine { short spawnPiece(short color, short pawnId); short takePawns(short color, short field); bool movePiece(short color, short field, short steps); + short getFirstPawnAtBase(short color); + short getFirstPawnNotAtBase(short color); // Audio bool dicerollLoaded = true; diff --git a/Chinczyk188/Player.hpp b/Chinczyk188/Player.hpp index 0ea36da..2790bd0 100644 --- a/Chinczyk188/Player.hpp +++ b/Chinczyk188/Player.hpp @@ -36,7 +36,7 @@ class Player { unsigned int seed; std::vector pawns; short color; - short relativePawns[4] = {-1}; + short relativePawns[4] = {-1, -1, -1, -1}; int rollCount = 0;