Пример #1
0
 def edit_mode(self):
   self.state.game_state = Constants.PAUSE
   self.state.game_map.game_maps[self.state.game_map.game_map_id][self.state.get_target_x()][self.state.get_target_y()].targeted = True
   while not libtcod.console_is_window_closed():
     self.state.turn += 1
     Util.render_all(self.state)
     libtcod.console_flush()
     Input.handle_keys(self.state, False)
     if self.state.game_state == Constants.PLAYING:
       self.play_game()
Пример #2
0
 def play_game(self):
   self.state.game_state = Constants.PLAYING
   self.state.game_map.game_maps[self.state.game_map.game_map_id][self.state.get_target_x()][self.state.get_target_y()].targeted = False
   self.state.game_map.game_maps[self.state.game_map.previous_map_id][self.state.get_target_x()][self.state.get_target_y()].targeted = False
   while not libtcod.console_is_window_closed():
     sleep(0.20)
     self.state.turn += 1
     Util.render_all(self.state)
     libtcod.console_flush()
     Input.handle_keys(self.state, True)
     if self.state.game_state == Constants.PAUSE:
       self.edit_mode()
     self.state.game_map.process_map(self.state)
Пример #3
0
 def next_level(self):
   self.state.dijkstra_map_update = True
   self.state.dungeon_level += 1
   self.state.status_panel.message('You take a moment to rest and recover 50% health', libtcod.violet)
   self.state.player.fighter.heal(self.state.player.fighter.max_hp(self.state) / 2, self.state)
   self.state.status_panel.message('and now you descend into the depths of the dungeon', libtcod.red)
   if self.state.dungeon_level in self.state.game_map.complete_game_map:
     self.state.game_map.set_game_map(self.state.dungeon_level)
     down_stairs_id = Util.get_padded_coords(self.state.player.x, self.state.player.y)
     up_stairs_id = self.follow_stairs(MapConstants.DOWN_STAIRS_OBJECT, down_stairs_id, self.state.dungeon_level - 1)
     self.state.player.x, self.state.player.y = Util.get_coords_from_padded_coords(up_stairs_id)
   else:
     self.state.objects_map[self.state.dungeon_level] = [self.state.player]
     self.state.game_map.generate_map(self.state, self.state.dungeon_level)
     self.state.score += self.state.dungeon_level * 10
   self.state.objects = self.state.objects_map[self.state.dungeon_level]
   self.initialize_fov(self.state.dungeon_level)
   self.state.set_player_action(None)
   self.state.fov_recompute = True
   Util.render_all(self.state)
Пример #4
0
  def play_game(self):
    self.state.set_game_state(Constants.PLAYING)
    self.state.set_player_action(None)
    self.state.fov_recompute = True

    while not libtcod.console_is_window_closed():
      self.state.turn += 1
      Util.render_all(self.state)
      libtcod.console_flush()
      Util.check_level_up(self.state)
      for object in self.state.objects:
        object.clear(self.state.con)
      self.state.set_player_action(Constants.DID_NOT_TAKE_TURN)
      while self.state.get_player_action() == Constants.DID_NOT_TAKE_TURN:
        Input.handle_keys(self.state)

      player_action = self.state.get_player_action()
      if player_action == Constants.EXIT or self.state.player.color == libtcod.dark_red:
        self.save_game()
        break

      if self.state.get_game_state() == Constants.PLAYING and self.state.get_player_action() != Constants.DID_NOT_TAKE_TURN:
        AiUtils.dijkstra_on_map(self.state, self.state.player.x, self.state.player.y)
        monsters_still_alive = False
        for object in self.state.objects:
          if object.ai:
            monsters_still_alive = True
            object.ai.take_turn(self.state)
        if not monsters_still_alive and self.state.game_type == Constants.BATTLE:
          old_player_coords = self.state.player.x, self.state.player.y
          self.state.game_map.generate_battle_map(self.state)
          self.state.player.x, self.state.player.y = old_player_coords
      if player_action == Constants.NEXT_LEVEL:
        self.next_level()
      elif player_action == Constants.PREVIOUS_LEVEL:
        self.previous_level()
      elif player_action == Constants.EXIT or self.state.player.color == libtcod.dark_red:
        Util.render_all(self.state)
        self.save_game()
        break
      self.state.status_panel.message('###### Turn ' + str(self.state.turn) + ' has ended')