ConnectX 3.0
ConnectX Game Suite
Loading...
Searching...
No Matches
interface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <atomic>
5#include <thread>
6
7#include "client/client.hpp"
8
9enum class JoinMode
10{
11 AUTO, // Join first available game
12 BY_ID, // Join specific game by ID
13 BY_NAME, // Join game by name
14 CREATE_CUSTOM, // Create custom game
15};
16
18{
19 std::string name;
20 uint8_t rows;
21 uint8_t cols;
22 uint8_t num_players;
24};
25
31{
32public:
35
40 int run(int argc, char *argv[]);
41
42private:
43 Client client_;
44 std::atomic<bool> waiting_for_input_;
45 std::thread event_thread_;
46
47 // Configuration
48 std::string server_host_;
49 uint16_t server_port_;
50 std::string player_name_;
51 JoinMode join_mode_;
52 std::optional<uint32_t> target_game_id_;
53 std::optional<std::string> target_game_name_;
54 std::optional<GameSpec> custom_game_spec_;
55 bool request_game_list_;
56 bool with_ai_;
57 bool first_update = true;
58
59 // Setup and initialization
60 void parseArguments(int argc, char *argv[]);
61 bool parseGameSpec(const std::string &spec);
62 void setupCallbacks();
63 void handleJoinMode();
64 void joinGame();
65 void joinGame(uint32_t game_id);
66 void joinGame(const std::string &name);
67 void createCustomGame();
68
69 // Display functions
70 void printBanner();
71 void printLobby(const GameStateUpdate &state);
72 void printBoard(const GameStateUpdate &state);
73 void printHelp();
74 void printGameList(const std::vector<GameInfo> &games);
75 std::string printPlayer(uint8_t player_id, const std::string &player_name, bool highlight = false);
76
77 // Input handling
78 void handleUserInput();
79
80 // Utility
81 std::string colorize(const std::string &text, int color_code);
82};
Definition interface.hpp:31
~CLIInterface()
Definition interface.cpp:56
int run(int argc, char *argv[])
Definition interface.cpp:64
CLIInterface()
Definition interface.cpp:46
Definition client.hpp:19
JoinMode
Definition interface.hpp:10
Definition interface.hpp:18
std::string name
Definition interface.hpp:19
uint8_t connect_length
Definition interface.hpp:23
uint8_t num_players
Definition interface.hpp:22
uint8_t rows
Definition interface.hpp:20
uint8_t cols
Definition interface.hpp:21
Definition messages.hpp:83