Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/game_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
START_GAME_RESPONSE = "StartGameInfo" # Backend -> Frontend; username->userid mapping

NEW_PRESIDENT = "President" # Backend -> Frontend; userid of the president, govtFailCount
REQUEST_NOMINATE_CHANCELLOR = "RequestNominateChancellor" # Backend -> Frontend; userids that can be nominated
NOMINATED_CHANCELLOR = "NominatedChancellor" # Frontend -> Backend; userid of the chancellor
VOTE_CHANCELLOR = "VoteChancellor" # Backend -> Frontend; userid of the chancellor in case voting is required.
VOTE_FOR_CHANCELLOR = "VoteForChancellor" # Frontend -> Backend; yes/no on chancelor election
ELECTED_CHANCELLOR = "ElectedChancellor" # Backend -> Frontend; userid of the chancellor

PRESIDENT_POLICIES_OPTIONS = "PresidentPolicyOptions" # Backend -> Frontend; good/bad policy count
Expand Down
30 changes: 29 additions & 1 deletion backend/game_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid
import json
import GameState
import game_events

NEW_USER_JOINED_ROOM = "NewUserJoinedRoom"

Expand Down Expand Up @@ -75,7 +76,34 @@ def emit_to_users(self, user_ids, event, data):


def handle_event(self, sid, event, data):
pass
origin_user = None

for key, val in self._users.items():
if val == sid:
origin_user = key
if origin_user == None :
raise RuntimeError(f"No user with sid {sid} exists in room {self._room_id}")

if event == game_events.START_GAME :
self._state.start_game()
elif event == game_events.NOMINATED_CHANCELLOR :
nomination = data["user_id"]
self._state.nominate(origin_user, nomination)
elif event == game_events.VOTE_FOR_CHANCELLOR :
vote = data["vote"]
self._state.vote(origin_user, vote)
elif event == game_events.PRESIDENT_POLICIES :
discard_index = data["card"]
self._state.president_discard(discard_index)
elif event == game_events.CHANCELLOR_POLICY :
play_index = data["card"]
self._state.chancellor_play(play_index)
elif event == game_events.RESPONSE_KILL :
victim = data["user_id"]
self._state.kill(victim)
else:
raise RuntimeError(f"invalid event {event}")


@property
def users(self):
Expand Down