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;
while (this->manualUpdate()) {
while (this->manualUpdate() && this->running()) {
sf::Event currentEvent = this->lastEvent;
switch (currentEvent.type) {
@@ -233,7 +233,6 @@ void Board::selectAField(short &pickStatus, short &field) {
case sf::Event::Closed:
this->closeWindow();
// Zamknięcie okna powinno wyjść z tej pętli
pickStatus = 8;
break;
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";
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) {
@@ -130,15 +135,17 @@ void Engine::nextTurn() {
}
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;
// 4 pionki na planszy - musi ruszyć pionek, o ile może
case 4:
// TODO
pickAPlace = true;
this->pawnmoveBuffer.play();
break;
}
@@ -181,7 +188,7 @@ void Engine::nextTurn() {
}
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ć
@@ -199,7 +206,14 @@ void Engine::nextTurn() {
if (pickAPlace) {
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 {
// Nadpisz moveResult jeżeli gracz nie wybiera pionka
moveResult = true;
@@ -251,6 +265,32 @@ void Engine::nextTurn() {
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.
*
@@ -258,7 +298,6 @@ void Engine::nextTurn() {
*
* @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) {
@@ -276,7 +315,6 @@ short Engine::getFirstPawnAtBase(short 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) {
@@ -295,7 +333,6 @@ short Engine::getFirstPawnNotAtBase(short color) {
*
* @return Returns true on success, false on failure
*/
short Engine::spawnPiece(short color, short pawnId) {
short * relativePieces = players[color].getRelativePawns();
if (relativePieces[pawnId] == -1) {

View File

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

Binary file not shown.