init commit

This commit is contained in:
Dane Johnson 2023-01-31 16:29:40 -06:00
parent 9c11d244c9
commit a8578c02f1
6 changed files with 76 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
env/
*.pyc

3
pyproject.toml Normal file
View File

@ -0,0 +1,3 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

11
requirements.txt Normal file
View File

@ -0,0 +1,11 @@
bidict==0.22.1
click==8.1.3
colorama==0.4.6
Flask==2.2.2
Flask-SocketIO==5.3.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
python-engineio==4.3.4
python-socketio==5.7.2
Werkzeug==2.2.2

41
src/__init__.py Normal file
View File

@ -0,0 +1,41 @@
from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit, join_room, rooms
from src.code import make_code
from src.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
src/code.py Normal file
View File

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

13
src/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