audio feedback for wrong choice, ask the player repeatedly to pick a valid field

also prepared helper functions for checking if there is a possible move
This commit is contained in:
2025-01-28 00:05:48 +01:00
parent 79d53efea2
commit 39cd06e8f3
4 changed files with 50 additions and 10 deletions

View File

@@ -225,7 +225,7 @@ void Board::selectAField(short &pickStatus, short &field) {
sf::Vector2f mapped; sf::Vector2f mapped;
while (this->manualUpdate()) { while (this->manualUpdate() && this->running()) {
sf::Event currentEvent = this->lastEvent; sf::Event currentEvent = this->lastEvent;
switch (currentEvent.type) { switch (currentEvent.type) {
@@ -233,7 +233,6 @@ void Board::selectAField(short &pickStatus, short &field) {
case sf::Event::Closed: case sf::Event::Closed:
this->closeWindow(); this->closeWindow();
// Zamknięcie okna powinno wyjść z tej pętli // Zamknięcie okna powinno wyjść z tej pętli
pickStatus = 8;
break; break;
case sf::Event::MouseButtonPressed: case sf::Event::MouseButtonPressed:

View File

@@ -24,6 +24,11 @@ Engine::Engine(): currentPlayerIndex(0) {
std::cerr << "Nie udalo sie zaladowac efektu dzwiekowego wygranej.\n\n"; std::cerr << "Nie udalo sie zaladowac efektu dzwiekowego wygranej.\n\n";
this->tadaLoaded = false; this->tadaLoaded = false;
} }
if (!this->invalidBuffer.openFromFile("res/audio/timgormly_incorrect.ogg")) {
std::cerr << "Nie udalo sie zaladowac efektu dzwiekowego niepoprawnego wyboru.\n\n";
this->invalidLoaded = false;
}
} }
void Engine::addPlayer(const std::string& name, unsigned int seed, short color) { void Engine::addPlayer(const std::string& name, unsigned int seed, short color) {
@@ -130,15 +135,17 @@ void Engine::nextTurn() {
} }
break; break;
} else std::cout << "Podaj jedna z wymienionych odpowiedzi!\n> "; } else {
std::cout << "Podaj jedna z wymienionych odpowiedzi!\n> ";
this->invalidBuffer.play();
this->board.smartSleep(1000);
}
} }
break; break;
// 4 pionki na planszy - musi ruszyć pionek, o ile może // 4 pionki na planszy - musi ruszyć pionek, o ile może
case 4: case 4:
// TODO
pickAPlace = true; pickAPlace = true;
this->pawnmoveBuffer.play();
break; break;
} }
@@ -181,7 +188,7 @@ void Engine::nextTurn() {
} }
if (pickAPlace) { if (pickAPlace) {
std::cout << "Wybierz prosze pionek na planszy ktorym chcesz wykonac ruch.\n"; std::cout << "Wybierz prosze pionek na planszy, ktorym chcesz wykonac ruch.\n";
} }
// Użytkownik wybiera pionek na planszy, którym chce się ruszyć // Użytkownik wybiera pionek na planszy, którym chce się ruszyć
@@ -199,7 +206,14 @@ void Engine::nextTurn() {
if (pickAPlace) { if (pickAPlace) {
moveResult = this->movePiece(currentPlayer.getColor(), selectedField, diceRoll); moveResult = this->movePiece(currentPlayer.getColor(), selectedField, diceRoll);
if (!moveResult) std::cout << "Nie mozna wykonac tego ruchu.\n"; if (!moveResult) {
std::cout << "Nie mozesz wykonac tego ruchu.\n";
this->invalidBuffer.play();
this->board.smartSleep(1000);
// Jeżeli błąd nie jest wywołany wyłączeniem gry,
// to poproś gracza o ponowny wybór ruchu
if (this->board.running()) pickStatus = 0;
}
} else { } else {
// Nadpisz moveResult jeżeli gracz nie wybiera pionka // Nadpisz moveResult jeżeli gracz nie wybiera pionka
moveResult = true; moveResult = true;
@@ -251,6 +265,32 @@ void Engine::nextTurn() {
return; return;
} }
/**
* @brief Turn a field into the first pawn inside it.
*
* @param[in] color Player's color
* @param[in] field Given field
*
* @return Player's pawn ID, between 0 and 3.
*/
short Engine::fieldToFirstPawnId(short color, short field) {
// TODO
return 0;
}
/**
* @brief Iterates through player's pawns to check if they can move.
*
* @param[in] color Player's color
* @param[in] steps Amount of steps
*
* @return Returns the number of pawns which can be moved given the step count.
*/
short Engine::checkPossibleMoves(short color, short steps) {
// TODO
return 0;
}
/** /**
* @brief Returns the first pawn at a player's base. * @brief Returns the first pawn at a player's base.
* *
@@ -258,7 +298,6 @@ void Engine::nextTurn() {
* *
* @return The first pawn at base, or -1 if no pawns at base. * @return The first pawn at base, or -1 if no pawns at base.
*/ */
short Engine::getFirstPawnAtBase(short color) { short Engine::getFirstPawnAtBase(short color) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (players[color].getRelativePawns()[i] == -1) { if (players[color].getRelativePawns()[i] == -1) {
@@ -276,7 +315,6 @@ short Engine::getFirstPawnAtBase(short color) {
* *
* @return The first pawn at base, or -1 if no pawns at base. * @return The first pawn at base, or -1 if no pawns at base.
*/ */
short Engine::getFirstPawnNotAtBase(short color) { short Engine::getFirstPawnNotAtBase(short color) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (players[color].getRelativePawns()[i] != -1) { if (players[color].getRelativePawns()[i] != -1) {
@@ -295,7 +333,6 @@ short Engine::getFirstPawnNotAtBase(short color) {
* *
* @return Returns true on success, false on failure * @return Returns true on success, false on failure
*/ */
short Engine::spawnPiece(short color, short pawnId) { short Engine::spawnPiece(short color, short pawnId) {
short * relativePieces = players[color].getRelativePawns(); short * relativePieces = players[color].getRelativePawns();
if (relativePieces[pawnId] == -1) { if (relativePieces[pawnId] == -1) {

View File

@@ -29,14 +29,18 @@ class Engine {
bool movePiece(short color, short field, short steps); bool movePiece(short color, short field, short steps);
short getFirstPawnAtBase(short color); short getFirstPawnAtBase(short color);
short getFirstPawnNotAtBase(short color); short getFirstPawnNotAtBase(short color);
short fieldToFirstPawnId(short color, short field);
short checkPossibleMoves(short color, short steps);
// Audio // Audio
bool dicerollLoaded = true; bool dicerollLoaded = true;
bool pawnmoveLoaded = true; bool pawnmoveLoaded = true;
bool tadaLoaded = true; bool tadaLoaded = true;
bool invalidLoaded = true;
sf::Music dicerollBuffer; sf::Music dicerollBuffer;
sf::Music pawnmoveBuffer; sf::Music pawnmoveBuffer;
sf::Music tadaBuffer; sf::Music tadaBuffer;
sf::Music invalidBuffer;
// Pomocnicze // Pomocnicze
std::string winnerNickname = ""; std::string winnerNickname = "";

Binary file not shown.