|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random as r
class Turtle:
orientx = r.randint(0,10)
orienty = r.randint(0,10)
strength = 100
count = 0
def game(self):
while self.strength > 0:
move = r.randint(1,2) #移动1或者2
direction = r.randint(1,4) #方向上下左右
if direction == 1:
self.orientx += move
if direction == 2:
self.orientx -= move
if direction == 3:
self.orienty += move
if direction == 4:
self.orienty -= move
if self.orientx == -1:
self.orientx = 1
if self.orientx == -2:
self.orientx = 2
if self.orientx == 11:
self.orientx = 9
if self.orientx == 12:
self.orientx = 8
if self.orienty == -1:
self.orienty = 1
if self.orienty == -2:
self.orienty = 2
if self.orienty == 11:
self.orienty = 9
if self.orienty == 12:
self.orienty = 8
twhere = (self.orientx,self.orienty)
self.strength -= 1
count += 1
class Fish:
orientx = r.randint(0,10)
orienty = r.randint(0,10)
count = 0
def game(self):
while 1:
move = 1
direction = r.randint(1,4) #方向上下左右
if direction == 1:
self.orientx += move
if direction == 2:
self.orientx -= move
if direction == 3:
self.orienty += move
if direction == 4:
self.orienty -= move
if self.orientx == -1:
self.orientx = 1
if self.orientx == 11:
self.orientx = 9
if self.orienty == -1:
self.orienty = 1
if self.orienty == 11:
self.orienty = 9
twhere = (self.orientx,self.orienty)
t1 = Turtle()
f1 = Fish();f2 = Fish();f3 = Fish();f4 = Fish();f5 = Fish();\
f6 = Fish();f7 = Fish();f8 = Fish();f9 = Fish();f10 = Fish()
d = {'1':f1,'2':f2,'3':f3,'4':f4,'5':f5,'6':f6,'7':f7,'8':f8,'9':f9,'10':f10}
while True:
t1.game
for each in range(1,11):
each = str(each)
d[each].game
if d[each].count == t1.count and d[each].orientx == t1.orientx and d[each].orienty == t1.orienty:
t1.strength += 20
del d[each]
print('小鱼%s被吃掉啦' % each)
if t1.strength == 0:
print('乌龟完犊子')
break
if len(d) == 0:
print('鱼吃完了')
break
|
|