Example #1
0
 /**
  * display all open positions on the board based on the current arrangements of the lake tiles
  *
  * @return text of all lake tile on board
  * @throws ColorNotExistedException when color of lake tile does not exist
  */
 public String getLakeTileBoardText() throws ColorNotExistedException {
   ArrayList<String> index = new ArrayList<String>();
   ArrayList<String> line1 = new ArrayList<String>();
   ArrayList<String> line2 = new ArrayList<String>();
   ArrayList<String> line3 = new ArrayList<String>();
   int[] size = getBoardSize();
   for (int y = size[1]; y <= size[3]; y++) {
     String index_str = new String();
     String line1_str = new String();
     String line2_str = new String();
     String line3_str = new String();
     for (int x = size[0]; x <= size[2]; x++) {
       LakeTile l = lakeTilesOnBoard[x][y];
       if (l == null) {
         index_str += String.format("%11s", "");
         line1_str += String.format("%11s", "");
         line2_str += String.format("%11s", "");
         line3_str += String.format("%11s", "");
       } else {
         index_str += String.format("%2s", l.getIndex());
         index_str += ":";
         index_str += String.format("%-7s", "(" + x + "," + y + ")");
         index_str += " ";
         ArrayList<Color> laketile_colors = new ArrayList<Color>(l.getColorOfFourSides());
         line1_str += "     ";
         line1_str += Color.getColorText(laketile_colors.get(0), Symbol.UP);
         line1_str += "     ";
         line2_str += "   ";
         line2_str += Color.getColorText(laketile_colors.get(3), Symbol.LEFT);
         line2_str += " ";
         if (l.isPlatform()) {
           line2_str += "0 ";
         } else {
           line2_str += "X ";
         }
         line2_str += Color.getColorText(laketile_colors.get(1), Symbol.RIGHT);
         line2_str += "   ";
         line3_str += "     ";
         line3_str += Color.getColorText(laketile_colors.get(2), Symbol.DOWN);
         line3_str += "     ";
       }
     }
     index.add(index_str + "\n");
     line1.add(line1_str + "\n");
     line2.add(line2_str + "\n");
     line3.add(line3_str + "\n");
   }
   String text = new String("");
   for (int i = 0; i < index.size(); i++) {
     text += index.get(i);
     text += line1.get(i);
     text += line2.get(i);
     text += line3.get(i);
   }
   return ":::Lake Tile Board:::\n" + text;
 }
Example #2
0
  /**
   * put the flip lake tile of the game
   *
   * @param players list of players
   */
  private void setUpLakeTile(Queue<Player> players) {
    Random r = new Random();
    int randomRedLantern = r.nextInt(players.size());
    Queue<Color> color = startLakeTile.getColorOfFourSides();
    // change the current player who get red lantern card
    color.add(color.remove());
    for (int i = 0; i < randomRedLantern; i++) {
      players.add(players.remove());
    }
    int current_number_player = 0;
    // add index to player
    for (int i = 0; i < players.size(); i++) {
      Player p = players.remove();
      p.setIndex(i);
      players.add(p);
    }

    for (Color lantern_color : color) {
      if (current_number_player == players.size()) {
        break;
      } else {
        current_number_player++;
      }
      Player p = players.remove();

      p.getLanternCards().add(supply.get(lantern_color).pop());
      players.add(p);
    }
  }