mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
feat: target player bool for action
Added validation logic that checks for target player if needed.
This commit is contained in:
parent
ee12e48a86
commit
9a7bc42db6
12
src/lib.cpp
12
src/lib.cpp
@ -16,9 +16,11 @@ enum VALIDATION_STATUS {
|
|||||||
void run() {
|
void run() {
|
||||||
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
|
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
|
||||||
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
|
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
|
||||||
Role role1({Action::KILL, Action::HEAL});
|
const Action kill = Action("kill", true);
|
||||||
std::vector<Action> actions = {Action::HEAL};
|
const Action heal = Action("heal", true);
|
||||||
Role role2(actions);
|
const Action vote = Action("vote", true);
|
||||||
|
Role role1({vote, kill, heal});
|
||||||
|
Role role2({heal});
|
||||||
}
|
}
|
||||||
|
|
||||||
int validateAction(
|
int validateAction(
|
||||||
@ -26,7 +28,9 @@ int validateAction(
|
|||||||
if (!actor) {
|
if (!actor) {
|
||||||
return NO_PLAYER;
|
return NO_PLAYER;
|
||||||
}
|
}
|
||||||
// TODO: Check if action has a target
|
if (action->hasTarget && !target) {
|
||||||
|
return NO_PLAYER;
|
||||||
|
}
|
||||||
if (room->status != RoomStatus::IN_PROGRESS) {
|
if (room->status != RoomStatus::IN_PROGRESS) {
|
||||||
return ROOM_NOT_IN_PROGRESS;
|
return ROOM_NOT_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,11 @@ int add(int a, int b) {
|
|||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Action::Action(std::string name, bool hasTarget) {
|
||||||
|
this->name = name;
|
||||||
|
this->hasTarget = hasTarget;
|
||||||
|
}
|
||||||
|
|
||||||
Role::Role(std::initializer_list<Action> actions) {
|
Role::Role(std::initializer_list<Action> actions) {
|
||||||
for (auto &a : actions) {
|
for (auto &a : actions) {
|
||||||
this->actions.push_back(a);
|
this->actions.push_back(a);
|
||||||
|
|||||||
@ -18,14 +18,6 @@ enum EventType {
|
|||||||
PLAYER_STATE_CHANGE,
|
PLAYER_STATE_CHANGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Action {
|
|
||||||
KILL,
|
|
||||||
VOTE,
|
|
||||||
INVESTIGATE,
|
|
||||||
HEAL,
|
|
||||||
PROTECT,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum RoomStatus {
|
enum RoomStatus {
|
||||||
AWAITING_START,
|
AWAITING_START,
|
||||||
IN_PROGRESS,
|
IN_PROGRESS,
|
||||||
@ -45,6 +37,13 @@ struct Player;
|
|||||||
struct Room;
|
struct Room;
|
||||||
struct Event;
|
struct Event;
|
||||||
|
|
||||||
|
struct Action {
|
||||||
|
std::string name;
|
||||||
|
bool hasTarget;
|
||||||
|
|
||||||
|
Action(std::string name, bool hasTarget);
|
||||||
|
};
|
||||||
|
|
||||||
struct Role {
|
struct Role {
|
||||||
std::vector<Action> actions;
|
std::vector<Action> actions;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user