#创建食物,用到了random函数
formuerandom import Random
class Food:
def __init__(self):
self.position= None
def chose_new_position(self,used_position):
while True:
x = random.randint(1,size - 2)#我们设置的墙是从0到23,共24个小圈,而食物不能出现在墙上
y = random.randint(1,size - 2)
temp = True
for i in used_position:
if x == i.x and y == i.y:#这是判断食物是否在界限之内
temp = True
break
if not temp:
break
self._position = Point(x,y)#这是将xy输入position这个数组中
def get_position(self):
return [self.__position]
1.random.randint(1,9)的含义是从1到9这九个数中随机挑选出一个整数