From d5f996df6cde8097f57acc1c804e08379c05375f Mon Sep 17 00:00:00 2001 From: Kieran Kihn <114803508+kierankihn@users.noreply.github.com> Date: Tue, 9 Dec 2025 17:10:44 +0800 Subject: [PATCH] feat(client): add `PlayerAction` struct and payload types - Introduced `PlayerAction` to encapsulate player actions, including type and payload. - Added specific payload structures for connect, start game, play card, and draw card actions. --- src/client/PlayerAction.cpp | 22 +++++++++++++++++++++ src/client/PlayerAction.h | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/client/PlayerAction.cpp create mode 100644 src/client/PlayerAction.h 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