本文整理汇总了Python中Character.Character.keyPress方法的典型用法代码示例。如果您正苦于以下问题:Python Character.keyPress方法的具体用法?Python Character.keyPress怎么用?Python Character.keyPress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character.Character
的用法示例。
在下文中一共展示了Character.keyPress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import keyPress [as 别名]
#.........这里部分代码省略.........
# Manage Game Progression
self.story = Story(self.FRAME_RATE)
# Manage World
self.places = Places()
def new(self):
"""Load new game from file"""
debug("newgame...loading clues")
self.story.loadClues()
debug("newgame...loading charcter")
self.character = Character((0,0), "Character", "Character")
debug("newgame...loading places")
self.places.loadLoc()
debug("end of load")
self.places.addLoc(self.character)
self.story.currClue = self.story._clueList.pop()
#self.frameTimer = QTimer() # Create Frame Timer
self.gameTime = QTime()
self.launch()
def load(self,filename):
"""Load existing game from file"""
debug("loadgame...read data from saved file")
debug("loadgame...loading clues")
self.story.loadClues()
savedData = open(filename)
nextLine = savedData.readline()
# Parsing saved file
while (nextLine):
line = nextLine.split()
if (len(line) == 4 and self.loadIsValid(line)):
x = int(line[0])
y = int(line[1])
numClues = int(line[2])+1
self.story._clueList = self.story._clueList[:numClues]
self.story.score = int(line[3])
debug("x: " + `x` + " y: " + `y` + " numCLue: " + `len(self.story._clueList)` + \
" score is: " + `int(line[3])`)
nextLine = savedData.readline()
savedData.close()
self.story.currClue = self.story._clueList.pop()
debug("loadgame...loading initial character and places")
self.character = Character((x,y), "Character", "Character")
self.places.loadLoc()
debug("end of load")
self.places.addLoc(self.character)
# FIXME if QTime and QTimer should be stored in certain way
self.gameTime = QTime()
#self.frameTimer = QTimer() # Create Frame Timer
self.launch()
def loadIsValid(self,obj):
"""Check that the input from saved file is valid"""
posx = obj[0]
posy = obj[1]
numClue = obj[2]
score = obj[3]
try:
int(posx) and int(posy) and int(numClue) and int(score)
except:
debug("Invalid position input in save file")
return False
return True
def save(self, filename):
"""Save to file"""
fname = open(filename, "w")
score = `self.story.score`
numClues = `len(self.story._clueList)`
charX, charY = self.character.getCenter()
toWriteList = '\t' + `charX` + '\t' + `charY` + '\t' + \
numClues + '\t' + score
fname.write(toWriteList)
fname.close()
def endGame(self):
"""Make things tidy for another game instance"""
# Signal that we have won the game and should
None
def launch(self):
"""Start sending signals to the game using Timers"""
self.gameTime.start()
self.frameTimer.start(ONE_SECOND/self.FRAME_RATE)
self.frameTimer.timeout.connect(self.story.frameTime)
def keyPress(self, event):
key = event.key()
self.character.keyPress(key)
def keyRelease(self, event):
key = event.key()
self.character.keyRelease(key)