Created
October 6, 2011 17:13
-
-
Save adaptives/1267987 to your computer and use it in GitHub Desktop.
LPTHW Exercise 52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
from gothonweb import map | |
urls = ( | |
'/game', 'GameEngine', | |
'/', 'Index', | |
) | |
app = web.application(urls, globals()) | |
# little hack so that debug mode works with sessions | |
if web.config.get('_session') is None: | |
store = web.session.DiskStore('sessions') | |
session = web.session.Session(app, store, initializer={'room': None}) | |
web.config._session = session | |
else: | |
session = web.config._session | |
render = web.template.render('templates/', base="layout") | |
class Index(object): | |
def GET(self): | |
# setup the session with starting values | |
session.room = map.START | |
web.seeother("/game") | |
class GameEngine(object): | |
def GET(self): | |
if session.room: | |
return render.show_room(room=session.room) | |
else: | |
return render.game_lost() | |
def POST(self): | |
form = web.input(action=None) | |
if session.room and form.action: | |
transition = session.room.go(form.action) | |
if transition == None: | |
transition = session.room.go('*') | |
if transition != None: | |
session.room = transition.room | |
else: | |
session.room = None | |
web.seeother("/game") | |
if __name__ == "__main__": | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$def with (room) | |
<h1> $room.name </h1> | |
<pre> | |
$room.description | |
</pre> | |
$if room.name == "death": | |
<p><a href="/">Play Again?</a></p> | |
$else: | |
<p> | |
<form action="/game" method="POST"> | |
- <input type="text" name="action"> <input type="SUBMIT"> | |
</form> | |
</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment