init
This commit is contained in:
9
templates/main.html
Normal file
9
templates/main.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{% block title %}Wer bin ich{% endblock %}</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
19
templates/name_edit.html
Normal file
19
templates/name_edit.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Choose name{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Choose a name</h1>
|
||||||
|
<h2>You are: {{ current_player }}</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Please name your player:
|
||||||
|
<br/>
|
||||||
|
<form method=post>
|
||||||
|
{% for player in other_players %}
|
||||||
|
{{ player }}: <input type=text name={{ player }} /><br/>
|
||||||
|
{% endfor %}
|
||||||
|
<input type=submit />
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
16
templates/name_show.html
Normal file
16
templates/name_show.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Play!{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Play!</h1>
|
||||||
|
<h2>You are: {{ current_player }}</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<table>
|
||||||
|
{% for player,name in other_players.items() %}
|
||||||
|
<tr><td>{{ player }}</td><td>{{ name }}</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
15
templates/new_game.html
Normal file
15
templates/new_game.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}New Game{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>New Game</h1>
|
||||||
|
|
||||||
|
Please enter player names:
|
||||||
|
<br/>
|
||||||
|
<form method=post>
|
||||||
|
{% for _ in range(10) %}
|
||||||
|
<input type=text name=pname /><br/>
|
||||||
|
{% endfor %}
|
||||||
|
<input type=submit />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
19
templates/player_select.html
Normal file
19
templates/player_select.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Player select{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Player select</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Please select your player:
|
||||||
|
<br/>
|
||||||
|
{% for player in players %}
|
||||||
|
<a href=./edit/{{ player }}>{{ player }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
You can share <a href={{ gameurl }}>this</a> link
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
50
werbinich.py
Normal file
50
werbinich.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
from flask import Flask,render_template,request,url_for,redirect
|
||||||
|
from pprint import pprint
|
||||||
|
from uuid import uuid4
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
games = {}
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def new_game():
|
||||||
|
return render_template("new_game.html")
|
||||||
|
|
||||||
|
@app.route("/", methods=["post"])
|
||||||
|
def create_game():
|
||||||
|
global games
|
||||||
|
pnames = [ x for x in request.form.getlist("pname") if x != "" ]
|
||||||
|
gameid = str(uuid4())
|
||||||
|
mapping = {}
|
||||||
|
for player in pnames:
|
||||||
|
mapping[player] = None
|
||||||
|
games[gameid] = mapping
|
||||||
|
|
||||||
|
return redirect(url_for("player_select", gameid=gameid),303)
|
||||||
|
|
||||||
|
@app.route("/game/<uuid:gameid>/")
|
||||||
|
def player_select(gameid):
|
||||||
|
return render_template("player_select.html", players=games[str(gameid)].keys(), gameurl=url_for("player_select", gameid=gameid))
|
||||||
|
|
||||||
|
@app.route("/game/<uuid:gameid>/edit/<player>")
|
||||||
|
def name_edit(gameid, player):
|
||||||
|
all_players = games[str(gameid)].keys()
|
||||||
|
other_players = [ x for x in all_players if x != player ]
|
||||||
|
return render_template("name_edit.html", current_player=player, other_players=other_players)
|
||||||
|
|
||||||
|
@app.route("/game/<uuid:gameid>/edit/<player>", methods=["post"])
|
||||||
|
def store_name(gameid, player):
|
||||||
|
all_players = games[str(gameid)].keys()
|
||||||
|
for p in all_players:
|
||||||
|
if p not in request.form:
|
||||||
|
continue
|
||||||
|
if request.form[p]:
|
||||||
|
games[str(gameid)][p] = request.form[p]
|
||||||
|
return redirect(url_for("name_show", gameid=gameid, player=player), 303)
|
||||||
|
|
||||||
|
@app.route("/game/<uuid:gameid>/show/<player>")
|
||||||
|
def name_show(gameid, player):
|
||||||
|
other_players = dict(games[str(gameid)])
|
||||||
|
other_players.pop(player,None)
|
||||||
|
pprint(other_players)
|
||||||
|
return render_template("name_show.html", current_player=player, other_players=other_players)
|
||||||
Reference in New Issue
Block a user