コード例 #1
0
  /**
   * Launch game method is both designed to launch a game, to hand out territories as well as taking
   * care of the game itself and the win scenario
   *
   * @throws InterruptedException
   */
  public void initGame() throws InterruptedException {

    // init of the game by distributing the regions to the players
    // using a LinkedList and random number
    List<Region> listOfRegionsLeft = new LinkedList<Region>();
    int idRegion;

    for (Region regionToDistribute : this.gamingTray.gamingTrayRegions)
      listOfRegionsLeft.add(regionToDistribute);

    while (!(listOfRegionsLeft.isEmpty())) {
      for (Player playerToDistribute : this.getPlayerList()) {
        idRegion = Dice.throwDice(listOfRegionsLeft.size());
        try {
          listOfRegionsLeft.get(idRegion).conquest(playerToDistribute);
          listOfRegionsLeft.remove(idRegion);
        } catch (Exception e) {
          break;
        }
      }
    }

    Window.MAIN_GAMING_WINDOW.getContentPane().repaint();

    // once the Regions have been handed out, we just have to launch the
    // game
    launchGame();
  }
コード例 #2
0
  /**
   * launchGame isn't less than the main turn method which will launch every player turn aswell as
   * taking care of who will be the winner and such
   *
   * @throws InterruptedException
   */
  public void launchGame() throws InterruptedException {

    // first reinforcement and capital choice turn for every players
    for (Player firstTurnOfPlayer : this.playerList) {
      this.setCurrentPlayer(firstTurnOfPlayer);
      firstTurnOfPlayer.reinforcementStep((int) (100 / this.playerList.size()));
      firstTurnOfPlayer.capitalAttribution();
      Window.MAIN_GAMING_WINDOW.getContentPane().repaint();
    }

    // all game turns in there
    while (
    /*this.playersStillAlive() >= 2*/ true) {
      for (Player currentPlayer : this.getPlayerList()) {
        this.setCurrentPlayer(currentPlayer);
        this.print("Tour de : " + currentPlayer.name);
        Window.MAIN_GAMING_WINDOW.getContentPane().repaint();
        currentPlayer.reinforcementStep(currentPlayer.unitReinforcements());
        Window.MAIN_GAMING_WINDOW.getContentPane().repaint();
        currentPlayer.attackStep();
        Window.MAIN_GAMING_WINDOW.getContentPane().repaint();
        currentPlayer.forceMouvementStep();
      }

      // check up of the players to see if one of them is dead (no
      // regions left)
      // for (Player isPlayerDead : this.getPlayerList()) {
      //	if (isPlayerDead.playerRegions().length == 0) isPlayerDead.setDead();
      // }

      // check up of the capitals to see if a player possess them all :
      // if it is the case, the player have won the game
      // for (Player playerToFetchCapitals : this.getPlayerList()) {
      //	if (playerToFetchCapitals.victoryByCapitals()) for (Player playerToSetDead :
      // this.getPlayerList())
      //		playerToSetDead.setDead();
      //	playerToFetchCapitals.setAlive();
      // }
    }

    // print of the name of the player
    // for (Player isPlayerTheWinner : this.getPlayerList())
    //	if (isPlayerTheWinner.isAlive()) this.print("Partie remportée par " +
    // isPlayerTheWinner.name);

  }
コード例 #3
0
  /**
   * Static main that will launch the game after creating the players and the colors : it is also
   * meant to recreate a lost game in case the Serialisation methods find anything on disk
   * unfortunately, it is not working yet
   *
   * @param args
   * @throws FileNotFoundException
   * @throws IOException
   * @throws ClassNotFoundException
   * @throws InterruptedException
   */
  public static void main(String[] args)
      throws FileNotFoundException, IOException, ClassNotFoundException, InterruptedException {

    Window.colorList.add(new Color(150, 110, 80));
    Window.colorList.add(new Color(240, 190, 110));
    Window.colorList.add(new Color(100, 140, 220));
    Window.colorList.add(new Color(40, 50, 110));
    Window.colorList.add(new Color(110, 150, 130));

    // this.serialization(); to be fixed
    Window.MAIN_GAMING_WINDOW.print(
        "Merci d'entrer le nombre de joueurs puis de renseigner leurs pseudos !");
    int numberOfPlayers = 10;

    // creation of all the players using the WIndow JTextInput
    while (numberOfPlayers > Player.MAX_PLAYERS)
      numberOfPlayers = Window.MAIN_GAMING_WINDOW.selectNumber();
    Window.MAIN_GAMING_WINDOW.print("Entrez les pseudo des joueurs à créer :");
    for (int playerArrayCounter = 0; playerArrayCounter < numberOfPlayers; playerArrayCounter++)
      Window.MAIN_GAMING_WINDOW.playerList.add(Window.MAIN_GAMING_WINDOW.createPlayer());

    // once all the players have been set up, we launch the game
    Window.MAIN_GAMING_WINDOW.initGame();
  }
コード例 #4
0
 @Override
 public void actionPerformed(ActionEvent e) {
   Window.MAIN_GAMING_WINDOW.setEnteredText(Window.MAIN_GAMING_WINDOW.getInput().getText());
   Window.MAIN_GAMING_WINDOW.getInput().selectAll();
 }
コード例 #5
0
 /** @param numberToPrint will be printed on the JFrame console */
 public void print(int numberToPrint) {
   Window.MAIN_GAMING_WINDOW.setText(
       Integer.toString(numberToPrint) + "\n" + Window.MAIN_GAMING_WINDOW.getText());
 }
コード例 #6
0
 /** @param textToPrint will be printed on the JFrame console */
 public void print(String textToPrint) {
   Window.MAIN_GAMING_WINDOW.setText(textToPrint + "\n" + Window.MAIN_GAMING_WINDOW.getText());
 }