diff --git a/src/client/PlayerAction.cpp b/src/client/PlayerAction.cpp new file mode 100644 index 0000000..44a1594 --- /dev/null +++ b/src/client/PlayerAction.cpp @@ -0,0 +1,22 @@ +/** + * @file PlayerAction.cpp + * + * @author Yuzhe Guo + * @date 2025.12.07 + */ + +#include "PlayerAction.h" + +#include + +namespace UNO::CLIENT { + PlayerAction::PlayerAction(PlayerActionType type, PlayerActionPayload payload) : playerActionType(type), payload(std::move(payload)) + { + if (playerActionType == PlayerActionType::CONNECT && std::holds_alternative(payload) == false + || playerActionType == PlayerActionType::START_GAME && std::holds_alternative(payload) == false + || playerActionType == PlayerActionType::PLAY_CARD && std::holds_alternative(payload) == false + || playerActionType == PlayerActionType::DRAW_CARD && std::holds_alternative(payload) == false) { + throw std::invalid_argument("Payload type do not match"); + } + } +} // namespace UNO::CLIENT \ No newline at end of file diff --git a/src/client/PlayerAction.h b/src/client/PlayerAction.h new file mode 100644 index 0000000..4e4ba58 --- /dev/null +++ b/src/client/PlayerAction.h @@ -0,0 +1,38 @@ +/** + * @file PlayerAction.h + * + * @author Yuzhe Guo + * @date 2025.12.07 + */ +#pragma once +#include +#include + +#include "../game/Card.h" + +namespace UNO::CLIENT { + enum class PlayerActionType { CONNECT, START_GAME, PLAY_CARD, DRAW_CARD }; + + struct PlayerConnectPayload { + std::string playerName; + std::string host; + uint16_t port; + }; + + struct PlayerStartGamePayload {}; + + struct PlayerPlayCardPayload { + GAME::Card card; + }; + + struct PlayerDrawCardPayload {}; + + using PlayerActionPayload = std::variant; + + struct PlayerAction { + PlayerActionType playerActionType; + PlayerActionPayload payload; + + PlayerAction(PlayerActionType type, PlayerActionPayload payload); + }; +} // namespace UNO::CLIENT