diff --git a/main.py b/main.py new file mode 100644 index 0000000..02f38ce --- /dev/null +++ b/main.py @@ -0,0 +1,42 @@ +from bottle import template, get, run, post, request, redirect +from chess import Game + + +TEMPLATE = "template.html" +games = dict() + +def is_submitted(name): + return request.forms.get(name) != None + +@get("/") +def index(): + game = Game() + id = max(list(games.keys())+[0]) + 1 + games[id] = game + redirect("/game/{}/".format(id)) + +@get("/game//") +def show(id): + return template(TEMPLATE, game=games[id], valid=True) + +@post("/game//") +def move(id): + valid = True + if is_submitted("newgame"): + redirect("/") + if is_submitted("prev"): + games[id].prev() + elif is_submitted("first"): + games[id].first() + elif is_submitted("next"): + games[id].next() + elif is_submitted("last"): + games[id].last() + else: + AN = request.forms.get("move") + valid = games[id].AN_move(AN) + return template(TEMPLATE, game=games[id], valid=valid) + + +run(host="localhost", port=8080) +