diff --git a/Chinczyk188/Board.cpp b/Chinczyk188/Board.cpp index ca3015d..1fbab46 100644 --- a/Chinczyk188/Board.cpp +++ b/Chinczyk188/Board.cpp @@ -233,7 +233,7 @@ void Board::selectAField(short &pickStatus, short &field) { case sf::Event::Closed: this->closeWindow(); // Zamknięcie okna powinno wyjść z tej pętli - break; + return; case sf::Event::MouseButtonPressed: // Informacje musimy pobrać przy naciśnięciu, @@ -257,7 +257,9 @@ void Board::selectAField(short &pickStatus, short &field) { break; case sf::Event::Resized: - std::cout << "resized triggered: " << currentEvent.size.width << " " << currentEvent.size.height << "\n"; + #ifdef DEBUG + std::cout << "Resized event triggered: " << currentEvent.size.width << " " << currentEvent.size.height << "\n"; + #endif this->handleResize(currentEvent.size.width, currentEvent.size.height); break; diff --git a/Chinczyk188/Engine.cpp b/Chinczyk188/Engine.cpp index c20e216..aaeb01f 100644 --- a/Chinczyk188/Engine.cpp +++ b/Chinczyk188/Engine.cpp @@ -68,6 +68,7 @@ void Engine::nextTurn() { // Rysuj pionki // ... this->board.drawPawns(); + this->board.render(); // Rzut kostką if (dicerollLoaded) this->dicerollBuffer.play(); @@ -187,6 +188,12 @@ void Engine::nextTurn() { } + if (!isMovePossible) { + pickAPlace = false; + std::cout << "Niestety, nie mozna wykonac zadnego ruchu.\n"; + this->board.smartSleep(500); + } + if (pickAPlace) { std::cout << "Wybierz prosze pionek na planszy, ktorym chcesz wykonac ruch.\n"; } @@ -196,9 +203,9 @@ void Engine::nextTurn() { short pickStatus = 0; short selectedField = -1; if (!pickAPlace) pickStatus = 8; // pomiń pętlę - while (!moveResult) { + while (!moveResult && this->board.running()) { - while (pickStatus != 8) { + while (pickStatus != 8 && this->board.running()) { this->board.selectAField(pickStatus, selectedField); @@ -206,7 +213,7 @@ void Engine::nextTurn() { if (pickAPlace) { moveResult = this->movePiece(currentPlayer.getColor(), selectedField, diceRoll); - if (!moveResult) { + if (!moveResult && selectedField != -1) { std::cout << "Nie mozesz wykonac tego ruchu.\n"; this->invalidBuffer.play(); this->board.smartSleep(1000); @@ -221,7 +228,10 @@ void Engine::nextTurn() { } - std::cout << "(Engine.cpp) selected: " << selectedField << "\n"; + // Do debugowania zaznaczonego pola + #ifdef DEBUG + std::cout << "(Engine.cpp) selected: " << selectedField << "\n"; + #endif // Jeżeli gracz się ruszył, odtwórz dźwięk ruchu if (selectedField != -1) { diff --git a/Chinczyk188/Engine.hpp b/Chinczyk188/Engine.hpp index fac3445..2a5261f 100644 --- a/Chinczyk188/Engine.hpp +++ b/Chinczyk188/Engine.hpp @@ -30,7 +30,9 @@ class Engine { short getFirstPawnAtBase(short color); short getFirstPawnNotAtBase(short color); short fieldToFirstPawnId(short color, short field); + bool isMoveLegal(short color, short field, short steps); short checkPossibleMoves(short color, short steps); + short fieldToColor(short field); // Audio bool dicerollLoaded = true; diff --git a/Chinczyk188/Makefile b/Chinczyk188/Makefile index 3d0e6c1..27efc11 100644 --- a/Chinczyk188/Makefile +++ b/Chinczyk188/Makefile @@ -5,7 +5,7 @@ CC = "C:\\msys64\\mingw64\\bin\\g++.exe" DEPS = -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lopenal32 -lfreetype -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lpthread LINK = -L. -Lres/SFML/lib-mingw/ -FLAGS = -DSFML_STATIC # -DCHINCZYK188_IGNORE_USER_SEED +FLAGS = -DSFML_STATIC # -DCHINCZYK188_IGNORE_USER_SEED -DDEBUG OUTPUT = output.exe CPPSTD = c++17 diff --git a/Chinczyk188/Player.hpp b/Chinczyk188/Player.hpp index 2790bd0..cb82fd2 100644 --- a/Chinczyk188/Player.hpp +++ b/Chinczyk188/Player.hpp @@ -2,6 +2,7 @@ #include #include #include "Pawn.hpp" +#include "Utils.hpp" class Player { public: @@ -13,6 +14,7 @@ class Player { int getRollCount() const; short getColor() const; short* getRelativePawns(); + bool isPawnAtHome(short pawnId); void incrementRollCount(); @@ -27,6 +29,7 @@ class Player { short pawnsAtBase = 4; short pawnsActive = 0; short pawnsAtHome = 0; + void recalculatePawnStates(); bool hasWon() const; bool hasLeftBase = false;