From 21cccbd8751d0698fdc4c6250b813b5d5d231779 Mon Sep 17 00:00:00 2001 From: marie3003 <marie.viktoria.becker@gmail.com> Date: Sun, 15 Dec 2024 21:57:18 +0100 Subject: [PATCH] delete trump color request --- CMakeLists.txt | 4 -- src/client/GameController.cpp | 5 +++ src/client/GameController.h | 5 +++ src/client/panels/MainGamePanelWizard.cpp | 2 +- src/common/game_state/game_state.cpp | 1 - .../network/requests/client_request.cpp | 6 --- src/common/network/requests/client_request.h | 1 - .../requests/decide_trump_color_request.cpp | 38 ------------------- .../requests/decide_trump_color_request.h | 32 ---------------- src/server/request_handler.cpp | 17 --------- 10 files changed, 11 insertions(+), 100 deletions(-) delete mode 100644 src/common/network/requests/decide_trump_color_request.cpp delete mode 100644 src/common/network/requests/decide_trump_color_request.h diff --git a/CMakeLists.txt b/CMakeLists.txt index acf1a3c..5fada45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ set(CLIENT_SOURCE_FILES src/common/game_state/cards/deck.cpp src/common/game_state/cards/deck.h # client requests src/common/network/requests/client_request.cpp src/common/network/requests/client_request.h - src/common/network/requests/decide_trump_color_request.cpp src/common/network/requests/decide_trump_color_request.h src/common/network/requests/estimate_tricks_request.cpp src/common/network/requests/estimate_tricks_request.h src/common/network/requests/join_game_request.cpp src/common/network/requests/join_game_request.h src/common/network/requests/leave_game_request.cpp src/common/network/requests/leave_game_request.h @@ -50,8 +49,6 @@ set(CLIENT_SOURCE_FILES src/common/serialization/json_utils.h src/common/serialization/uuid_generator.h src/common/serialization/unique_serializable.cpp src/common/serialization/unique_serializable.h - src/common/network/requests/decide_trump_color_request.cpp - src/common/network/requests/decide_trump_color_request.h src/common/network/requests/leave_game_request.cpp src/common/network/requests/leave_game_request.h src/common/network/requests/estimate_tricks_request.cpp @@ -84,7 +81,6 @@ set(SERVER_SOURCE_FILES src/common/game_state/cards/deck.cpp src/common/game_state/cards/deck.h # client requests src/common/network/requests/client_request.cpp src/common/network/requests/client_request.h - src/common/network/requests/decide_trump_color_request.cpp src/common/network/requests/decide_trump_color_request.h src/common/network/requests/estimate_tricks_request.cpp src/common/network/requests/estimate_tricks_request.h src/common/network/requests/join_game_request.cpp src/common/network/requests/join_game_request.h src/common/network/requests/leave_game_request.cpp src/common/network/requests/leave_game_request.h diff --git a/src/client/GameController.cpp b/src/client/GameController.cpp index 5cbe6ed..5e48993 100644 --- a/src/client/GameController.cpp +++ b/src/client/GameController.cpp @@ -308,4 +308,9 @@ void GameController::showGameOverMessage() { if(buttonClicked == wxID_OK) { GameController::_gameWindow->Close(); } +} + +void GameController::closeGameWindow() +{ + GameController::_gameWindow->Close(); } \ No newline at end of file diff --git a/src/client/GameController.h b/src/client/GameController.h index 26413bb..116b46c 100644 --- a/src/client/GameController.h +++ b/src/client/GameController.h @@ -91,6 +91,11 @@ public: */ static void showGameOverMessage(); + /** + * @brief Closes Game Window. + */ + static void closeGameWindow(); + private: static GameWindow* _gameWindow; ///< The window which contains all panels shown to the user. static ConnectionPanel* _connectionPanel; ///< The pannel used to connect to the game. diff --git a/src/client/panels/MainGamePanelWizard.cpp b/src/client/panels/MainGamePanelWizard.cpp index 327acee..85fd851 100644 --- a/src/client/panels/MainGamePanelWizard.cpp +++ b/src/client/panels/MainGamePanelWizard.cpp @@ -71,7 +71,7 @@ void MainGamePanelWizard::buildGameState(game_state* gameState, player* me) } else if (me->has_left_game() == true) { - GameController::showGameOverMessage(); + GameController::closeGameWindow(); return; } else { diff --git a/src/common/game_state/game_state.cpp b/src/common/game_state/game_state.cpp index b7f3350..e3b4a24 100644 --- a/src/common/game_state/game_state.cpp +++ b/src/common/game_state/game_state.cpp @@ -249,7 +249,6 @@ void game_state::determine_trump_color() const 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() } } } diff --git a/src/common/network/requests/client_request.cpp b/src/common/network/requests/client_request.cpp index bbf4c2d..8077e96 100644 --- a/src/common/network/requests/client_request.cpp +++ b/src/common/network/requests/client_request.cpp @@ -5,7 +5,6 @@ #include "client_request.h" #include "play_card_request.h" #include "estimate_tricks_request.h" -#include "decide_trump_color_request.h" #include "join_game_request.h" #include "start_game_request.h" #include "leave_game_request.h" @@ -18,7 +17,6 @@ const std::unordered_map<std::string, RequestType> client_request::_string_to_re {"start_game", RequestType::start_game}, {"play_card", RequestType::play_card}, {"estimate_tricks", RequestType::estimate_tricks}, - {"decide_trump_color", RequestType::decide_trump_color}, {"leave_game", RequestType::leave_game} }; // for serialization @@ -27,7 +25,6 @@ const std::unordered_map<RequestType, std::string> client_request::_request_type { RequestType::start_game, "start_game"}, { RequestType::play_card, "play_card"}, {RequestType::estimate_tricks, "estimate_tricks"}, - {RequestType::decide_trump_color, "decide_trump_color"}, {RequestType::leave_game, "leave_game"} }; @@ -108,9 +105,6 @@ client_request* client_request::from_json(const rapidjson::Value &json) { else if (request_type == RequestType::estimate_tricks) { return estimate_tricks_request::from_json(json); } - else if (request_type == RequestType::decide_trump_color) { - return decide_trump_color_request::from_json(json); - } else if (request_type == RequestType::leave_game) { return leave_game_request::from_json(json); } diff --git a/src/common/network/requests/client_request.h b/src/common/network/requests/client_request.h index 1182d14..4b4de0f 100644 --- a/src/common/network/requests/client_request.h +++ b/src/common/network/requests/client_request.h @@ -22,7 +22,6 @@ enum RequestType { join_game, start_game, play_card, - decide_trump_color, estimate_tricks, leave_game }; diff --git a/src/common/network/requests/decide_trump_color_request.cpp b/src/common/network/requests/decide_trump_color_request.cpp deleted file mode 100644 index 94ac5ee..0000000 --- a/src/common/network/requests/decide_trump_color_request.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by martinalavanya on 09.11.24. -// - -#include "decide_trump_color_request.h" - -#ifdef WIZARD_SERVER -#include "../../../server/game_instance_manager.h" -#include "../../../server/game_instance.h" -#endif - -// Public constructor -decide_trump_color_request::decide_trump_color_request(std::string game_id, std::string player_id, int trump_color) - : client_request( client_request::create_base_class_properties(RequestType::decide_trump_color, uuid_generator::generate_uuid_v4(), player_id, game_id) ) -{ - _trump_color = trump_color; -} - -// private constructor for deserialization -decide_trump_color_request::decide_trump_color_request(client_request::base_class_properties props, int trump_color) : - client_request(props), - _trump_color(trump_color) -{ } - -decide_trump_color_request* decide_trump_color_request::from_json(const rapidjson::Value &json) { - base_class_properties props = client_request::extract_base_class_properties(json); - if (json.HasMember("trump_color") ) { - return new decide_trump_color_request(props, json["trump_color"].GetInt()); - } else { - throw WizardException("Could not find 'trump_color' in decide_trump_color_request"); - } -} - -void decide_trump_color_request::write_into_json(rapidjson::Value &json, - rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> &allocator) const { - client_request::write_into_json(json, allocator); - json.AddMember("trump_color", rapidjson::Value(this->_trump_color),allocator); -} diff --git a/src/common/network/requests/decide_trump_color_request.h b/src/common/network/requests/decide_trump_color_request.h deleted file mode 100644 index f8f478c..0000000 --- a/src/common/network/requests/decide_trump_color_request.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Created by Manuel on 29.01.2021. -// - -#ifndef WIZARD_DECIDE_TRUMP_COLOR_REQUEST_H -#define WIZARD_DECIDE_TRUMP_COLOR_REQUEST_H - -#include <string> -#include "client_request.h" -#include "../../../../rapidjson/include/rapidjson/document.h" - -class decide_trump_color_request : public client_request { - -private: - int _trump_color; - - /* - * Private constructor for deserialization - */ - decide_trump_color_request(base_class_properties, int val); - -public: - - [[nodiscard]] int get_trump_color() const { return this->_trump_color; } - - decide_trump_color_request(std::string game_id, std::string player_id, int trump_color = 1); // why default value of 1?? - virtual void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override; - static decide_trump_color_request* from_json(const rapidjson::Value& json); -}; - - -#endif //WIZARD_DECIDE_TRUMP_COLOR_REQUEST_H \ No newline at end of file diff --git a/src/server/request_handler.cpp b/src/server/request_handler.cpp index 081e78c..30a67a9 100644 --- a/src/server/request_handler.cpp +++ b/src/server/request_handler.cpp @@ -13,7 +13,6 @@ #include "../common/network/requests/join_game_request.h" #include "../common/network/requests/estimate_tricks_request.h" -#include "../common/network/requests/decide_trump_color_request.h" #include "../common/network/requests/play_card_request.h" #include "../common/network/requests/leave_game_request.h" @@ -111,22 +110,6 @@ request_response* request_handler::handle_request(const client_request* const re } return new request_response("", req_id, false, nullptr, err); } - // ##################### DECIDE TRUMP COLOR ##################### // - /* - case RequestType:: decide_trump_color: { - //TODO: figure out where to get trick estimate from and how to handle request - if (game_instance_manager::try_get_player_and_game_instance(player_id, player, game_instance_ptr, err)) { - int trump_color = ((decide_trump_color_request* )req)->get_trump_color(); //call getter function in decide trump color request - if (game_instance_ptr->decide_trump_color(player, trump_color, err)) { // randomly selects number between 1 and 4 - return new request_response(game_instance_ptr->get_id(), req_id, true, - game_instance_ptr->get_game_state()->to_json(), err); - } - } - return new request_response("", req_id, false, nullptr, err); - - } - */ - // ##################### LEAVE GAME ##################### // case RequestType::leave_game: { // Case 1: player is in a game -- GitLab