本文整理汇总了Python中display.Display.getch方法的典型用法代码示例。如果您正苦于以下问题:Python Display.getch方法的具体用法?Python Display.getch怎么用?Python Display.getch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类display.Display
的用法示例。
在下文中一共展示了Display.getch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import getch [as 别名]
#.........这里部分代码省略.........
self.display.write(block)
# Display Ship
self.display.write(self.ship)
# Move down Aliens
if ori_way != way:
for index, alien in enumerate(self.aliens):
alien.move_down(self.speed_down)
# Move right or left Aliens
for index, alien in enumerate(self.aliens):
if not alien.destroyed:
#if ways[alien.line]:
if way:
alien.move_right()
else:
alien.move_left()
collisions = self.display.write(alien)
if collisions:
self.game_over()
run = False
if not run:
break
# Move Torpedos
for index, torpedo in enumerate(self.torpedos):
if torpedo.destroyed:
del self.torpedos[index]
else:
# Destroy torpedo
if torpedo.atTop or torpedo.atBottom:
# Touch the sky
torpedo.destroy()
self.display.write(torpedo)
else:
torpedo.move()
# Display torpedo
collisions = self.display.write(torpedo)
if collisions:
for entity in collisions:
if type(entity) == Torpedo:
# Align sprite
torpedo.y = entity.y + entity.height
# Destroy torpedo
entity.touch()
torpedo.touch()
elif type(entity) in [Alien1, Alien2] and type(torpedo.parent) in [Alien1, Alien2]:
# Alien2 vs Alien1
pass
else:
# Self shot :)
if torpedo.parent != entity:
entity.touch()
torpedo.destroyed = True
# Display map
self.display.refresh()
# Display score
self.display.addStr((1,1), "Score: %s" % self.score)
lifeStr = "Life: %s" % self.ship.life
self.display.addStr((1,self.display.width - len(lifeStr)), lifeStr)
# Bind keys
c = self.display.getch()
if c == curses.KEY_LEFT:
self.ship.move_left()
elif c == curses.KEY_RIGHT:
self.ship.move_right()
# Space
elif c == 32:
if (time.time() - lastfire) > 0.1:
lastfire = time.time()
self.ship.fire()
# Q
elif c == 113:
self.logger.debug("Quit game")
break
elif c != -1:
self.logger.debug("Key %s preseed" % c)
self.logger.debug("End of game")
except Exception as err:
pass
finally:
self.display.close()
self.logger.dump()
if err:
traceback.print_exc(limit=20, file=sys.stdout)
示例2: start
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import getch [as 别名]
def start(self):
score = 0
lives = 3
level = 1
framerate = 25
shields = 4
alien_tick = 15
gameover = False
display = Display()
gun = Gun(maxx=display.width, maxy=display.height)
aliens = self.make_aliens(42, display.width, alien_tick)
while True:
self.status(display, lives, score, level)
for alien in aliens:
alien.move()
display.putstring(alien.last[0], alien.last[1], " ")
display.putstring(alien.current[0], alien.current[1], alien.alien)
display.putstring(gun.guny, gun.gunx, gun.gun)
for index, alien in enumerate(aliens):
hit = gun.hit(alien.current[0], alien.current[1])
if hit:
display.putstring(alien.current[0], alien.current[1], " BOOM ")
score += 1
del(aliens[index])
break
if alien.current[0] == display.height - 2:
if lives > 0:
lives -= 1
aliens = self.make_aliens(42, display.width, alien_tick)
display.erase()
else:
gameover = True
display.putstring(10, 30, "Game Over!!!")
break
if aliens == []:
display.putstring(10, 30, "YOU WIN!!!!")
if gun.firing:
gun.fire()
display.putstring(gun.bullety, gun.bulletx, gun.bullet)
display.refresh()
time.sleep(1.0 / framerate)
if gameover:
display.close()
break
if gun.firing:
display.putstring(gun.bullety, gun.bulletx, " ")
if hit:
display.putstring(alien.current[0], alien.current[1], " ")
if aliens == []:
display.putstring(10, 30, " ")
level += 1
alien_tick -= 1
aliens = self.make_aliens(42, display.width, alien_tick)
display.refresh()
i = display.getch()
if i == ord("a"):
gun.left()
elif i == ord("d"):
gun.right()
elif i == ord("s"):
gun.start()
elif i == ord("q"):
display.close()
break