actually move pawns, add some helper functions, fix text rendering
first "playable" prototype so far
This commit is contained in:
@@ -288,9 +288,11 @@ void Board::drawPawn(short color, short field, short howMany) {
|
|||||||
|
|
||||||
if (howMany > 1) {
|
if (howMany > 1) {
|
||||||
sf::Text number(std::to_string(howMany), Ubuntu);
|
sf::Text number(std::to_string(howMany), Ubuntu);
|
||||||
number.setCharacterSize(30);
|
number.setCharacterSize(48);
|
||||||
number.setFillColor(sf::Color::Black);
|
number.setFillColor(sf::Color::White);
|
||||||
number.setPosition(XY.x, XY.y);
|
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);
|
this->piecesText.push_back(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,8 +301,8 @@ void Board::drawPawn(short color, short field, short howMany) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Board::drawPawns() {
|
void Board::drawPawns() {
|
||||||
/*this->pieces.clear();
|
this->pieces.clear();
|
||||||
this->piecesText.clear();*/
|
this->piecesText.clear();
|
||||||
for (int i = 0; i < 121; i++) {
|
for (int i = 0; i < 121; i++) {
|
||||||
// Wyznacz kolor i zlicz pionki
|
// Wyznacz kolor i zlicz pionki
|
||||||
short color = -1;
|
short color = -1;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void Engine::initializeGame() {
|
|||||||
// 3. najmniej znaczący bit informuje o zajęciu pola
|
// 3. najmniej znaczący bit informuje o zajęciu pola
|
||||||
// Ponadto przyjmujemy, że jeśli tylko 0 miejsce jest
|
// Ponadto przyjmujemy, że jeśli tylko 0 miejsce jest
|
||||||
// zajęte, to możemy wyświetlić
|
// 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;
|
pickAPlace = false;
|
||||||
std::cout << currentPlayer.getName() << " wychodzi "
|
std::cout << currentPlayer.getName() << " wychodzi "
|
||||||
<< currentPlayer.pawnsActive + 1 << ". pionkiem z bazy.\n";
|
<< 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->pawnmoveBuffer.play();
|
||||||
this->board.smartSleep(2000);
|
this->board.smartSleep(2000);
|
||||||
break;
|
break;
|
||||||
@@ -160,6 +161,11 @@ void Engine::nextTurn() {
|
|||||||
// TODO: znajdź ten pionek i ustaw selectedField na niego!!!
|
// TODO: znajdź ten pionek i ustaw selectedField na niego!!!
|
||||||
std::cout << currentPlayer.getName() << " rusza jedyny pionek "
|
std::cout << currentPlayer.getName() << " rusza jedyny pionek "
|
||||||
<< diceRoll << " pol do przodu.\n";
|
<< 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->pawnmoveBuffer.play();
|
||||||
this->board.smartSleep(2000);
|
this->board.smartSleep(2000);
|
||||||
break;
|
break;
|
||||||
@@ -245,6 +251,42 @@ void Engine::nextTurn() {
|
|||||||
return;
|
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
|
* @brief Put the piece onto the board
|
||||||
*
|
*
|
||||||
@@ -259,6 +301,7 @@ short Engine::spawnPiece(short color, short pawnId) {
|
|||||||
if (relativePieces[pawnId] == -1) {
|
if (relativePieces[pawnId] == -1) {
|
||||||
players[color].sendToBoard(pawnId);
|
players[color].sendToBoard(pawnId);
|
||||||
this->board.fields[relPosToField(color, relativePieces[pawnId])][pawnId] = color + 4;
|
this->board.fields[relPosToField(color, relativePieces[pawnId])][pawnId] = color + 4;
|
||||||
|
this->board.fields[getPawnInitialPosition(color, pawnId)][pawnId] = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -335,8 +378,10 @@ bool Engine::movePiece(short color, short field, short steps) { // podajemy colo
|
|||||||
// - jeśli ma, musimy go (/je) zbić
|
// - jeśli ma, musimy go (/je) zbić
|
||||||
if (isNewFieldOccupied) takePawns(occupyingColor, newField);
|
if (isNewFieldOccupied) takePawns(occupyingColor, newField);
|
||||||
// - w końcu, dopisujemy pionek bieżącego gracza
|
// - 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);
|
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ż
|
// - po przesunięciu jednego z pionków kończymy pętlę, ponieważ
|
||||||
// nie chcemy przesuwać kolejnych pionków
|
// nie chcemy przesuwać kolejnych pionków
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class Engine {
|
|||||||
short spawnPiece(short color, short pawnId);
|
short spawnPiece(short color, short pawnId);
|
||||||
short takePawns(short color, short field);
|
short takePawns(short color, short field);
|
||||||
bool movePiece(short color, short field, short steps);
|
bool movePiece(short color, short field, short steps);
|
||||||
|
short getFirstPawnAtBase(short color);
|
||||||
|
short getFirstPawnNotAtBase(short color);
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
bool dicerollLoaded = true;
|
bool dicerollLoaded = true;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Player {
|
|||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
std::vector<Pawn> pawns;
|
std::vector<Pawn> pawns;
|
||||||
short color;
|
short color;
|
||||||
short relativePawns[4] = {-1};
|
short relativePawns[4] = {-1, -1, -1, -1};
|
||||||
|
|
||||||
int rollCount = 0;
|
int rollCount = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user