Example #1
0
  private static ArrayList<Word> getWordsOnBoard(GameBoard gameBoard) {
    ArrayList<Word> wordsOnBoard = new ArrayList<>(50);
    StringBuilder stringBuilder;
    Coordinate coord;
    Word word;

    // find words
    // could this be expressed more concisely?
    // cause it's sort of a bear. but also sort of awesome?
    for (int a = 0; a < 2; a++) {
      for (int i = 0; i < 15; i++) {
        for (int j = 0; j < 15; j++) {
          coord = a == 0 ? new Coordinate(j, i) : new Coordinate(i, j);
          BoardCell boardCell = gameBoard.getCellAt(coord);
          while (!boardCell.isEmpty()) { // catch the first letter
            Coordinate head = coord;
            stringBuilder = new StringBuilder(15);
            do {
              stringBuilder.append(boardCell.getTile().getCharacter()); // add a letter
              coord = a == 0 ? new Coordinate(++j, i) : new Coordinate(i, ++j); // the next tile
              if (gameBoard.getCellAt(coord).isEmpty()) { // if the next tile is empty we're done
                if (stringBuilder.length() > 1) { // one letter does not a word make
                  word = new Word(head, a == 0, stringBuilder.toString());
                  wordsOnBoard.add(word);
                }
              }
              boardCell = gameBoard.getCellAt(coord);
            } while (!gameBoard.getCellAt(coord).isEmpty());
          }
        }
      }
    }
    return wordsOnBoard;
  }
Example #2
0
  public void nextPlayer(BottomButtons bb, TopButtons tb) {
    //		p[currentPlayerIndex];
    // if it is human players turn and humanTurnWasMade = false
    if (!humanTurnWasMade && currentPlayerIndex == humanPlayerIndex) {
      clueGame.invalidNeedToFinishTurn();
      return;
    }
    humanTurnWasMade = false;
    System.out.println("before incrementing = " + currentPlayerIndex);
    currentPlayerIndex = (currentPlayerIndex + 1) % 6;
    System.out.println("after incrementing = " + currentPlayerIndex);
    // if player turn and not clicked display error and return

    // set dice view
    Random n = new Random(System.currentTimeMillis());
    int dice = n.nextInt(6) + 1;
    BottomButtons.diceNum = dice;
    diceNum = dice;
    System.out.println(dice + "");
    bb.setDice(dice);

    // if currentPlayer is a human player then show move spaces
    if (currentPlayerIndex == humanPlayerIndex) {
      System.out.println("setting human turn");
      humanTurn = true;
    } else {
      Player p[] = new Player[6];
      players.toArray(p);
      Player a = p[currentPlayerIndex];
      BoardCell b = a.pickLocation(getTargets(a.index, dice));
      a.index = calcIndex(b.row, b.col);
      BoardCell bc = getCellAt((a.index));
      if (bc.isDoorway()) {
        Player[] thePlayers = new Player[6];
        players.toArray(thePlayers);
        System.out.println("------------------------------in room");
        clueGame.showSuggestionPanel(rooms.get(bc.getRooomName()), thePlayers[currentPlayerIndex]);
      }
    }
    this.updateUI();
    // print whose turn
    Player p[] = new Player[6];
    players.toArray(p);
    tb.setPlayersName(p[currentPlayerIndex].name);
  }
Example #3
0
  @Override
  protected void paintComponent(Graphics g) {
    // TODO Auto-generated method stub
    super.paintComponent(g);
    for (BoardCell bc : cells) {
      bc.draw(g, this);
    }
    g.setColor(Color.white);
    g.drawString("Conservatory", 20, 40);
    g.drawString("Ballroom", 60, 200);
    g.drawString("Kitchen", 60, 380);
    g.drawString("Billiard Room", 160, 60);
    g.drawString("Library", 280, 60);
    g.drawString("Study", 400, 60);
    g.drawString("Hall", 400, 200);
    g.drawString("Dining Room", 200, 360);
    g.drawString("Lounge", 400, 360);
    for (Player cp : players) {
      g.setColor(cp.color);
      g.fillOval(cells.get(cp.index).col * 20, cells.get(cp.index).row * 20, 20, 20);
      g.setColor(Color.BLACK);
      g.drawOval(cells.get(cp.index).col * 20, cells.get(cp.index).row * 20, 20, 20);
    }
    System.out.println("want to pring locations");
    System.out.println(humanPlayerIndex);
    System.out.println(currentPlayerIndex);

    if (humanPlayerIndex == currentPlayerIndex && !humanTurnWasMade) {

      Player p[] = new Player[6];
      players.toArray(p);
      int index = p[currentPlayerIndex].index;
      System.out.println("index is " + index);
      Set<BoardCell> drawLocations = getTargets(index, diceNum);
      moveLocations = drawLocations;
      System.out.println("drawLocation size" + drawLocations.size());
      for (BoardCell c : drawLocations) {
        g.setColor(Color.cyan);
        g.fillRect(20 * c.col, 20 * c.row, 20, 20);
        System.out.println("draw a location");
      }
    }

    // draw player locations
  }
Example #4
0
    @Override
    public void mouseReleased(MouseEvent e) {
      // TODO Auto-generated method stub
      if (!humanTurnWasMade) {
        humanTurnWasMade = true;
        if (e.getX() == x && e.getY() == y && currentPlayerIndex == humanPlayerIndex) {
          int xCell = x / 20;
          int yCell = y / 20;
          boolean foundCell = false;
          for (BoardCell bc : moveLocations) {
            if (bc.col == xCell && bc.row == yCell) {
              System.out.println("you win");
              foundCell = true;
              you.index = calcIndex(yCell, xCell);
              repaint();
              // show what room your in
              if (bc.isDoorway()) {
                Player[] thePlayers = new Player[6];
                players.toArray(thePlayers);
                System.out.println("------------------------------in room");
                clueGame.showSuggestionPanel(
                    rooms.get(bc.getRooomName()), thePlayers[currentPlayerIndex]);
              }
              return;
            }
          }
          if (!foundCell) {

            clueGame.invalidMoveClick();
            humanTurnWasMade = false;
          }

          System.out.println("xCell = " + xCell);
          System.out.println("yCell = " + yCell);
        }
      }
    }
Example #5
0
 @Override
 public String toString() {
   String header = "    A   B   C   D   E   F   G   H   I   J   K   L   M   N   O\n";
   String row = "  |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|";
   StringBuilder sb = new StringBuilder(header);
   sb.append(row);
   sb.append('\n');
   for (int i = 0; i < 15; i++) {
     Integer y = i + 1;
     sb.append(y);
     sb.append(i < 9 ? " |" : "|");
     for (int j = 0; j < 15; j++) {
       BoardCell bc = boardCells[i][j];
       if (i == 7 && j == 7 && bc.isEmpty()) {
         sb.append(" * |");
         continue;
       }
       if (bc.isEmpty()) {
         switch (bc.getMultiplier()) {
           case 1:
             sb.append("   |");
             break;
           case 2:
             sb.append(bc.isWordMultiplier() ? "DW |" : "DL |");
             break;
           case 3:
             sb.append(bc.isWordMultiplier() ? "TW |" : "TL |");
             break;
         }
       } else {
         sb.append(bc.getTile().toString());
         sb.append(bc.getTile().toString().length() == 2 ? " |" : "|");
       }
     }
     sb.append(y);
     sb.append('\n');
     sb.append(row);
     sb.append('\n');
   }
   sb.append(header);
   return sb.toString();
 }
Example #6
0
  public LinkedList<Integer> getAdjList(int i) {
    if (adjacencies.containsKey(i)) {
      return adjacencies.get(i);
    }

    LinkedList<Integer> neighbors = new LinkedList<Integer>();
    int column = i % numColumns;
    int row = i / numColumns;
    BoardCell adj;
    BoardCell cell = getCellAt(i);

    adjacencies.put(i, neighbors);

    if (cell.isRoom()) {
      // only midget doorways have adjacencies, and they only have one arm, so short-circuit

      // if a door was placed facing an edge, this would be invalid, but the board should not be set
      // up that way
      if (cell.isDoorway()) {
        switch (((RoomCell) cell).getDoorDirection()) {
          case RIGHT:
            neighbors.add(i + 1);
            break;
          case LEFT:
            neighbors.add(i - 1);
            break;
          case UP:
            neighbors.add(i - numColumns);
            break;
          case DOWN:
            neighbors.add(i + numColumns);
            break;
        }
      }
      return neighbors;
    }

    if (column > 0) {
      adj = getCellAt(i - 1); // the cell to the left

      if (adj.isWalkway()
          || (adj.isDoorway() && ((RoomCell) adj).getDoorDirection() == DoorDirection.RIGHT)) {
        neighbors.add(i - 1);
      }
    }

    if (column < numColumns - 1) {
      adj = getCellAt(i + 1); // the cell to the right

      if (adj.isWalkway()
          || (adj.isDoorway() && ((RoomCell) adj).getDoorDirection() == DoorDirection.LEFT)) {
        neighbors.add(i + 1);
      }
    }

    if (row > 0) {
      adj = getCellAt(i - numColumns); // the cell above

      if (adj.isWalkway()
          || (adj.isDoorway() && ((RoomCell) adj).getDoorDirection() == DoorDirection.DOWN)) {
        neighbors.add(i - numColumns);
      }
    }

    if (row < numRows - 1) {
      adj = getCellAt(i + numColumns); // the cell below

      if (adj.isWalkway()
          || (adj.isDoorway() && ((RoomCell) adj).getDoorDirection() == DoorDirection.UP)) {
        neighbors.add(i + numColumns);
      }
    }

    return neighbors;
  }