diff --git a/assets/card_1.png b/assets/card_15_1.png similarity index 100% rename from assets/card_1.png rename to assets/card_15_1.png diff --git a/assets/card_2.png b/assets/card_15_2.png similarity index 100% rename from assets/card_2.png rename to assets/card_15_2.png diff --git a/assets/card_3.png b/assets/card_15_3.png similarity index 100% rename from assets/card_3.png rename to assets/card_15_3.png diff --git a/assets/card_4.png b/assets/card_15_4.png similarity index 100% rename from assets/card_4.png rename to assets/card_15_4.png diff --git a/src/client/panels/MainGamePanelWizard.cpp b/src/client/panels/MainGamePanelWizard.cpp index 9d8f3b11fee446bed2f057e2d3d2d16629c9c94a..03c600637865455919996b1c3aa88414c3f8817f 100644 --- a/src/client/panels/MainGamePanelWizard.cpp +++ b/src/client/panels/MainGamePanelWizard.cpp @@ -305,8 +305,10 @@ void MainGamePanelWizard::buildTrumpCard(wxGridBagSizer* sizer, game_state* game trumpText->SetForegroundColour(*wxWHITE); trumpText->SetFont(regularFont); int trumpColor = gameState->get_trump_color(); + int trumpCardValue = gameState->get_trump_card_value(); - std::string cardImage = "assets/card_" + std::to_string(trumpColor) + ".png"; + std::string cardImage = "assets/card_" + std::to_string(trumpCardValue) + "_" + std::to_string(trumpColor)+".png"; + std::cout << cardImage << std::endl; ImagePanel* cardPanel = new ImagePanel(trumpPanel, cardImage, wxBITMAP_TYPE_ANY, wxDefaultPosition, MainGamePanelWizard::cardSize); diff --git a/src/client/panels/TrickEstimationPanel.cpp b/src/client/panels/TrickEstimationPanel.cpp index a29ca2b4973b1452c5cbcc191260b1cca073375c..581df62ff2a02fd7c3dc0e2e9afdd6fcf4a26647 100644 --- a/src/client/panels/TrickEstimationPanel.cpp +++ b/src/client/panels/TrickEstimationPanel.cpp @@ -157,8 +157,10 @@ void TrickEstimationPanel::buildTrumpColor(wxGridBagSizer *sizer, game_state *ga trumpText->SetFont(regularFontTrickBig); int trumpColor = gameState->get_trump_color(); + int trumpCardValue = gameState->get_trump_card_value(); - std::string cardImage = "assets/card_" + std::to_string(trumpColor) + ".png"; + std::string cardImage = "assets/card_" + std::to_string(trumpCardValue) + "_" + std::to_string(trumpColor)+".png"; + std::cout << cardImage << std::endl; ImagePanel* cardPanel = new ImagePanel(trumpPanel, cardImage, wxBITMAP_TYPE_ANY, wxDefaultPosition, TrickEstimationPanel::cardSize); diff --git a/src/common/game_state/game_state.cpp b/src/common/game_state/game_state.cpp index 78a0dd9152ef756c7389568bcea4a55e5ce80463..845f15781274075902bc53a8ba4f07643dbdcd3b 100644 --- a/src/common/game_state/game_state.cpp +++ b/src/common/game_state/game_state.cpp @@ -1,5 +1,6 @@ #include "game_state.h" #include <vector> +#include <unordered_map> #include "../exceptions/WizardException.h" #include "../serialization/vector_utils.h" @@ -21,6 +22,7 @@ game_state::game_state(const std::string& id) : unique_serializable(id) { _trick_starting_player_idx = new serializable_value<int>(0); _current_player_idx = new serializable_value<int>(0); _trump_color = new serializable_value<int>(0); + _trump_card_value = new serializable_value<int>(0); _trick_estimate_sum = new serializable_value<int>(0); } @@ -30,7 +32,7 @@ game_state::game_state(const std::string& id, const std::vector<player*>& player serializable_value<bool>* is_estimation_phase, serializable_value<int>* round_number, serializable_value<int>* trick_number, serializable_value<int>* starting_player_idx, serializable_value<int>* trick_starting_player_idx, serializable_value<int>* current_player_idx, - serializable_value<int>* trump_color, serializable_value<int>* trick_estimate_sum) + serializable_value<int>* trump_color, serializable_value<int>* trump_card_value, serializable_value<int>* trick_estimate_sum) : unique_serializable(id), _players(players), _deck(deck), @@ -47,29 +49,8 @@ game_state::game_state(const std::string& id, const std::vector<player*>& player _trick_starting_player_idx(trick_starting_player_idx), _current_player_idx(current_player_idx), _trump_color(trump_color), - _trick_estimate_sum(trick_estimate_sum) -{ - //checks if all player names are unique. if not, add _1, _2 etc. to the duplicate names - std::unordered_map<std::string, int> name_counts; // track occurrences of names - - for (player* p : _players) { - std::string original_name = p->get_player_name(); - std::string unique_name = original_name; - if (name_counts[original_name] > 0) { - // Assign a unique suffix based on the current count - unique_name = original_name + "_" + std::to_string(name_counts[original_name]); - } - - // Increment count for new and original name - name_counts[original_name]++; - name_counts[unique_name]++; - - // update player's name if modified - if (unique_name != original_name) { - p->set_player_name(unique_name); - } - } -} + _trump_card_value(trump_card_value), + _trick_estimate_sum(trick_estimate_sum){} // public constructor game_state::game_state() : unique_serializable() @@ -89,9 +70,8 @@ game_state::game_state() : unique_serializable() _trick_starting_player_idx = new serializable_value<int>(0); _current_player_idx = new serializable_value<int>(0); _trump_color = new serializable_value<int>(0); + _trump_card_value = new serializable_value<int>(0); _trick_estimate_sum = new serializable_value<int>(0); - - } // destructor @@ -112,6 +92,7 @@ game_state::~game_state() delete _trick_starting_player_idx; delete _current_player_idx; delete _trump_color; + delete _trump_card_value; delete _trick_estimate_sum; _deck = nullptr; @@ -128,6 +109,7 @@ game_state::~game_state() _trick_starting_player_idx = nullptr; _current_player_idx = nullptr; _trump_color = nullptr; + _trump_card_value = nullptr; _trick_estimate_sum = nullptr; } @@ -150,6 +132,11 @@ int game_state::get_trump_color() const return _trump_color->get_value(); } +int game_state::get_trump_card_value() const +{ + return _trump_card_value->get_value(); +} + player* game_state::get_trick_starting_player() const { if(_trick_starting_player_idx == nullptr || _players.empty()) { @@ -245,13 +232,16 @@ void game_state::determine_trump_color() const { if(_round_number->get_value() * _players.size() == 60) { _trump_color->set_value(0); // there is no trump since it is the last round + _trump_card_value->set_value(0); } else { card* trump_card = _deck->draw_trump(); if (trump_card->get_color() != 0){ _trump_color->set_value(trump_card->get_color()); + _trump_card_value->set_value(trump_card->get_value()); } else if (trump_card->get_value() == 0) { //jester _trump_color->set_value(0); + _trump_card_value->set_value(0); } else if (trump_card->get_value() == 14){ //wizard // for now: just randomly generates number @@ -259,6 +249,7 @@ void game_state::determine_trump_color() const std::mt19937 gen(rd()); std::uniform_int_distribution<> distrib(1, 4); _trump_color->set_value(distrib(gen)); + _trump_card_value->set_value(15); // TODO: include get trump_color_request() } } @@ -471,7 +462,7 @@ bool game_state::remove_player(player *player_ptr, std::string &err) } } -bool game_state::add_player(player* player, std::string& err) +bool game_state::add_player(player* player_, std::string& err) { if (_is_started->get_value()) { err = "Could not join game, because the requested game is already started."; @@ -485,12 +476,33 @@ bool game_state::add_player(player* player, std::string& err) err = "Could not join game, because the max number of players is already reached."; return false; } - if (std::ranges::find(_players, player) != _players.end()) { + if (std::ranges::find(_players, player_) != _players.end()) { err = "Could not join game, because this player is already subscribed to this game."; return false; } - _players.push_back(player); + _players.push_back(player_); + + //checks if all player names are unique. if not, add _1, _2 etc. to the duplicate names + std::unordered_map<std::string, int> name_counts; // track occurrences of names + + for (player* p: _players) { + std::string original_name = p->get_player_name(); + std::string unique_name = original_name; + if (name_counts[original_name] > 0) { + // Assign a unique suffix based on the current count + unique_name = original_name + "_" + std::to_string(name_counts[original_name]); + } + + // Increment count for new and original name + name_counts[original_name]++; + name_counts[unique_name]++; + + // update player's name if modified + if (unique_name != original_name) { + p->set_player_name(unique_name); + } + } return true; } @@ -560,6 +572,10 @@ void game_state::write_into_json(rapidjson::Value &json, _trump_color->write_into_json(trump_color_val, allocator); json.AddMember("trump_color", trump_color_val, allocator); + rapidjson::Value trump_card_value_val(rapidjson::kObjectType); + _trump_card_value->write_into_json(trump_card_value_val, allocator); + json.AddMember("trump_card_value", trump_card_value_val, allocator); + rapidjson::Value trick_estimate_sum_val(rapidjson::kObjectType); _trick_estimate_sum->write_into_json(trick_estimate_sum_val, allocator); json.AddMember("trick_estimate_sum_val", trick_estimate_sum_val, allocator); @@ -583,6 +599,7 @@ game_state* game_state::from_json(const rapidjson::Value &json) { && json.HasMember("trick_starting_player_idx") && json.HasMember("current_player_idx") && json.HasMember("trump_color") + && json.HasMember("trump_card_value") && json.HasMember("trick_estimate_sum_val")) { std::vector<player*> deserialized_players; @@ -605,6 +622,7 @@ game_state* game_state::from_json(const rapidjson::Value &json) { serializable_value<int>::from_json(json["trick_starting_player_idx"].GetObject()), serializable_value<int>::from_json(json["current_player_idx"].GetObject()), serializable_value<int>::from_json(json["trump_color"].GetObject()), + serializable_value<int>::from_json(json["trump_card_value"].GetObject()), serializable_value<int>::from_json(json["trick_estimate_sum_val"].GetObject())); } throw WizardException("Failed to deserialize game_state. Required entries were missing."); diff --git a/src/common/game_state/game_state.h b/src/common/game_state/game_state.h index 2669091f8b1862c6b420347078cee175a128c405..ea96c7cbc02fc1c37b0e1037412cc28bc15445db 100644 --- a/src/common/game_state/game_state.h +++ b/src/common/game_state/game_state.h @@ -46,6 +46,7 @@ private: serializable_value<int>* _trick_starting_player_idx; ///< The index of the player that started the current trick. serializable_value<int>* _current_player_idx; ///< The index of the player that is currently playing. serializable_value<int>* _trump_color; ///< The trump color of the current round. + serializable_value<int>* _trump_card_value; ///< Value of the trump card to show in GUI. serializable_value<int>* _trick_estimate_sum; ///< The sum of trick estimates. // constructors @@ -71,6 +72,7 @@ private: * @param trick_starting_player_idx The trick starting player's index. * @param current_player_idx The current player's index. * @param trump_color The trump color. + * @param trump_card_value The value of the trump card to show in GUI. * @param trick_estimate_sum The sum of trick estimates. */ game_state( @@ -90,6 +92,7 @@ private: serializable_value<int>* trick_starting_player_idx, serializable_value<int>* current_player_idx, serializable_value<int>* trump_color, + serializable_value<int>* trump_card_value, serializable_value<int>* trick_estimate_sum ); @@ -218,6 +221,12 @@ public: */ [[nodiscard]] int get_trump_color() const; + /** + * @brief Gets the value of the trump card to display in GUI. + * @return The value of the trum card + */ + [[nodiscard]] int get_trump_card_value() const; + /** * @brief Gets the current player. * @return The current player.