refactor(player): move player to separate file

This commit is contained in:
Kristofers Solo 2024-03-14 00:48:16 +02:00
parent 9a4b8831ee
commit b4b01c4a11
7 changed files with 45 additions and 31 deletions

View File

@ -10,4 +10,4 @@ struct Action {
bool operator==(const Action &other) const;
};
#endif // ACTION_HH
#endif // !ACTION_HH

View File

@ -1,4 +1,5 @@
#include "action.hh"
#include "player.hh"
#include "prep/prep.hh"
#include "role.hh"

16
src/player.cc Normal file
View File

@ -0,0 +1,16 @@
#include "player.hh"
#include "role.hh"
#include <string>
Player::Player(uint32_t id, std::string username, Role role, PlayerStatus status):
id(id),
username(username),
role(role),
status(status) {
}
bool Player::operator==(const Player &other) const {
return this->id == other.id;
}

26
src/player.hh Normal file
View File

@ -0,0 +1,26 @@
#ifndef PLAYER_HH
#define PLAYER_HH
#include "role.hh"
#include <cstdint>
#include <string>
enum PlayerStatus {
Kicked,
Alive,
Dead,
VotedOut,
};
struct Player {
uint32_t id;
std::string username;
Role role;
PlayerStatus status;
Player(uint32_t id, std::string username, Role role, PlayerStatus status);
bool operator==(const Player &other) const;
};
#endif // !PLAYER_HH

View File

@ -5,17 +5,6 @@
#include <cstdint>
#include <initializer_list>
Player::Player(uint32_t id, std::string username, Role role, PlayerStatus playerStatus):
id(id),
username(username),
role(role),
playerStatus(playerStatus) {
}
bool Player::operator==(const Player &other) const {
return this->id == other.id;
}
Room::Room(
uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status, std::vector<Player> players):
id(id),

View File

@ -21,27 +21,9 @@ enum RoomStatus {
ENDED,
};
enum PlayerStatus {
KICKED,
ALIVE,
DEAD,
VOTED_OUT,
};
struct Player;
struct Room;
struct Event;
struct Player {
uint32_t id;
std::string username;
Role role;
PlayerStatus playerStatus;
Player(uint32_t id, std::string username, Role role, PlayerStatus playerStatus);
bool operator==(const Player &other) const;
};
struct Room {
uint32_t id;
std::string title;

View File

@ -12,4 +12,4 @@ struct Role {
Role(std::vector<Action> actions);
};
#endif // ROLE_HH
#endif // !ROLE_HH