void BinarySearchTree<T>::_travel(TreeItem<T> *p) { if (!p) { return; } _travel(p->_left); std::cout << p->_value << " "; _travel(p->_right); }
void game_loop() { int regen_timer = 0; _draw(); while (io::window_is_open() && _game_running) { if (!io::window_is_open()) break; bool do_update_action_list = false; int state = statestack_top(); if (get_action_list_size() == 0) { append_action_list(&player); for (size_t i = 0; i < current_dungeon->creatures.size(); i++) { append_action_list(current_dungeon->creatures.at(i)); } _regenerate_creatures(regen_timer); // Tick effects every turn. tick_effects(); // Update gas clouds and gas machines. update_gas_machines(current_dungeon); // Update stealth check_stealth(); // Respawn creatures if few enough. if (_count_enemies_in_current_dungeon() <= 3 && one_in(25)) { spawn_monsters(current_branch->name, current_dungeon, current_dungeon->level, random(0, 3), true); } // Increase turn count. turn_count++; } if (current_actor()->identity == IDENT_PLAYER) { int old_player_ap = player.ap; // Do this before taking action -> // Draws everything from the previous turn and also // shows all the previous turns messages. _draw(); if (state == STATE_READ_COMMAND) { _read_command(); } else if (state == STATE_EXAMINE || state == STATE_CAST_SPELL || state == STATE_ZAP_WAND) { _move_targeting_cursor(); } else if (state == STATE_CLOSE_DOOR || state == STATE_CHAT) { _select_direction(); } else if (state == STATE_TRAVEL) { _travel(); } do_update_action_list = old_player_ap != player.ap; if (do_update_action_list) { check_cloud_collisions(current_dungeon); // Check if player has gained a level. if (can_gain_level()) { gain_level(); } } } else { creature_t* actor = current_actor(); actor->update(); do_update_action_list = true; } if (do_update_action_list) { if (current_actor() && current_actor()->ap <= 0) { if (current_actor()->identity == IDENT_PLAYER) { tick_food_clock(); } // TODO: Regenerate creature here. current_actor()->ap += 100; remove_from_action_list(current_actor()); } sort_action_list(); } } }
void BinarySearchTree<T>::travel() { _travel(root); }