From 0007f25cf6c21cf48679392e961413774c552b96 Mon Sep 17 00:00:00 2001 From: Yannik Enss Date: Wed, 2 Jan 2019 04:30:59 +0100 Subject: [PATCH] init --- templates/main.html | 9 +++++++ templates/name_edit.html | 19 ++++++++++++++ templates/name_show.html | 16 ++++++++++++ templates/new_game.html | 15 +++++++++++ templates/player_select.html | 19 ++++++++++++++ werbinich.py | 50 ++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 templates/main.html create mode 100644 templates/name_edit.html create mode 100644 templates/name_show.html create mode 100644 templates/new_game.html create mode 100644 templates/player_select.html create mode 100644 werbinich.py diff --git a/templates/main.html b/templates/main.html new file mode 100644 index 0000000..a365ddb --- /dev/null +++ b/templates/main.html @@ -0,0 +1,9 @@ + + + {% block title %}Wer bin ich{% endblock %} + + + + {% block content %}{% endblock %} + + diff --git a/templates/name_edit.html b/templates/name_edit.html new file mode 100644 index 0000000..8621f4b --- /dev/null +++ b/templates/name_edit.html @@ -0,0 +1,19 @@ +{% extends "main.html" %} +{% block title %}Choose name{% endblock %} +{% block content %} + +

Choose a name

+

You are: {{ current_player }}

+ +

+Please name your player: +
+

+{% for player in other_players %} +{{ player }}:
+{% endfor %} + +
+

+ +{% endblock %} diff --git a/templates/name_show.html b/templates/name_show.html new file mode 100644 index 0000000..2ed4725 --- /dev/null +++ b/templates/name_show.html @@ -0,0 +1,16 @@ +{% extends "main.html" %} +{% block title %}Play!{% endblock %} +{% block content %} + +

Play!

+

You are: {{ current_player }}

+ +

+ +{% for player,name in other_players.items() %} + +{% endfor %} +
{{ player }}{{ name }}
+

+ +{% endblock %} diff --git a/templates/new_game.html b/templates/new_game.html new file mode 100644 index 0000000..89ae1ca --- /dev/null +++ b/templates/new_game.html @@ -0,0 +1,15 @@ +{% extends "main.html" %} +{% block title %}New Game{% endblock %} +{% block content %} + +

New Game

+ +Please enter player names: +
+
+{% for _ in range(10) %} +
+{% endfor %} + +
+{% endblock %} diff --git a/templates/player_select.html b/templates/player_select.html new file mode 100644 index 0000000..79fd64d --- /dev/null +++ b/templates/player_select.html @@ -0,0 +1,19 @@ +{% extends "main.html" %} +{% block title %}Player select{% endblock %} +{% block content %} + +

Player select

+ +

+Please select your player: +
+{% for player in players %} +{{ player }} +{% endfor %} +

+ +

+You can share this link +

+ +{% endblock %} diff --git a/werbinich.py b/werbinich.py new file mode 100644 index 0000000..9caa788 --- /dev/null +++ b/werbinich.py @@ -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//") +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//edit/") +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//edit/", 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//show/") +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)