|
发表于 2020-6-8 17:44:59
From FishC Mobile
|
显示全部楼层
|阅读模式
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import random
- class Turtle:
- def creat(self):
- return [0,0]
- def moving(self,pos_x,pos_y):
- self.pos_x=pos_x
- self.pos_y=pos_y
- step_x=random.randint(-2,2)
- step_y=random.randint(-2,2)
- new_pos_x=self.pos_x+step_x
- if new_pos_x>10:
- new_pos_x-=10
- if new_pos_x<0:
- new_pos_x*=-1
- new_pos_y=self.pos_y+step_y
- if new_pos_y>10:
- new_pos_y-=10
- if new_pos_y<0:
- new_pos_y*=-1
- return [new_pos_x,new_pos_y]
- class Fish:
- def __init__(self):
- self.step=random.randint(-1,1)
- self.pos_x=random.randint(0,11)
- self.pos_y=random.randint(0,11)
- def creat(self):
- return [self.pos_x,self.pos_y]
- def moving(self,pos_x,pos_y):
- self.pos_x=pos_x
- self.pos_y=pos_y
- step_x=random.randint(-1,1)
- step_y=random.randint(-1,1)
- new_pos_x=self.pos_x+step_x
- if new_pos_x>10:
- new_pos_x-=10
- if new_pos_x<0:
- new_pos_x*=-1
- new_pos_y=self.pos_y+step_y
- if new_pos_y>10:
- new_pos_y-=10
- if new_pos_y<0:
- new_pos_y*=-1
- return [new_pos_x,new_pos_y]
- t=Turtle()
- tt=t.creat()
- f=Fish()
- mylist=[]
- for i in range(1,11):
- ff=f.creat()
- mylist.append(ff)
- count=101
- while count>0:
- if mylist!=[]:
- if tt in mylist:
- print('恭喜你吃了一条鱼,体力加20!')
- mylist.remove(tt)
- count+=20
- else:
- count-=1
- print(tt,'\n',mylist)
- else:
- print('恭喜您,victory')
- break
- t=Turtle()
- tt=t.moving(tt[0],tt[1])
-
- for i in range(len(mylist)-1):
- a=Fish()
- b=a.moving(mylist[i][0],mylist[i][1])
- mylist.remove(mylist[i])
- mylist.insert(i,b)
- else:
- print('体力为0,游戏结束')
复制代码
达不到要求啊,咋改改 |
|