Ejemplo n.º 1
0
  public WarMain(WarGameSettings settings, String... selectedTeamsName) throws WarCommandException {
    availableTeams = new HashMap<>();

    TeamLoader tl = new TeamLoader();
    // On initialise la liste des équipes existantes dans le dossier "teams"
    availableTeams = tl.loadAllAvailableTeams(true);

    // On vérifie qu'au moins une équipe a été chargée
    if (availableTeams.size() > 0) {
      // On lance le jeu
      this.settings = settings;
      if (selectedTeamsName.length > 1) {
        for (String teamName : selectedTeamsName) {
          if (availableTeams.containsKey(teamName))
            settings.addSelectedTeam(availableTeams.get(teamName));
          else
            throw new WarCommandException(
                "InGameTeam \""
                    + teamName
                    + "\" does not exists. Available teams are : "
                    + availableTeams.keySet());
        }
      } else {
        throw new WarCommandException(
            "Please select at least two teams. Available teams are : " + availableTeams.keySet());
      }
      start();
    } else {
      throw new WarCommandException("Not team found in folder \"" + TEAMS_DIRECTORY_NAME + "\"");
    }
  }
Ejemplo n.º 2
0
 @Override
 public void onGameStopped() {
   gdxFrame.setExtendedState(JFrame.ICONIFIED);
   //    	gdxFrame.setVisible(false);
   for (int i = 0; i < game.getAllTeams().size(); ++i) {
     game.getAllTeams().get(i).removeAllAgents();
   }
   game.getPlayerTeams().clear();
   settings.prepareForNewGame();
   logger.log(Level.INFO, "Reset settings");
   launcherInterface.setVisible(true);
   launcherInterface.revalidate();
   launcherInterface.repaint();
 }
Ejemplo n.º 3
0
 @Override
 public void onGameStarted() {
   loadingDialog.setVisible(false);
   if (settings.isEnabledEnhancedGraphism()) gdxFrame.setExtendedState(JFrame.NORMAL);
   //        	gdxFrame.setVisible(true);
 }
Ejemplo n.º 4
0
  private static void commandLine(String[] args) throws WarCommandException {

    WarGameSettings settings = new WarGameSettings();
    ArrayList<String> selectedTeams = new ArrayList<>();

    WarbotOptions wo = new WarbotOptions();

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine line = parser.parse(wo, args);
      if (line.hasOption(WarbotOptions.HELP)) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("warbot", wo);
        return;
      }
      if (line.hasOption(WarbotOptions.GAMEMODE)) {
        try {
          logger.info("Setting mode in : " + line.getOptionValue(WarbotOptions.GAMEMODE));
          WarGameMode gameMode = WarGameMode.valueOf(line.getOptionValue(WarbotOptions.GAMEMODE));
          settings.setGameMode(gameMode);
        } catch (IllegalArgumentException e) {
          throw new WarCommandException(
              "Unknown game mode : " + line.getOptionValue(WarbotOptions.GAMEMODE));
        }
      }
      if (line.hasOption("l")) {
        try {
          settings.setDefaultLogLevel(Level.parse(line.getOptionValue("l")));
        } catch (IllegalArgumentException e) {
          throw new WarCommandException("Invalid log level : " + line.getOptionValue("l"));
        }
      }

      if (line.hasOption("nb")) {

        String[] values = line.getOptionValues("nb");
        for (int i = 0; i < values.length; i += 2) {
          logger.info(values[i].toString() + ":" + values[i + 1].toString());
          try {
            WarAgentType wat = WarAgentType.valueOf(values[i]);
            int nb = Integer.parseInt(values[i + 1]);
            settings.setNbAgentOfType(wat, nb);
          } catch (IllegalArgumentException e) {
            throw new WarCommandException("Error when parsing " + values);
          }
        }
      }

      if (line.hasOption("t")) {
        String[] values = line.getOptionValues("t");
        for (int i = 0; i < values.length; ++i) {
          selectedTeams.add(values[i]);
        }
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
    new WarMain(settings, selectedTeams.toArray(new String[] {}));
  }