-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathviews.py
More file actions
56 lines (42 loc) · 1.59 KB
/
views.py
File metadata and controls
56 lines (42 loc) · 1.59 KB
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
from flask import render_template, session, request
from route_helper import simple_route
@simple_route('/')
def hello(world: dict) -> str:
"""
The welcome screen for the game.
:param world: The current world
:return: The HTML to show the player
"""
return render_template('index.html', world=world)
@simple_route('/goto/<where>/')
def move_to_place(world: dict, where: str) -> str:
"""
Update the player location and encounter a monster, prompting the player
to give them a name.
:param world: The current world
:param where: The new location to move to
:return: The HTML to show the player
"""
world['location'] = where
# Add a new, unknown corgi if we have no unknown corgis
corgi_names = [corgi['Name'] for corgi in world['corgis']]
if '???' not in corgi_names:
world['corgis'].append({"Name": "???", "Mood": "Unknown"})
return render_template('encounter_monster.html', world=world)
@simple_route("/save/")
def save_name(world: dict, *args) -> str:
"""
Update the name of the monster.
:param world: The current world
:param monsters_name:
:return:
"""
# Rename the latest corgi
world['corgis'][-1]['Name'] = request.values.get('monster_name')
world['corgis'][-1]['Mood'] = request.values.get('monster_mood')
try:
world['corgis'][0]['Age'] = int(request.values.get('age'))
except ValueError:
world['corgis'][0]['Age'] = None
world['corgis'][0]['Fluffy'] = 'true' == request.values.get('is_fluffy', False)
return render_template('name_monster.html', world=world)