马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
好像王八的确容易饿死 ,还是圈小点好,养青蛙也不容易啊 import random as r
def move(pos,stepmax):
(x,y)=pos
direction=r.randint(0,4)
step=r.randint(1,stepmax)
if direction==0:
y+=step
elif direction==1:
y-=step
elif direction==2:
x-=step
else:
x+=step
if x<0:
x *=-1
if x>10:
x=20-x
if y<0:
y *= -1
if y>10:
y=20-y
return (x,y)
class Turtle():
def __init__(self):
self.x=r.randint(0,10)
self.y=r.randint(0,10)
self.hp=100
def getpos(self):
return (self.x,self.y)
def setpos(self,pos):
self.x,self.y=pos
class Fish():
def __init__(self):
self.x=r.randint(0,10)
self.y=r.randint(0,10)
turtle=Turtle()
fish=[]
for i in range(10):
newfish=Fish()
fish.append((newfish.x,newfish.y))
def Game():
count=10
while turtle.hp>0 and count>0:
index=[]
for i in range(len(fish)):
if fish[i]==turtle.getpos():
turtle.hp += 20
print("王八hp+20,hp为",turtle.hp)
count -= 1
index.append(i)
print(10-count,'鱼被吃')
sorted(index)
for each in index:
fish.pop(each)
turtle.setpos(move(turtle.getpos(),2))
turtle.hp -= 1
print('王八动了,hp-1,hp为',turtle.hp)
for each_fish in fish:
each_fish=move(each_fish,1)
print('GAME OVER!')
if turtle.hp==0:
print('王八是饿死的!')
else:
print('鱼都被吃完啦!')
Game()
根据条件,基本都是饿死的
|