本文整理汇总了Python中snake.Snake.check_loss方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.check_loss方法的具体用法?Python Snake.check_loss怎么用?Python Snake.check_loss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.check_loss方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import check_loss [as 别名]
class Game():
star_cords = (0, 0)
def __init__(self, screen):
self.screen = screen
self.RUNNING = True
self.speed = 1.0
self.place_star()
def speed_up(self):
self.speed /= 2.0
def speed_down(self):
self.speed *= 2.0
def calc_start_loc(self):
y = curses.LINES // 2
x = curses.COLS // 2
return (y, x)
def start(self):
self.snek = Snake(
self.screen,
6,
self.calc_start_loc()
)
self.snek.render()
while self.RUNNING:
try:
time.sleep(self.speed)
self.tick()
except KeyboardInterrupt:
self.RUNNING = False
def place_star(self):
y = random.randint(0, curses.LINES - 1)
x = random.randint(0, curses.COLS - 1)
self.star_cords = (y, x)
def check_star_get(self):
if self.star_cords in [
seg.coordinates
for seg in self.snek.body
]:
self.snek.add_segment()
self.place_star()
def tick(self):
self.screen.clear()
direction = self.screen.getch()
if 258 <= direction <= 261:
if direction == self.snek.direction:
self.speed_up()
elif (direction <= 259 and self.snek.direction <= 259
or direction >= 260 and self.snek.direction >= 260):
self.speed_down()
elif direction < 260:
self.speed_down()
self.snek.direction = direction
else:
self.speed_up()
self.snek.direction = direction
self.snek.move()
self.snek.check_loss()
self.check_star_get()
self.screen.addstr(
self.star_cords[0],
self.star_cords[1],
'*'
)
self.snek.render()
self.screen.refresh()