Skip to content

Commit 8c8cbc1

Browse files
committed
Added documentation for client and common classes
1 parent 4dec958 commit 8c8cbc1

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

client_src/game_protocol_client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const uint8_t GameProtocolClient::receive_enemy_event() {
7070
const std::string GameProtocolClient::get_enemy_event_message(
7171
const uint8_t& enemy_event_code, const std::string& ENEMY_DIED_EVENT_MESSAGE,
7272
const std::string& ENEMY_REVIVED_EVENT_MESSAGE) const {
73+
7374
if (enemy_event_code == this->game_commands.get_enemy_died_code()) {
7475
return ENEMY_DIED_EVENT_MESSAGE;
7576

client_src/game_protocol_client.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ class GameProtocolClient {
2020
bool is_skt_closed;
2121
GameCommands game_commands;
2222

23-
/*
24-
* Receives all the information from the server to build a valid GameMessage
25-
*/
26-
const GameMessage receive_message_from_server(const std::string& ENEMY_DIED_EVENT_MESSAGE,
27-
const std::string& ENEMY_REVIVED_EVENT_MESSAGE);
28-
29-
3023
/*
3124
* Receives from the server code that represents the start of a broadcast message
3225
*/
@@ -47,10 +40,19 @@ class GameProtocolClient {
4740
*/
4841
const uint8_t receive_enemy_event();
4942

43+
/*
44+
* Translates the command codes into a string message with the function arguments
45+
*/
5046
const std::string get_enemy_event_message(const uint8_t& enemy_event_code,
5147
const std::string& ENEMY_DIED_EVENT_MESSAGE,
5248
const std::string& ENEMY_REVIVED_EVENT_MESSAGE) const;
5349

50+
/*
51+
* Receives all the information from the server to build a valid GameMessage
52+
*/
53+
const GameMessage receive_message_from_server(const std::string& ENEMY_DIED_EVENT_MESSAGE,
54+
const std::string& ENEMY_REVIVED_EVENT_MESSAGE);
55+
5456
public:
5557
/*
5658
* GameProtocolClient handles the way the client should interact with the server, in terms of
@@ -73,6 +75,9 @@ class GameProtocolClient {
7375
GameProtocolClient(GameProtocolClient&&) = default;
7476
GameProtocolClient& operator=(GameProtocolClient&&) = default;
7577

78+
/*
79+
* Sends an attack message to the server
80+
*/
7681
void send_attack();
7782

7883

client_src/jazz_jackrabbit_2_game_client.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class JazzJackrabbit2GameClient {
1414
const std::vector<std::string> available_user_options;
1515

1616
/*
17-
* Compares two options in equal conditions (both are sanitized with
18-
* JazzJackrabbit2GameClient::sanitize_string) and returns true if they are equal
17+
* Compares two options in equal conditions and returns true if they are equal
1918
*/
2019
const bool are_options_equal(const std::string& option1, const std::string& option2) const;
2120

@@ -36,25 +35,16 @@ class JazzJackrabbit2GameClient {
3635
void vectorize_user_input(const std::string& user_input,
3736
std::vector<std::string>& user_input_vectorized);
3837

39-
/*
40-
* Calls the appropiate method depending on the desired action
41-
*/
42-
void execute_command(const std::vector<std::string>& user_input_vectorized);
4338

4439
/*
45-
* Returns an uppercase copy of the string
46-
*/
47-
const std::string string_to_uppercase(const std::string& string) const;
48-
49-
/*
50-
* Returns the result of JazzJackrabbit2GameClient::string_to_uppercase
40+
* Uses the client_protocol to send an attack to the server
5141
*/
52-
const std::string sanitize_string(const std::string& string) const;
42+
void execute_attack(const std::vector<std::string>& user_input_vectorized);
5343

5444
/*
55-
* Uses the client_protocol to send an attack to the server
45+
* Prints to std::out the message read from the server
5646
*/
57-
void execute_attack(const std::vector<std::string>& user_input_vectorized);
47+
void print_messages_from_server(const std::vector<GameMessage>& messages) const;
5848

5949
/*
6050
* Uses the client_protocol to block the I/O until read all the messages expressed
@@ -63,9 +53,9 @@ class JazzJackrabbit2GameClient {
6353
void execute_read_from_server(const std::vector<std::string>& user_input_vectorized);
6454

6555
/*
66-
* Prints to std::out the message read from the server
56+
* Calls the appropiate method depending on the desired action
6757
*/
68-
void print_messages_from_server(const std::vector<GameMessage>& messages) const;
58+
void execute_command(const std::vector<std::string>& user_input_vectorized);
6959

7060
public:
7161
/*

common_src/game_commands.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ const uint8_t GameCommands::get_enemy_revived_code() const {
3535

3636

3737
const std::string GameCommands::get_key_from_code(const uint8_t& cmd_code) const {
38-
// A lambda expression detects if this is the correct command by code
39-
// It will be evaluated in each iteration of the search loop
4038
auto lambda_is_searched_cmd = [&cmd_code](const auto& command) {
4139
return command.second == cmd_code;
4240
};
43-
// Iterate through the map until it founds the matching command
41+
4442
auto found_command = std::find_if(this->game_commands_map.begin(),
4543
this->game_commands_map.end(), lambda_is_searched_cmd);
4644

server_src/game_server_engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void GameServerEngine::broadcast_revived_enemies_if_any(const uint16_t& revived_
138138
}
139139
}
140140

141+
141142
void GameServerEngine::run() {
142143
while (!this->should_server_shutdown()) {
143144
std::string next_cmd;

0 commit comments

Comments
 (0)