diff --git a/Chinczyk188/Board.cpp b/Chinczyk188/Board.cpp index ca69324..ca3015d 100644 --- a/Chinczyk188/Board.cpp +++ b/Chinczyk188/Board.cpp @@ -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: diff --git a/Chinczyk188/Engine.cpp b/Chinczyk188/Engine.cpp index d1c8730..c20e216 100644 --- a/Chinczyk188/Engine.cpp +++ b/Chinczyk188/Engine.cpp @@ -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) { diff --git a/Chinczyk188/Engine.hpp b/Chinczyk188/Engine.hpp index ca3064c..fac3445 100644 --- a/Chinczyk188/Engine.hpp +++ b/Chinczyk188/Engine.hpp @@ -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 = ""; diff --git a/Chinczyk188/res/audio/timgormly_incorrect.ogg b/Chinczyk188/res/audio/timgormly_incorrect.ogg new file mode 100644 index 0000000..fc55e09 Binary files /dev/null and b/Chinczyk188/res/audio/timgormly_incorrect.ogg differ