feat: add player to the room

This commit is contained in:
Jorens Shtekels 2024-03-12 21:51:05 +02:00
parent db4a4be369
commit 23345ba89f
3 changed files with 23 additions and 5 deletions

View File

@ -16,8 +16,6 @@ enum VALIDATION_STATUS {
};
void run() {
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
const Action kill = Action("kill", true);
const Action heal = Action("heal", true);
const Action vote = Action("vote", true);
@ -29,6 +27,8 @@ void run() {
std::vector<Event> relatedEvents({event2, event3});
Player player1 = Player("player1", role1, PlayerStatus::ALIVE);
Player player2 = Player("player2", role1, PlayerStatus::ALIVE);
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS, {player1, player2});
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED, {player1, player2});
int actionValidated = validateAction(&player1, &kill, &room1, &relatedEvents, &player2);
std::cout << actionValidated << std::endl;
}

View File

@ -35,10 +35,21 @@ Player::Player(std::string username, Role role, PlayerStatus playerStatus):
playerStatus(playerStatus) {
}
Room::Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status):
Room::Room(
uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status, std::vector<Player> players):
id(id),
title(title),
status(status) {
status(status),
players(players) {
this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt);
}
Room::Room(uint32_t id,
std::string title,
uint32_t utcTimestampCreatedAt,
RoomStatus status,
std::initializer_list<Player> players):
Room(id, title, utcTimestampCreatedAt, status, std::vector<Player>(players)) {
this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt);
}

View File

@ -65,8 +65,15 @@ struct Room {
std::string title;
std::tm *utcTimestampCreatedAt;
RoomStatus status;
std::vector<Player> players;
Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status);
Room(
uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status, std::vector<Player> players);
Room(uint32_t id,
std::string title,
uint32_t utcTimestampCreatedAt,
RoomStatus status,
std::initializer_list<Player> players);
};
struct Event {