Example #1
0
  // this is the actual game thread start
  // it loops for each complete game played
  public void run() {
    while (true) {

      Screen ss = new Screen(this);
      ss.setBackground(new Color(0, 0, 0));
      ss.setLayout(new BorderLayout());
      {
        TitleScreen ts = new TitleScreen(this);
        ts.setBackground(new Color(0, 0, 0));
        ss.add("Center", ts);
      }
      MessagePanel mp = new MessagePanel(this);
      Game.messagepanel = mp;
      ss.add("South", mp);

      switchScreen(ss);

      repaint();

      if (!isapplet && gameFileFromCommandLine != null) {
        Game.message("Loading " + gameFileFromCommandLine + " game file...");
        final String ret = Game.tryToRestore(gameFileFromCommandLine);
        if (ret == null) {
          setupScreen();
          getScreen().mainLoop();
          continue;
        }

        Game.message("Load game failed: " + ret);
        Game.message("Press any key (except Tab) to continue");
        Game.getInput(false); // !!! not very good - this does not
        // recognize Tab key, for instance

      }

      Game.message("");
      Game.message(
          "Welcome to Tyrant. You are playing version " + Game.VERSION + ". Would you like to:");
      Game.message(" [a] Create a new character");
      Game.message(" [b] Load a previously saved game");
      Game.message(" [c] Play in debug mode");
      Game.message(" [d] QuickStart debug mode");
      Game.message(" [e] Edit a map");
      mp.repaint();

      // create lib in background
      Game.asynchronousCreateLib();

      char c = Game.getOption("abcdeQ");

      Game.setDebug(false);
      Game.visuals = true;

      if (c == 'b') {
        if (Game.restore()) {
          setupScreen();
          getScreen().mainLoop();
        }

      } else if (c == 'c') {
        // do hero creation
        Game.create();
        Thing h = createHero(true);
        if (h == null) continue;

        Game.setDebug(true);
        setupScreen();
        gameStart();

      } else if (c == 'e') {
        // Designer
        Game.message("");
        Game.message("Launching Designer...");
        mikera.tyrant.author.Designer.main(new String[] {"embedded"});
        continue;

      } else {

        Game.create();
        Thing h = createHero(true);

        if (h == null) continue;

        // first display starting info....
        InfoScreen l =
            new InfoScreen(
                this,
                "                                 Introduction\n"
                    + "\n"
                    + "Times are hard for the humble adventurer. Lawlessness has ravaged the land, and few can afford to pay for your services.\n"
                    + "\n"
                    + "After many weeks of travel, you find yourself in the valley of North Karrain. This region has suffered less badly from the incursions of evil, and you hear that some small towns are still prosperous. Perhaps here you can find a way to make your fortune.\n"
                    + "\n"
                    + "After a long day of travel, you see a small inn to the west. Perhaps this would be a good place to meet some and learn some more about these strange lands.\n"
                    + "\n"
                    + "                           [ Press a key to continue ]\n"
                    + "\n"
                    + "\n"
                    + "\n"
                    + "\n"
                    + "\n");

        l.setForeground(new Color(192, 160, 64));
        l.setBackground(new Color(0, 0, 0));
        switchScreen(l);
        Game.getInput();
        setupScreen();
        gameStart();

        // Debug mode should not start when pressing Enter!!
        // Game.create();
        // Game.setDebug(true);
        // createHero(false);
        // setupScreen();
        // gameStart();
      }
    }
  }
Example #2
0
  // creates a hero according to specified parameters
  public Thing createHero(boolean prompts) {
    long start = System.currentTimeMillis();
    String race = null;
    String profession = null;

    if (!prompts) {
      race = "human";
      profession = "fighter";
      Game.setDebug(true);
    }

    // get list of races
    String[] raceherostrings = Hero.heroRaces();
    String[] racedescriptions = Hero.heroRaceDescriptions();
    if (race == null) {
      DetailedListScreen ls =
          new DetailedListScreen("What race are you?", raceherostrings, racedescriptions);
      ls.setForeground(new Color(128, 128, 128));
      ls.setBackground(new Color(0, 0, 0));
      ls.bottomString = "Press a letter key to select your race";
      switchScreen(ls);
      while (true) {
        race = (String) ls.getObject();
        // Game.warn(race);
        if ((race != null) || Game.isDebug()) break;
      }
    }

    if (race == null) {
      // Debug mode only
      // have escaped, so choose randomly
      race = raceherostrings[Rand.r(raceherostrings.length)];
      String[] herostrings = Hero.heroProfessions(race);
      profession = herostrings[Rand.r(herostrings.length)];
    }

    // get list of possible prfessions
    String[] professionstrings = Hero.heroProfessions(race);
    String[] professiondescriptions = Hero.heroProfessionDescriptions(race);
    if (profession == null) {

      DetailedListScreen ls =
          new DetailedListScreen(
              "What is your profession?", professionstrings, professiondescriptions);
      ls.bottomString = "Press a letter key to select your profession";
      ls.setForeground(new Color(128, 128, 128));
      ls.setBackground(new Color(0, 0, 0));
      switchScreen(ls);

      while (profession == null) {
        profession = (String) ls.getObject();
      }
    }

    Thing h = Hero.createHero(prompts ? null : "QuickTester", race, profession);

    // hero name and history display
    String name = "QuickTester";
    if (prompts) {
      // setup screen to get name
      Screen ss = new Screen(this);
      ss.setBackground(new Color(0, 0, 0));
      ss.setLayout(new BorderLayout());
      {
        InfoScreen ts = new InfoScreen(this, h.getString("HeroHistory"));
        ts.setBackground(new Color(0, 0, 0));
        ss.add("Center", ts);
      }
      MessagePanel mp = new MessagePanel(this);
      Game.messagepanel = mp;
      ss.add("South", mp);

      switchScreen(ss);

      name = getHeroName(true);
      if (name == null) return null;
    }
    Hero.setHeroName(h, name);

    System.out.println((System.currentTimeMillis() - start) + "ms to createHero");
    return h;
  }