This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.py
executable file
·79 lines (64 loc) · 2.21 KB
/
webapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import pprint
import os
import cPickle as pickle
from flask import Flask
from flask import request
from flask import session
from flask import redirect
from flask import url_for
from flask import abort
from flask import render_template
from flask import flash
from utok import textDisplay
from utok import game
from utok import play_cli
import models
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'development key'
@app.route('/')
def frontpage():
gameEntries = models.get_gameEntries()
players = models.get_players()
return render_template('frontpage.html', gameEntries=gameEntries, players=players)
@app.route('/games/')
def allgames():
gameEntries = models.get_gameEntries()
return render_template('allgames.html', gameEntries=gameEntries)
@app.route('/player/<player>/games/')
def player_games(player):
gameEntries = models.get_gameEntries(player=player)
return render_template('playergames.html', gameEntries=gameEntries, player=player)
@app.route('/game/<int:game_id>/text', methods=['GET', 'POST'])
def display_game_text(game_id):
"""View and play a risk game in text mode"""
gameEntry = models.GameEntry(game_id)
g = gameEntry.game
if request.method == 'POST':
cmd = request.form['cmd']
g = play_cli.run_command_on_game(g, cmd)
models.GameEntry(game_id).update_game(g)
else:
cmd = None
d = textDisplay.Display(g)
s = d.get()
return render_template('textgame.html', gameEntry=gameEntry, game=g, command=cmd, gamestring=s)
@app.route('/game/<int:game_id>/cmd/<path:command>')
def input_command(game_id, command):
words = command.split('/')
gameEntry = models.GameEntry(game_id)
g = gameEntry.game
g = play_cli.run_command_on_game(g, ' '.join(words))
gameEntry.update_game(g)
d = textDisplay.Display(g)
s = d.get()
return render_template('textgame.html', gameEntry=gameEntry, game=g, command=' '.join(words), gamestring=s)
@app.route('/game/graphics/<int:game_id>/')
def display_game_graphics(game_id):
pass
if __name__ == '__main__':
import populate_db
populate_db.populate()
port = int(os.environ.get("PORT", 5000))
app.run('0.0.0.0', port=port)