# 随机生成无冲突坐标 def_get_random_block(self): block = self._random() for pos in self.snake.body: if pos[0] == block[0] and pos[1] == block[1]: return self._get_random_block() for pos in self._block: if pos[0] == block[0] and pos[1] == block[1]: return self._get_random_block() if block[0] == self._food[0] and block[1] == self._food[1]: return self._get_random_block() return block
生成砖块和食物后,我们将他绘制到地图上
1 2 3 4 5
defon_draw(self): self.snake.on_draw(self) self.draw_surface(self._food, self.food) for block in self._block: self.draw_surface(block, self.block)