Exemple #1
0
int select_level (MapPack const & mappack) {
  int input;
  int level = mappack.get_currentlevel();
  int maxlevel = mappack.get_maxlevel() + 1;

  if (maxlevel > mappack.get_number_maps())
    maxlevel = mappack.get_number_maps();
  if (level == 0)
    level = mappack.get_lastlevel();

  pauserun(1);
  fillsquare(LINES / 2 - 2, (COLS - 16) / 2, 4, 16);
  do {
    mvprintw(LINES / 2 - 1, (COLS - 14) / 2, "Choose a Level");
    mvprintw(LINES / 2, (COLS - 7) / 2, "< %3d >", level);
    refresh();
    restms(10);
    input = getinput();
    if (input == 27) return -1; // Back to the menu
#ifdef PDCURSES
    if (input == KEY_RESIZE) resize_term(0,0);
#endif
#ifndef __NOSOUND__
    if ((input == 'M') || (input == 'm')) toggle_ambience ();
#endif
    if ((input >= '0') && (input <= '9')) {
      level = level * 10 + input - '0';
#ifndef __NOSOUND__
      play_sound(MENUBEEP);
#endif
    }
    if (input == KEY_RIGHT) {
#ifndef __NOSOUND__
      play_sound(MENUBEEP);
#endif
      level ++;
    }
          if (input == KEY_LEFT) {
#ifndef __NOSOUND__
      play_sound(MENUBEEP);
#endif
            level --;
          }
          if (level > maxlevel) {
            if ((input >= '0') && (input <= '9')) level = input - '0';
            else level = maxlevel;
          }
    if (level < 1) level = 1;
  } while ((input != '\n') && (input != ' ') && (input != 'z') && (input != 'x'));

  pauserun(0);
#ifndef __NOSOUND__
  play_sound(MENUCHOICE);
#endif
  return level;
}
Exemple #2
0
int play(MapPack &mappack) {
  level &lvl = mappack.lvl;

  // Have we finished the map pack yet?
  bool finished = false;
    
#ifndef __NOSOUND__
  default_ambience (0);
  start_ambience ();
#endif
 
  while (!finished) {
    switch (play_level(mappack)) {
    case 0: return 0; break;
    case 2: // We're dead...
#ifndef __NOSOUND__
      beep ();
#endif
      lvl.stats.numdeaths++;
      mappack.save.numticks += lvl.ticks;
      mappack.save.numdeaths++;
      lvl.stats.numportals = 0;
      fillscreen(screenchar(XFIELD)); refresh();
      restms(100);
      fillscreen(CharData[XFIELD][2] | color_pair(XFIELD) | WA_ALTCHARSET); refresh();
      restms(150);
      mappack.reload_level();
      flushinput();
      break;
    case 3: // We've won!
#ifndef __NOSOUND__
      play_sound(WIN);
#endif
      lvl.stats.numticks = lvl.ticks;
      mappack.update_stats();
      mappack.set_maxlevel(mappack.get_currentlevel());
      // if the user wants to quit now, he will restart with the next level
      mappack.set_lastlevel(mappack.get_currentlevel() + 1);
      if (displaystats(lvl)) {
        if (mappack.get_currentlevel() == mappack.get_number_maps())
          finished = true;
        ++mappack;
      } else
        mappack.reload_level();
      break;
    } // switch
  } // while (!finished)

  roll_credits(mappack);
  return 1;
}