Commit Graph

119 Commits

Author SHA1 Message Date
Kieran Kihn
d1f87d8113 refactor(game): replace player iterator with player ID in GameState functions 2025-12-10 21:43:53 +08:00
Kieran Kihn
8d9f76eab3 refactor(game): standardize card color and type serialization format 2025-12-10 21:41:30 +08:00
Kieran Kihn
59f8ac8186 fix(client): add destructor to UnoClient for resource cleanup 2025-12-10 21:40:58 +08:00
Kieran Kihn
5ff38c2bde feat(client): validate and handle wild card type in handlePlayerPlayCard
- Added validation for wild card types and ensured proper color assignment.
- Updated `PlayerPlayCardPayload` to use ID and color instead of card object.
2025-12-10 21:40:37 +08:00
Kieran Kihn
592ae1ad23 refactor(ui): update Slint UI paths and update CMakeList.txt accordingly 2025-12-09 20:17:12 +08:00
Kieran Kihn
bea9caa078 feat(ui): add ConnectPage, StartPage, and MainWindow components
- Implemented `ConnectPage` to handle server connection input and initiation.
- Added `StartPage` to manage player readiness before starting the game.
- Created `MainWindow` to manage page transitions and callbacks.
2025-12-09 20:07:12 +08:00
Kieran Kihn
63e87aa3e9 feat(ui): add reusable Button and LabeledInput components using Slint 2025-12-09 20:06:58 +08:00
Kieran Kihn
7bb302a672 chore: include PlayerAction and GameUI in build targets 2025-12-09 20:06:22 +08:00
Kieran Kihn
4eecc0a269 feat(ui): add GameUI class for handling game UI and player actions
- Implemented `GameUI` for managing game state transitions and player interactions.
- Integrated Slint `MainWindow` for UI rendering and event handling.
2025-12-09 20:06:13 +08:00
Kieran Kihn
095a34af1c chore: integrate Slint UI framework and update build configuration
- Added Slint as a required dependency in the CMake configuration.
- Integrated Slint sources into `uno-game-lib`.
- Modified Windows debug build to create a GUI executable.
2025-12-09 20:05:35 +08:00
Kieran Kihn
c6342469df test(game): remove player name from ClientGameState constructor in test
- Simplified `ClientGameState` initialization in `GameStateTest`.
2025-12-09 20:03:37 +08:00
Kieran Kihn
25a0a66c93 feat(client): introduce UnoClient with network and UI integration
- Added `UnoClient` class to handle network, UI, and player actions.
- Implemented methods for processing network and player events.
- Created entry point in `main.cpp` for client execution.
2025-12-09 20:03:21 +08:00
Kieran Kihn
5eee316acf feat(game): add player name management methods
- Added `setPlayerName` and `getPlayerName` to `ClientGameState`.
- Introduced `setName` method for `Player`.
- Updated constructors for `Player` and `ClientGameState` to support name management.
2025-12-09 19:43:51 +08:00
Kieran Kihn
3b31dd2dcc feat(game): add setClientGameStageConnected method to manage client state transitions 2025-12-09 19:43:41 +08:00
Kieran Kihn
41936b3525 test(network): expand NetworkClientTest with connection and send tests
- Added `onConnect` callback to test constructor.
- Introduced thread-based tests for connection and message sending.
2025-12-09 19:42:45 +08:00
Kieran Kihn
98a7ef7d41 feat(network): add async connect with onConnect callback
- Replaced synchronous `connect` with asynchronous connection logic.
- Introduced `onConnect` callback to handle connection success events.
- Ensured proper `io_context` work guard management.
2025-12-09 19:42:26 +08:00
Kieran Kihn
d5f996df6c 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.
2025-12-09 17:10:44 +08:00
Kieran Kihn
6ab5550fd3 fix(server): update playerId type in UnoServer lambda 2025-12-09 17:10:17 +08:00
Kieran Kihn
f968b4d3f2 test(network): add empty player list to InitGamePayload serialization tests
- Updated `InitGamePayload` to include an empty `players` array.
- Adjusted related serialization and deserialization test cases in `MessageSerializerTest`.
2025-12-07 19:33:43 +08:00
Kieran Kihn
9ae3b9cc89 test(game): simplify card play and player initialization in tests
- Updated `HandCard::play` usage to accept a dereferenced card.
- Replaced sequential `addPlayer` calls with `init` method in `GameStateTest`.
2025-12-07 19:33:29 +08:00
Kieran Kihn
d266f1c514 refactor(server): move addPlayer implementation to ServerGameState
- Relocated `addPlayer` method from template-based `GameState` to `ServerGameState`.
- Updated method signature and comments for better clarity.
2025-12-07 19:32:40 +08:00
Kieran Kihn
a1c46b8c9b refactor(server): enhance turn validation and game state handling
- Added `ServerGameStage` check in turn validation logic.
- Switched to `ClientPlayerState` in `handleStartGame` for player initialization.
- Integrated `endGame` in `handleEndGame` and removed redundant `reset` call.
2025-12-07 19:03:45 +08:00
Kieran Kihn
0802d989f8 refractor(game): enhance state management with clear and endGame methods
- Added `clear` methods to `PlayerState`, `ServerPlayerState`, and `HandCard`.
- Introduced `endGame` methods to `GameState`, `ClientGameState`, and `ServerGameState`.
- Improved `init` and `nextPlayer` logic in `ClientGameState`.
- Added `getClientGameStage` and `getServerGameStage` methods to retrieve game stages.
2025-12-07 19:03:13 +08:00
Kieran Kihn
ebb49a02ef refactor(network): replace PlayerPublicState with ClientPlayerState
- Updated `InitGamePayload` to use `ClientPlayerState` instead of `PlayerPublicState`.
- Adjusted serialization and deserialization methods in `MessageSerializer` accordingly.
2025-12-07 13:59:40 +08:00
Kieran Kihn
5196de460a refactor(game): simplify card play logic
- Replaced iterator-based `play` methods with a single card-based method.
- Streamlined logic in `ServerPlayerState`, `ClientGameState`, and `HandCard`.
2025-12-07 13:57:54 +08:00
Kieran Kihn
ea87fca1fd fix(network): ensure write continuation upon successful async_write
- Added a check in `Session::doWrite` to invoke subsequent writes when the message queue is not empty.
2025-12-04 17:17:32 +08:00
Kieran Kihn
8335769cc8 feat(network): enhance NetworkClient with run and stop methods
- Added `run` and `stop` methods to manage the IO context lifecycle.
- Updated `send` to post messages to the IO context.
2025-12-04 17:17:24 +08:00
Kieran Kihn
024f99fc01 feat(network): add PlayerPublicState to InitGamePayload
- Introduced `PlayerPublicState` structure to represent player state.
- Updated `InitGamePayload` to include `PlayerPublicState` for all players.
- Enhanced `MessageSerializer` to handle serialization and deserialization of `PlayerPublicState`.
2025-12-04 17:15:49 +08:00
Kieran Kihn
a136e309e6 chore: include Session.cpp in build configuration 2025-12-04 16:40:03 +08:00
Kieran Kihn
0e9f5bc924 test(network): simplify and consolidate NetworkClientTest
- Removed redundant tests and merged similar cases in `NetworkClientTest`.
- Updated `Connect` and `Send` tests to streamline functionality.
- Enhanced `MessageSerializerTest` to validate `playerId` in `InitGamePayload`.
2025-12-04 16:39:47 +08:00
Kieran Kihn
b22f88aa60 fix(server): include playerId in InitGamePayload initialization 2025-12-04 16:39:24 +08:00
Kieran Kihn
731ed5a890 feat(network): add playerId to InitGamePayload
- Updated `InitGamePayload` to include `playerId`.
- Modified `MessageSerializer` to handle serialization and deserialization of `playerId`.
- Added validation for `playerId` in INIT_GAME payload.
2025-12-04 16:21:11 +08:00
Kieran Kihn
1d2e77aca3 refactor(network): integrate NetworkClient with Session
- Moved `Session` implementation to `Session.cpp` and `Session.h`.
- Updated `Session` to use a `message` queue for sending data, improving handling of writes.
- Adjusted `NetworkClient` and `NetworkServer` to integrate with the new `Session` logic.
2025-12-04 14:42:22 +08:00
Kieran Kihn
7363556ad5 feat(game): add init method to ClientGameState
- Introduced `init` method to initialize `discardPile` in `ClientGameState`.
- Added `<ranges>` header to support future range-based operations.
2025-12-04 13:28:56 +08:00
Kieran Kihn
766e9f9a21 feat(server): add game reset and end game handling
- Introduced `reset` method in `ServerGameState` to allow game state reinitialization.
- Added `handleEndGame` in `UnoServer` to detect and process game conclusion.
2025-12-04 13:28:36 +08:00
Kieran Kihn
535e62c852 feat(server): add argument parsing for server port
- Integrated `argparse` to parse command-line arguments for setting the server port.
- Default port set to `10001`.
2025-12-04 10:22:37 +08:00
Kieran Kihn
5f3a4083fd chore: update CMake library visibility for dependencies
- Changed `uno-game-lib` dependencies to `PUBLIC` visibility for `ftxui` components, `nlohmann_json`, and `asio`.
- Modified `uno-game-test` to use `PRIVATE` visibility for `uno-game-lib`.
2025-12-02 12:31:01 +08:00
Kieran Kihn
0d5a187cba feat(server): implement Uno server functionality
- Added `UnoServer` class to handle player actions, game state, and networking.
- Supported message handling for joining, starting, drawing, and playing cards.
- Integrated `ServerGameState` with `NetworkServer` for multiplayer game logic.
- Created `main.cpp` to initialize and run the Uno server.
2025-12-02 12:28:59 +08:00
Kieran Kihn
4b498e3b4a test(network): update tests to reflect InitGamePayload changes
- Modified `MessageSerializerTest` to pass `handCard.getCards()` instead of `handCard` in `InitGamePayload` construction.
2025-12-02 12:28:12 +08:00
Kieran Kihn
271d89df0d refactor(network): change DrawCardPayload::drawCount to size_t 2025-12-02 12:17:28 +08:00
Kieran Kihn
016e87288d refactor(network): replace HandCard with std::multiset<Card> in InitGamePayload
- Updated `InitGamePayload` to use `std::multiset<Card>` for `handCard`.
- Removed `serializeHandCard` method and replaced its usage with `serializeCards`.
- Adjusted `deserializeHandCard` to return `std::multiset<Card>` and simplified insertion logic.
- Cleaned up unused declarations in `MessageSerializer`.
2025-12-02 12:06:21 +08:00
Kieran Kihn
8a00b66047 refactor(game): return drawn cards in updateStateByDraw
- Updated `updateStateByDraw` to return a `std::vector<Card>` instead of `void`.
- Adjusted `ServerGameState`, `GameState`, and `ClientGameState` implementations to reflect the change.
2025-12-02 12:06:06 +08:00
Kieran Kihn
e5304b8c6c refactor(game): simplify GameState construction and initialization
- Removed `GameStatus` dependency from `GameState` constructors.
- Adjusted `ClientGameState` and `ServerGameState` constructors accordingly.
- Simplified `ServerGameState::init()` to handle card initialization and player actions.
- Updated tests to reflect these changes.
2025-12-02 11:08:42 +08:00
Kieran Kihn
a650b61610 chore: split client and server executables
- Added `uno-client` and `uno-server` executables.
- Updated `CMakeLists.txt` to reflect new structure.
- Removed duplicate requirement for `ftxui`.
2025-12-01 23:34:22 +08:00
Kieran Kihn
e3821e9f6d chore: update .gitignore to exclude cmake-build-debug-with-coverage/ 2025-12-01 15:07:35 +08:00
Kieran Kihn
a8ed0f6397 chore: Removed /utf-8 option from ftxui compile options for Clang to improve compatibility. 2025-12-01 15:07:22 +08:00
Kieran Kihn
a10674fbd3 test(network): add unit tests for NetworkClient and NetworkServer
- Introduced comprehensive test cases for `NetworkClient` and `NetworkServer` functionality.
- Added tests for constructor, `connect`, `send`, `read`, and round-trip scenarios in `NetworkClientTest`.
- Added tests for player management, message sending, and concurrent access in `NetworkServerTest`.
- Updated `CMakeLists.txt` to include `NetworkClientTest` and `NetworkServerTest` in the build configuration.
2025-11-29 18:52:08 +08:00
Kieran Kihn
c2ccaaf17e fix(network): ensure disconnect before connect in NetworkClient
- Added `disconnect` method to gracefully close existing connections before establishing a new one.
- Updated `connect` to call `disconnect` to prevent resource conflicts.
2025-11-29 18:51:58 +08:00
Kieran Kihn
12d1d6c93f fix(network): call accept on NetworkServer initialization and after player addition
- Ensure `accept` is called during `NetworkServer` initialization and after successfully adding a player to handle new connections continuously.
2025-11-29 18:51:41 +08:00
Kieran Kihn
b6144d33e9 fix(network): reattempt read in NetworkServer after message handling
- Added a call to `read()` after successfully processing an incoming message in `NetworkServer`.
2025-11-29 18:51:30 +08:00