Some project cleanup

This commit is contained in:
2023-02-01 22:07:20 -06:00
parent a8578c02f1
commit 2be456964a
4 changed files with 3 additions and 6 deletions

41
venture/__init__.py Normal file
View File

@@ -0,0 +1,41 @@
from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room, rooms
from venture.code import make_code
from venture.game import Game
games = {}
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, cors_allowed_origins="*")
if __name__ == '__main__':
socketio.run(app)
def with_game(listener):
global games
room = rooms()[1]
game = games[room]
def inner(event, data={}):
data['game'] = game
listener(game, data)
return inner
@socketio.on('new-game')
def on_newgame():
data = {}
code = make_code()
games[code] = Game(code)
join_room(code)
emit('set-code', {'code': code})
@socketio.on('contestant-join')
def on_join_contestant(data):
sid = request.sid
signature = data['signature']
room = data['room']
join_room(room)
games[room].add_contestant(sid, signature)
emit('contestant-joined', {'sid': sid, 'signature': signature }, to=room)

6
venture/code.py Normal file
View File

@@ -0,0 +1,6 @@
import uuid
def make_code():
code = uuid.uuid1().hex[:6]
return code

13
venture/game.py Normal file
View File

@@ -0,0 +1,13 @@
class Game:
def __init__(self, code):
self.code = code
self.locked = True
self.players = {}
def add_contestant(self, sid, signature):
self.players[sid] = Contestant(signature)
class Contestant:
def __init__(self, signature):
self.signature = signature
self.points = 0