上一个问题的BUG已经完善,加一个小飞机刷出条件不重叠。
代码如下:
import random as r
import sys
legal_x = [0,10]
legal_y = [0,25]
class Big:
def __init__(self):
"""在y=1随机生成炮台位置"""
self.x = r.randint(0,10)
self.y = 1
def move(self):
self.Interval = []
"""随机移动左右方向并移动到新的位置(x,1)"""
self.step = r.randint(0,legal_x[1])
self.direction = r.randint(-1,1)#方向,-1为左,0不移动,1为右
new_x = self.x + self.direction * self.step
mew_y = self.y
"""判断是否越界"""
if new_x > legal_x[1]:
pos_x = legal_x[1] - (new_x - legal_x[1])