예제 #1
0
int main() {

  // Actions
  action_map actions;

  actions.insert(std::make_pair<char, MenuActionPtrType>('w', &move_self_up));
  actions.insert(std::make_pair<char, MenuActionPtrType>('d', &move_self_right));
  actions.insert(std::make_pair<char, MenuActionPtrType>('s', &move_self_down));
  actions.insert(std::make_pair<char, MenuActionPtrType>('a', &move_self_left));
  actions.insert(std::make_pair<char, MenuActionPtrType>('q', &action_quit));
  actions.insert(std::make_pair<char, MenuActionPtrType>(' ', &action_do_stuff));
  actions.insert(std::make_pair<char, MenuActionPtrType>('i', &action_display_inventory));
  actions.insert(std::make_pair<char, MenuActionPtrType>('?', &action_display_help));
  gui.add_message("Welcome!");

  // Require colour
  if(has_colors() == FALSE) {	
    endwin();

    printf("Your terminal does not support color\n");
    RUNNING = false;
	}


  int level = 0;
  tile_info_text = "Here you will see information about what you encounter.";
  int c;
  action_display_help();
  gui.create_windows();
  gui.print_info();
  print_tile_info();
  gui.print_map();
  gui.show_notification_box(maphandler.get_map().get_map_info());

  while(RUNNING) {
  
    c = getch();
    action_map::const_iterator start = actions.find(c);
    if (start != actions.end()){
      ((*start).second) ();
    }
    
    // Tick for all objects
    maphandler.get_map().ticks();

    // Move player to other world, if needed
    int level = maphandler.get_map().set_level;
    if (level > 0) {
      maphandler.change_map(maphandler.current_map + 1);
      // gui.update_map(maphandler.get_map());
      gui.show_notification_box(maphandler.get_map().get_map_info());
      gui.add_message("A whole new world, exciting!");
    }

    print_tile_info();
    gui.print_info();
    gui.print_map();
  }
  endwin();

  return 0;
}
예제 #2
0
basic_building& simulation::create_building(WINDOW* scr)
{
    /*
     * The base of this code will eventually become the building editor
     * and the idea behind it will form the general procedure for editing
     * objects
     * 
     * Meaning it will be split into (template) functions
     */
    
    
    
    //create our form for input
    generic_form values_form(scr);
    keypad (scr, TRUE);
    //add the input fields
    values_form.add_field("Enter the width: ", false);
    values_form.add_field("Enter the height: ", false);
    values_form.add_field("Enter the name: ", true);
    values_form.add_field("Enter the desc:", true);
    //give the form control and fill fields
    values_form.fill_form();
    status_message = "(q) Quit  (s) Switch Solid State  (c) Set Appearance";
    //create the basic building
    basic_building* new_building = 
            new basic_building(values_form.get_str_input(0), 
            values_form.get_str_input(1), 0, 0, values_form.get_int_input(0), 
            values_form.get_int_input(1));
    //create a derived window of scr that can fit our new building
    WINDOW* building_scr = derwin(scr, new_building->get_length(), 
            new_building->get_width(), 2, 0);
    //print some console messages
    console_print("New building printed to screen");
    console_print("Building name: " + new_building->get_name());
    //while we are not done editing the building
    //aka main loop
    int c = 0;
    //print the building to the derived window
    new_building->print_building(building_scr);
    //update our screen
    update_parent_child(scr, building_scr);
    wmove(building_scr, 0, 0);
    keypad(building_scr, TRUE);
    //refresh the derived window
    int cursor_x = 0;
    int cursor_y = 0;
    wrefresh(building_scr);
    //create a generic_menu object because switch statements don't allow
    //declarations within them
    generic_menu app_menu(scr);
    //might as well fill it in up here, so it doesn't clutter up down there
    app_menu.add_choice("#", 0);
    app_menu.add_choice("+", 1);
    app_menu.add_choice("_", 2);
    app_menu.add_choice(" ", 3);
    app_menu.set_pos(2, new_building->get_width() + 1);
    while((c = wgetch(building_scr)) != 'q')
    {

        getyx(building_scr, cursor_y, cursor_x);
        
        switch (c)
        {
            case KEY_UP:
                wmove(building_scr, cursor_y - 1, cursor_x);
                print_tile_info(scr, new_building->get_tile(cursor_y - 1,
                        cursor_x));
                update_parent_child(scr, building_scr);
                break;
            case KEY_DOWN:
                wmove(building_scr, cursor_y + 1, cursor_x);
                print_tile_info(scr, new_building->get_tile(cursor_y + 1,
                        cursor_x));
                update_parent_child(scr, building_scr);
                break;
            case KEY_LEFT:
                wmove(building_scr, cursor_y, cursor_x - 1);
                print_tile_info(scr, new_building->get_tile(cursor_y, 
                        cursor_x - 1));
                update_parent_child(scr, building_scr);
                break;
            case KEY_RIGHT:
                wmove(building_scr, cursor_y, cursor_x + 1);
                print_tile_info(scr, new_building->get_tile(cursor_y, 
                        cursor_x + 1));
                update_parent_child(scr, building_scr);
                break;
            case 's': //switch solidity state of the tile
                new_building->get_tile(cursor_y, cursor_x)->set_solid
                (!new_building->get_tile(cursor_y, cursor_x)->is_solid());
                print_tile_info(scr, new_building->get_tile(cursor_y, 
                        cursor_x));
                break;
            case 'c':
                c = app_menu.get_choice();
                switch (c)
                {
                    case 0:
                        new_building->get_tile(cursor_y, 
                                cursor_x)->set_app('#');
                        break;
                    case 1:
                        new_building->get_tile(cursor_y, 
                                cursor_x)->set_app('+');
                        break;
                    case 2:
                        new_building->get_tile(cursor_y, 
                                cursor_x)->set_app('_');
                        break;
                    case 4:
                        new_building->get_tile(cursor_y, 
                                cursor_x)->set_app(' ');
                        break;
                }
                new_building->print_building(building_scr);
                print_tile_info(scr, new_building->get_tile(cursor_y, 
                        cursor_x));
        }
        update_parent_child(scr, building_scr);
    } 
}