本文整理汇总了Python中simulation.Simulation.setCatMove方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.setCatMove方法的具体用法?Python Simulation.setCatMove怎么用?Python Simulation.setCatMove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.Simulation
的用法示例。
在下文中一共展示了Simulation.setCatMove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import setCatMove [as 别名]
#.........这里部分代码省略.........
def mainLoop(self, ):
"""The main loop of the game.
"""
while self.run:
self.handleEvents()
self.updateGameState()
self.clock.tick(60)
self.draw()
def draw_text(self, text, x, y):
text_s = self.subfont.render(text, True, (255,255,255))
text_r = text_s.get_rect()
text_r.x = x
text_r.y = y
self.screen.blit(text_s, text_r)
return text_r.bottom
def draw(self):
"""
"""
self.screen.blit(self.background, (0,0))
self.screen.blit(self.goal.image, self.goal.getRect())
if self.DEBUG:
rect2 = pygame.Rect(0,0, 5*self.PPU, 2*self.PPU)
rect2.center = self.goal.position
pygame.draw.rect(self.screen, (255,0,0), rect2, 1)
for entity in self.dogs:
rect = entity.getRect()
self.screen.blit(entity.image, rect)
if self.DEBUG:
dogsize = self.simulation.DOG_SIZE
rect2 = pygame.Rect(0,0, dogsize[0]*self.PPU, dogsize[1]*self.PPU)
rect2.center = entity.position
pygame.draw.rect(self.screen, (255,0,0), rect2, 1)
catrect = self.cat.getRect()
self.screen.blit(self.cat.image, catrect)
pygame.draw.circle(self.screen, (255,0,0), catrect.center,
int(round(self.simulation.CAT_RADIUS*self.PPU)), 1)
next_y = self.draw_text("Wins: %d" % self.wins, 5, 5)
next_y = self.draw_text("Losses: %d" % self.losses, 5, next_y)
self.draw_text("Interest: %.8f" % self.interest, 5, next_y)
pygame.display.flip()
def handleEvents(self):
"""
"""
for event in pygame.event.get():
if event.type == QUIT:
self.run = False
elif event.type == KEYDOWN:
if event.key in DIR_MAP:
self.input.keydown(DIR_MAP[event.key])
elif event.key == K_ESCAPE:
self.run = False
elif event.type == KEYUP:
if event.key in DIR_MAP:
self.input.keyup(DIR_MAP[event.key])
self.simulation.setCatMove(self.input.getDirection())
def updateGameState(self):
"""
"""
subtick = self.tickcount % self.TICKFACTOR
percentage = subtick/self.TICKFACTOR
# We're done with one round of game ticks, time for next sim tick
if subtick == 0:
# If simulation has not finished yet, keep ticking the simulation,
# otherwise set game's gameover flag and update all entities to
# final position, as we are on the final tick of this game
if self.simstate["gameover"] == False:
self.simstate = self.simulation.simtick()
self.logger.gameTicked(self.simstate)
self.cat.updateTarget(self._simToGamePosition(self.simstate["cat"]))
for simdog, gamedog in zip(self.simstate["dogs"], self.dogs):
gamedog.updateTarget(self._simToGamePosition(simdog))
else:
self.gameover = True
self.cat.updatePosition(1.0)
for dog in self.dogs:
dog.updatePosition(1.0)
if not self.gameover:
self.cat.updatePosition(percentage)
for dog in self.dogs:
dog.updatePosition(percentage)
self.tickcount += 1
else:
self.logger.gameEnded(self.simstate["win"])
N, wins, interest = self.logger.getStats(1.0, 1.0, 1.0)
self.wins = wins
self.losses = N-wins
self.interest = interest
self.simulationInit()
self.entityInit()