Example #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()
Example #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)
Example #3
0
 def frost_shock(state):
   monster = Input.target_monster(state, Constants.FROST_SHOCK_RANGE)
   if monster is None:
     state.status_panel.message('No enemy is close enough or none selected', libtcod.red)
     return Constants.CANCELLED
   state.status_panel.message('You Frost Shock: ' + monster.name + '! The damage done is '
                              + str(Constants.FROST_SHOCK_DAMAGE) + ' hp.', libtcod.light_blue)
   monster.fighter.take_damage(Constants.FROST_SHOCK_DAMAGE, state)
Example #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')