Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34fdab8

Browse files
committed
ex52 创建Web游戏
1 parent 8a6e14e commit 34fdab8

20 files changed

+384
-0
lines changed

ex52/gothonweb/ReadMe.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
运行指令如下:
2+
1.测试:nosetests
3+
2.运行:python bin/app.py
4+
3.注意如果导入包错误,请输入如下指令:
5+
"export PYTHONPATH=$PYTHONPATH:."(引号中的全部)
6+
4.运行前把seesion文件夹中的文件全部删除,以确保是从新开始!
7+
8+
5.ctrl+c是终止
9+
10+

ex52/gothonweb/bin/__init__.py

Whitespace-only changes.

ex52/gothonweb/bin/__init__.pyc

126 Bytes
Binary file not shown.

ex52/gothonweb/bin/app.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#coding:utf-8
2+
import web
3+
from gothonweb import map
4+
5+
urls = (
6+
'/game', 'GameEngine',
7+
'/', 'Index'
8+
)
9+
10+
app = web.application(urls, globals())
11+
12+
if web.config.get('_session') is None:
13+
store = web.session.DiskStore('sessions')
14+
session = web.session.Session(app, store, initializer={'room': None})
15+
web.config._session = session
16+
else:
17+
session = web.config._session
18+
19+
render = web.template.render('templates/', base="layout") # 渲染templates/文件夹下的index
20+
21+
class Index(object):
22+
def GET(self):
23+
session.room = map.START
24+
web.seeother("/game")
25+
26+
27+
class GameEngine(object):
28+
29+
def GET(self):
30+
if session.room:
31+
return render.show_room(room=session.room)
32+
else:
33+
return render.you_died()
34+
35+
def POST(self):
36+
form = web.input(action=None)
37+
# 据说这里有个bug 我没发现
38+
if session.room and form.action:
39+
session.room = session.room.go(form.action)
40+
web.seeother("/game")
41+
if __name__ == "__main__":
42+
app.run()

ex52/gothonweb/bin/app.pyc

1.75 KB
Binary file not shown.

ex52/gothonweb/gothonweb/__init__.py

Whitespace-only changes.
132 Bytes
Binary file not shown.

ex52/gothonweb/gothonweb/map.py

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#coding:utf-8
2+
class Room(object):
3+
4+
def __init__(self, name, description):
5+
self.name = name
6+
self.description = description
7+
self.paths = {}
8+
9+
# 返回依据direction在paths中的到的值
10+
def go(self, direction):
11+
return self.paths.get(direction, None)
12+
13+
# 给paths赋值
14+
def add_paths(self, paths):
15+
self.paths.update(paths)
16+
17+
18+
central_corridor = Room("Central Corridor",
19+
"""
20+
行星Percal#25 Gothons已经侵入你的飞船,销毁
21+
了你的所有船员。你是最后生存者,你的最后
22+
任务是从武器军械库获得中子毁灭炸弹,
23+
把它放在桥梁,引爆它并成功进入
24+
逃生舱逃生。
25+
26+
当你通过中央走廊向武器仓库跑去的时候,
27+
一个Gothon跳出,鳞状皮肤红,黑肮脏的牙齿,和邪恶的小丑服装
28+
流动围绕着他充满仇恨的身体。他堵大门
29+
(The Gothons of Planet Percal #25 have invaded your ship and destroyed
30+
your entire crew. You are the last surviving member and your last
31+
mission is to get the neutron destruct bomb from the Weapons Armory,
32+
put it in the bridge,and blow the ship up after getting into an
33+
escape pod.
34+
35+
You're running down the central corridor to the Weapons Armory when
36+
a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
37+
flowing around his hate filled body. He's blocking the door to the)
38+
""")
39+
40+
laser_weapon_armory = Room("Laser Weapon Armory",
41+
"""
42+
你是幸运的,他们让你学会Gothon侮辱的学院。
43+
你讲一个你知道的笑话给Gothon:
44+
Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhag gur ubhfr。
45+
Gothon停止,尽量不笑,然后爆发出大笑,无法动弹。
46+
在他的笑的时候你跑起来拍他的头部
47+
把他打倒,然后跳进武器军械库的门。
48+
49+
你你翻身滚进武器兵工厂,蹲下以及扫描这个房间
50+
寻找可能隐藏着的Gothons。这里死一般的安静,太安静了。
51+
你站起来,跑到房间的另一边,并找到
52+
获得炸弹需要的代码。如果你得到的代码
53+
错10次那么锁将永远关闭,你就不能
54+
拿到炸弹。代码是3位数的。
55+
(Lucky for you they made you learn Gothon insults in the academy.
56+
You tell the one Gothon joke you know:
57+
Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhag gur ubhfr.
58+
The Gothon stops, tries not to laugh, then busts out laughing and can't move.
59+
While he's laughing you run up and shoot him square in the head
60+
putting him down, then jump through the Weapon Armory door.
61+
62+
You do a dive roll into the Weapon Armory, crouch and scan the room
63+
for more Gothons that might be hiding. It's dead quiet, too quiet.
64+
You stand up and run to the far side of the room and find the
65+
and you need the code to get the bomb out. If you get the code
66+
wrong 10 times then the lock closes forever and you can't
67+
get the bomb. The code is 3 digits.)
68+
""")
69+
70+
71+
the_bridge = Room("The Bridge",
72+
"""
73+
该容器点击打开,密封断开,让气体出来。
74+
你拿起中子弹和拼锦全力的跑,你可以到
75+
桥,你必须将其放置在正确的位置。
76+
77+
你用胳膊夹着炸弹,5个试图占领
78+
飞船的控制权的Gothons。他们每个人都有一个更丑陋
79+
小丑服装对比之前。他们没有拿出自己
80+
武器出来呢,因为他们看到在活动的炸弹
81+
手臂,不希望被炸死。
82+
(The container clicks open and the seal breaks, letting gas out.
83+
You grab the neutron bomb and run as fast as you can to the
84+
bridge where you must place it in the right spot.
85+
86+
You burst onto the Bridge with the netron destruct bomb
87+
under your arm and surprise 5 Gothons who are trying to
88+
take control of the ship. Each of them has an even uglier
89+
clown costume than the last. They haven't pulled their
90+
weapons out yet,as they see the active bomb under your
91+
arm and don't want to set it off.)
92+
""")
93+
escape_pod = Room("Escape Pod",
94+
"""
95+
你全部寄托在你的胳膊夹着的原子弹
96+
Gothons举起他们的手,开始流口水。
97+
你快速到达门口,打开它,然后仔细地
98+
把炸弹放置在地板上,就指着你的炸弹了。
99+
之后你跳回到门外,按下了关闭按钮
100+
和摧毁了锁使Gothons无法通过。
101+
现在,炸弹被放置好了,你逃到了逃生舱,以
102+
逃离,这个铁罐(飞船)。
103+
104+
你急于飞船,拼命取保飞船爆炸前
105+
到达逃生舱。好像
106+
几乎没有任何Gothons在船上,所以你逃跑时没有任何
107+
干扰。你到达了逃生舱的房间,现在
108+
需要选择一个上去。他们中的一些可能是损坏的
109+
但你没有时间去仔细看。有艘逃生艇,你打算上
110+
那个?
111+
(You point your blaster at the bomb under your arm
112+
and the Gothons put their hands up and start to sweat.
113+
You inch backward to the door, open it, and then carefully
114+
place the bomb on the floor, pointing your blaster at it.
115+
You then jump back through the door, punch the close button
116+
and blast the lock so the Gothons can't get out.
117+
Now that the bomb is placed you run to the escape pod to
118+
get off this tin can.
119+
120+
You rush through the ship desperately trying to make it to
121+
the escape pod before the whole ship explodes. It seems like
122+
hardly any Gothons are on the ship, so your run is clear of
123+
interference. You get to the chamber with the escape pods, and
124+
now need to pick one to take. Some of them could be damaged
125+
but you don't have time to look. There's 5 pods, which on
126+
do you take?)
127+
""")
128+
129+
130+
the_end_winner = Room("The End",
131+
"""
132+
你跳进2号逃生舱,按下弹出按钮。
133+
该逃生舱很容易滑出到太空
134+
前往下面的星球。当它飞向地球时,你回头
135+
看,会发现你的船爆炸时像
136+
一颗明亮的星星,于此同时逃出了Gothon的飞船。你赢了!
137+
(You jump into pod 2 and hit the ejext button.
138+
The pod easily slides out into space heading to
139+
the planet below. As it flies to the planet, you look
140+
back and see your ship implode then explode like a
141+
bright star, taking out the Gothon ship at the same
142+
time. You won!)
143+
""")
144+
145+
146+
the_end_loser = Room("The End",
147+
"""
148+
你随机跳进一个逃生舱按下弹出按钮。
149+
该逃生舱掉进了空间空隙,然后
150+
船体破裂爆炸了,你的身体粉碎成了
151+
果酱果冻。
152+
(You jump into a random pod and hit the eject button.
153+
The pod escapes out into the void of space, then
154+
impolodes as the hull ruptures, crushing your body
155+
into jam jelly.)
156+
""")
157+
158+
escape_pod.add_paths({
159+
'2': the_end_winner,
160+
'*': the_end_loser
161+
})
162+
163+
generic_death = Room("death", "You died.")
164+
165+
the_bridge.add_paths({
166+
'throw the bomb': generic_death,
167+
'slowly place the bomb': escape_pod
168+
})
169+
170+
laser_weapon_armory.add_paths({
171+
'0132': the_bridge,
172+
'*': generic_death
173+
})
174+
175+
central_corridor.add_paths({
176+
'shoot!': generic_death,
177+
'dodge!': generic_death,
178+
'tell a joke': laser_weapon_armory
179+
})
180+
181+
START = central_corridor

ex52/gothonweb/gothonweb/map.pyc

6.2 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$def with (content)
2+
<html>
3+
<head>
4+
<title>Gothons From Planet Percal #25</title>
5+
</head>
6+
<body>
7+
<p>游戏攻略:
8+
<ul>
9+
<li>escape_pod(
10+
'2': the_end_winner,
11+
'*': the_end_loser)
12+
</li>
13+
<li>the_bridge(
14+
'throw the bomb': generic_death,
15+
'slowly place the bomb': escape_pod)
16+
</li>
17+
18+
<li>laser_weapon_armory(
19+
'0132': the_bridge,
20+
'*': generic_death)
21+
</li>
22+
23+
<li>central_corridor(
24+
'shoot!': generic_death,
25+
'dodge!': generic_death,
26+
'tell a joke': laser_weapon_armory)
27+
</li>
28+
<p>
29+
$:content
30+
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)