Beispiel #1
0
 def main_menu(self):
   # img = libtcod.image_load('rl_image.png')
   # show the background image, at twice the regular console resolution
   while not libtcod.console_is_window_closed():
     # libtcod.image_blit_2x(img, 0, 0, 0)
     choice = self.menu.display_menu_return_index('', ['Play a new game', 'Continue last game',
                                                       'Battle (work in progress)', 'High Scores', 'Quit'], 30,
                                                  self.state.con)
     if choice == 0:
       self.new_game()
       self.play_game()
     elif choice == 1:
       try:
         self.load_game()
       except:
         self.message_box('No saved game to load', 24)
         continue
       self.play_game()
     elif choice == 2:
       self.battle()
       self.play_game()
     elif choice == 3:
       self.show_high_scores()
     elif choice == 4:
       break
 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()
 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)
Beispiel #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')
 def main_menu(self):
   while not libtcod.console_is_window_closed():
     choice = self.menu.display_menu_return_index('', ['Play a new game', 'Continue last game',
                                                       'Custom Map Mode', 'High Scores', 'Quit'], 30, self.state.con)
     if choice == 0:
       self.new_game()
       self.play_game()
     elif choice == 1:
       try:
         self.load_game()
       except:
         self.message_box('No saved game to load', 24)
         continue
       self.play_game()
     elif choice == 2:
       self.make_custom_map()
       self.edit_mode()
     elif choice == 3:
       self.show_high_scores()
     elif choice == 4:
       break