Created backend
parent
9766116a99
commit
fdbd4d2f09
|
@ -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/<id:int>/")
|
||||
def show(id):
|
||||
return template(TEMPLATE, game=games[id], valid=True)
|
||||
|
||||
@post("/game/<id:int>/")
|
||||
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)
|
||||
|
Loading…
Reference in New Issue