|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random as r
class Turtle:
def __init__(self):
delf.power=100
def __init__(self):
self.x=r.randint(legal_x[0],legal_x[10])
self.y=r.randint(legal_y[0],legal_y[10])
def move(self):
new_x=self.x+r.choice([-1,1,2,-2])
new_y=self.y+r.choice([-1,1,2,-2])
if new_x==11:
new_x=9
if new_x==12:
new_x=8
if new_x==-1:
new_x=1
if new_x==-2:
new_x=2
if new_y==11:
new_y=9
if new_y==12:
new_y=8
if new_y==-1:
new_y=1
if new_y==-2:
new_y=2
self.x=new_x
self.y=new_y
self.power-=1
return(self.x,self.y)
def eat(self):
self.power+=20
if self.power>100:
self.power=100
class Fish:
def __init__(self):
self.x=r.randint(legal_x[0],legal_x[10])
self.y=r.randint(legal_y[0],legal_y[10])
def move(self):
new_x=self.x+r.choice([-1,1,2,-2])
new_y=self.y+r.choice([-1,1,2,-2])
if new_x==11:
new_x=9
if new_x==12:
new_x=8
if new_x==-1:
new_x=1
if new_x==-2:
new_x=2
if new_y==11:
new_y=9
if new_y==12:
new_y=8
if new_y==-1:
new_y=1
if new_y==-2:
new_y=2
self.x=new_x
self.y=new_y
self.power-=1
return(self.x,self.y)
turtle=Turtle()
new_fish=Fish()
fish=[]
for i in range(10):
fish.appent(new_fish)
while 1:
if len(fish==0):
print('鱼儿都被吃完了,游戏结束')
break
if title.power==0:
print('乌龟没有体力了,游戏结束')
break
for each_fish in fish[:]:
if each_fish.move==turtle.move():
title.eat()
fish.remove(each_fish)
print('有一条鱼儿被吃掉了')
求大神帮忙找找错误
自己找不到了
if len(fish==0):
改为
if len(fish)==0:
|
|