本文整理汇总了Python中snake.Snake.step1方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.step1方法的具体用法?Python Snake.step1怎么用?Python Snake.step1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.step1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import step1 [as 别名]
class Snakegame:
def __init__(self, gridWidth, gridHeight):
self.gridWidth = gridWidth
self.gridHeight = gridHeight
self.food = Space(randint(0, gridWidth - 1), randint(0, gridHeight - 1))
self.traindata = []
self.state = None
self.alive = True
self.snake = Snake(self)
def step1(self):
square = self.snake.step1()
def step2(self, gridWidth, gridHeight):
self.snake.step2()
if self.snake.hitFood(self.food):
self.food = Space(randint(0, self.gridWidth - 1), randint(0, self.gridHeight - 1))
self.snake.fat(3)
if self.snake.isDead(gridWidth, gridHeight):
self.alive = False
def draw(self, screen, squareSize):
for space in self.snake.spaces:
pygame.draw.rect(screen, Color.YELLOW, (space.x * squareSize, space.y * squareSize, squareSize, squareSize))
pygame.draw.rect(screen, Color.RED, (self.food.x * squareSize, self.food.y * squareSize, squareSize, squareSize))