Package com.svanloon.game.wizard.engine

Examples of com.svanloon.game.wizard.engine.WizardEngine


  public void run() {
    //_logger.info("Starting Server");
    int numberOfHumanPlayers = getNumberOfPlayers();

    WizardEngine wizardEngine = new WizardEngine(go);

    Iterator<Player> botsIterator = bots.iterator();

    List<Player> players = new ArrayList<Player>();

    for (GameEventListener listener: listeners) {
      wizardEngine.addGameEventListener(listener);
    }

    for(int totalPlayerNumberIndex = 0 ; totalPlayerNumberIndex < totalNumberOfPlayers; totalPlayerNumberIndex++) {
      //_logger.info("Getting player " + i + "'s information");
      int id = (totalPlayerNumberIndex+1)*21601;
      Player player;
      if((numberOfHumanPlayers == -1) || // computer players play themselves
         (numberOfHumanPlayers == 0 && totalPlayerNumberIndex > 0) || // assumes 1 player + n-1 computers
         (numberOfHumanPlayers == 1 && totalPlayerNumberIndex > 0) ||  // assumes 1 player + n-1 computers
         (numberOfHumanPlayers == 2 &&
             (
               (totalNumberOfPlayers == 3 && totalPlayerNumberIndex == 1) ||
                 (totalNumberOfPlayers == 4 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3)) ||
                 (totalNumberOfPlayers == 5 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3 || totalPlayerNumberIndex == 4)) ||
                 (totalNumberOfPlayers == 6 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3 || totalPlayerNumberIndex == 4 || totalPlayerNumberIndex == 5))
             )
         ) ||
         (numberOfHumanPlayers == 3 &&
             (
                 (totalNumberOfPlayers == 4 && (totalPlayerNumberIndex == 3)) ||
                 (totalNumberOfPlayers == 5 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3)) ||
                 (totalNumberOfPlayers == 6 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3 || totalPlayerNumberIndex == 5))
             )
         ) ||
         (numberOfHumanPlayers == 4 &&
             (
                 (totalNumberOfPlayers == 5 && (totalPlayerNumberIndex == 1)) ||
                 (totalNumberOfPlayers == 6 && (totalPlayerNumberIndex == 1 || totalPlayerNumberIndex == 3))
             )
         ) ||
         (numberOfHumanPlayers == 5 &&
             (
                 (totalNumberOfPlayers == 6 && (totalPlayerNumberIndex == 1 ))
             )
         )
        
       ) {
       
        Player bot;
        if (botsIterator.hasNext()) {
          bot = botsIterator.next();

          if (bot instanceof GameEventListener) {
            wizardEngine.addGameEventListener((GameEventListener) bot );
          }

          player = bot;
        } else {
          _logger.error(NOT_ENOUGH_COMPUTER_PLAYERS);
          throw new IllegalStateException(NOT_ENOUGH_COMPUTER_PLAYERS);
        }
       
      } else if (numberOfHumanPlayers > 1 && totalPlayerNumberIndex > 0) {
        try {
          player = getNetworkPlayer(wizardEngine, totalPlayerNumberIndex, id, go);
        } catch (IOException e) {
          e.printStackTrace();
          return;
        }
      } else {
        player = getLocalPlayer(wizardEngine);
      }
      player.setId(id);
     
      players.add(player);
    }
 
    wizardEngine.addPlayers(players);
   
    Thread t = new Thread(wizardEngine);
    t.setName(WIZARD_ENGINE_THREAD);
    t.start();

    try {
      t.join();
    } catch (Exception e) {
      _logger.error(e);
    }

    game = wizardEngine.getGame();
  }
View Full Code Here

TOP

Related Classes of com.svanloon.game.wizard.engine.WizardEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.