Examples of BoardCase


Examples of pdp.scrabble.game.BoardCase

    }

    public void setCaseLetter(
      int vertIndex, int horiIndex, Letter letter, boolean add) {

  BoardCase boardCase = this.getCase(vertIndex, horiIndex);
  boardCase.setLetter(letter);
  boardCase.setState(NEW);
  if (add) {
      this.newCases.add(boardCase);
  }
    }
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

    private void setCaseState(int vertIndex, int horiIndex, BoardCaseState bcs) {
  this.getCase(vertIndex, horiIndex).setState(bcs);
    }

    public void resetCase(int vertIndex, int horiIndex) {
  BoardCase boardCase = this.getCase(vertIndex, horiIndex);
  boardCase.setLetter(null);
  boardCase.setState(FREE);
  boardCase.setAdjacentIgnorence(false);
  boardCase.setChecked(false);
  boardCase.setMultUsed(false);
  boardCase.setIndex(NONE);
    }
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

  int horiTest = newCases.get(0).getH();
  int vertCount = 1, horiCount = 1;

  // Check all cases
  for (int i = 1; i < newCasesNum; i++) {
      BoardCase boardCase = newCases.get(i);
      if (boardCase.getV() == vertTest) {
    vertCount++;
      }
      if (boardCase.getH() == horiTest) {
    horiCount++;
      }
  }

  // One or more are not aligned on the same axis
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

     */
    private void checkWordUnifiedRules(
      List<BoardCase> newCases, int numberOfNewCases, boolean isVert)
    throws BoardWrongWordPlace {

  BoardCase boardCase = null;
  int first = 0, last = 0;
  int firstP = 0, lastP = 0;
  int axis = 0;

  // Get extremity index
  for (int i = 0; i < numberOfNewCases; i++) {
      boardCase = newCases.get(i);
      if (boardCase.getIndex() == FIRST) {
    first = i;
      }
      if (boardCase.getIndex() == LAST) {
    last = i;
      }
  }

  // Check unification
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

     * @throws BoardWrongWordPlace word hit rules violation.
     */
    private void checkWordHitRules(List<BoardCase> newCases, int newCasesNum)
    throws BoardWrongWordPlace {

  BoardCase bCase = null;
  int numberOfHit = 0;

  // Check all cases
  for (int i = 0; i < newCasesNum; i++) {
      bCase = newCases.get(i);

      if (this.caseJoinedTo(bCase.getV(), bCase.getH(), true, OLD)
        || this.caseJoinedTo(bCase.getV(), bCase.getH(), false, OLD)) {

    numberOfHit++;
      }
  }

View Full Code Here

Examples of pdp.scrabble.game.BoardCase

    private void checkWordExistence(
      boolean isVertical, int axis, int first, int last)
    throws BoardWrongWordPlace {

  StringBuilder word = new StringBuilder("");
  BoardCase boardCase = null;
  List<Letter> jokers = new ArrayList<Letter>(1);
  int firstP = first, lastP = last;

  // Get complete word
  if (isVertical) {
      while (this.getCase(firstP - 1, axis).getState() != FREE) {
    firstP--; // Top index
      }
      while (this.getCase(lastP + 1, axis).getState() != FREE) {
    lastP++; // Down index
      }

      // Current word letter
      for (int v = firstP; v <= lastP; v++) {
    Letter letter = this.getCase(v, axis).getLetter();
    word = word.append(letter.getName());
    if (letter.getName() == Bag.JOKER) {
        jokers.add(letter);
    }
      }
  }
  else {
      while (this.getCase(axis, firstP - 1).getState() != FREE) {
    firstP--; // Left index
      }
      while (this.getCase(axis, lastP + 1).getState() != FREE) {
    lastP++; // Right index
      }

      // Current word letter
      for (int h = firstP; h <= lastP; h++) {
    Letter letter = this.getCase(axis, h).getLetter();
    word = word.append(letter.getName());
    if (letter.getName() == Bag.JOKER) {
        jokers.add(letter);
    }
      }
  }

  // Apply joker char to use (if has and found)
  int numOfJoker = jokers.size();
  if (numOfJoker > 0) {
      Character[] joker = this.tryJokers(word);
      jokers.get(0).setJokerChar(joker[0]);
      if (numOfJoker == 2) {
    jokers.get(1).setJokerChar(joker[1]);
      }
      jokers.clear();
      jokers = null;
      joker = null;
  }

  // Check existence
  if (!this.dictionary.contains(word)) {
      if (this.isAI) {
    this.valide = false;
    return;
      }
      else {
    throw new BoardWrongWordPlace(
      "This word doesn't exist:", " " + word);
      }
  }

  // If word exists, calculate points
  int score = this.calculateWordPoints(isVertical, axis, firstP, lastP);
  Debug.console(
    "checkWordExistence", "word = ", word + " | score = " + score);

  this.words.add(word.toString());
  this.points += score;

  // Check now adjacents words (for each word letters)
  if (isVertical) {
      for (int v = firstP; v <= lastP; v++) {
    boardCase = this.getCase(v, axis);

    // Letter has adjacent letters (right or left)
    if (!boardCase.getAdjacentIgnorence() && !boardCase.isChecked()
      && boardCase.getState() == NEW) {

        if (this.getCase(v, axis - 1).getState() == OLD
          || this.getCase(v, axis + 1).getState() == OLD) {

      boardCase.setChecked(true);
      this.checkedCases.add(boardCase);
      this.checkWordExistence(!isVertical, v, axis, axis);
        }
    }
      }
  }
  else {
      for (int h = firstP; h <= lastP; h++) {
    boardCase = this.getCase(axis, h);

    // Letter has adjacent letters (up or down)
    if (!boardCase.getAdjacentIgnorence() && !boardCase.isChecked()
      && boardCase.getState() == NEW) {

        if (this.getCase(axis - 1, h).getState() == OLD
          || this.getCase(axis + 1, h).getState() == OLD) {

      boardCase.setChecked(true);
      this.checkedCases.add(boardCase);
      this.checkWordExistence(!isVertical, h, axis, axis);
        }
    }
      }
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

    private Placement tryWindow(Board board, Player player, boolean center,
        boolean vertical, int axis, int windowSize) {

  Placement best = FACTORY.createPlacement();
  Placement current = null;
  BoardCase boardCase = null;
  int index = 0;
  int boardMax = HORI_DIM;
  if (vertical) {
      boardMax = VERT_DIM;
  }

  // For each cases (vertical or horizontal)
  for (int i = 0; i < boardMax; i++) {

      // Ensure window is not too large
      if (i + windowSize - 1 >= boardMax) {
    break;
      }

      // Ensure window contains at least an old horizontal letter
      boolean ignoreLarge = false, ignoreOld = true, ignoreFree = true;
      boolean ignoreCenter = true;

      if (center) {
    if (i <= boardMax / 2 && (i + windowSize) > boardMax / 2) {
        ignoreCenter = false;
    }
    else {
        continue;
    }
      }

      // Check each window case
      for (int j = 0; j < windowSize; j++) {
    index = i + j;

    if (vertical) {
        boardCase = board.getCase(index, axis);
    }
    else {
        boardCase = board.getCase(axis, index);
    }

    // Search old and free cases
    if (index < boardMax) {

        if (vertical) {
      if (this.hitOldCase(index, axis)) {
          ignoreOld = false;
      }
        }
        else {
      if (this.hitOldCase(axis, index)) {
          ignoreOld = false;
      }
        }

        if (boardCase.getState() == FREE) {
      ignoreFree = false;
        }
    } // Window size too large, can't place word, ignore
    else {
        ignoreLarge = true;
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

    public void paintComponent(Graphics g) {

  // Display board cases
  for (int v = 0; v < VERT_DIM; v++) {
      for (int h = 0; h < HORI_DIM; h++) {
    BoardCase boardCase = this.board.getCase(v, h);
    boardCase.render(g, h * CASE_SIZE, v * CASE_SIZE);

    // Color new cases only
    if (boardCase.getState() == NEW) {
        g.setColor(NEW_CASE_COLOR);
        g.fill3DRect(h * CASE_SIZE, v * CASE_SIZE,
         CASE_SIZE, CASE_SIZE, true);
    }
      }
  }

  // Get mouse data
  if (this.action != null && this.game.engine().getPlayerTurn() != -1) {
      int mx = this.action.getMouseX();
      int my = this.action.getMouseY();
      int dragOffsetX = this.action.getDragOffsetX();
      int dragOffsetY = this.action.getDragOffsetY();
      int dragV = this.action.getDragV();
      int dragH = this.action.getDragH();

      // Display selected case
      if (mx > 0 && my > 0
    && mx < this.getWidth() - 1 && my < this.getHeight() - 1) {
    int x = (mx / CASE_SIZE) * CASE_SIZE;
    int y = (my / CASE_SIZE) * CASE_SIZE;

    g.setColor(SELECTED_CASE_COLOR);
    g.fill3DRect(x, y, CASE_SIZE, CASE_SIZE, true);
      }

      // Display dragging letter
      if (this.action.isDragging()) {
    BoardCase boardCase = this.board.getCase(dragV, dragH);
    if (boardCase.getState() == NEW) {
        boardCase.render(g, mx + dragOffsetX, my + dragOffsetY);
    }
      }
  }
    }
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

    public void paintComponent(Graphics g) {

  // Display board cases
  for (int v = 0; v < VERT_DIM; v++) {
      for (int h = 0; h < HORI_DIM; h++) {
    BoardCase boardCase = this.board.getCase(v, h);
    boardCase.render(g, h * CASE_SIZE, v * CASE_SIZE);

    // Color new cases only
    if (boardCase.getState() == NEW) {
        g.setColor(NEW_CASE_COLOR);
        g.fill3DRect(h * CASE_SIZE, v * CASE_SIZE,
         CASE_SIZE, CASE_SIZE, true);
    }
      }
  }

  // Get mouse data
  if (this.action != null && this.game.engine().getPlayerTurn() != -1) {
      int mx = this.action.getMouseX();
      int my = this.action.getMouseY();
      int dragOffsetX = this.action.getDragOffsetX();
      int dragOffsetY = this.action.getDragOffsetY();
      int dragV = this.action.getDragV();
      int dragH = this.action.getDragH();

      // Display selected case
      if (mx > 0 && my > 0
    && mx < this.getWidth() - 1 && my < this.getHeight() - 1) {
    int x = (mx / CASE_SIZE) * CASE_SIZE;
    int y = (my / CASE_SIZE) * CASE_SIZE;

    g.setColor(SELECTED_CASE_COLOR);
    g.fill3DRect(x, y, CASE_SIZE, CASE_SIZE, true);
      }

      // Display dragging letter
      if (this.action.isDragging()) {
    BoardCase boardCase = this.board.getCase(dragV, dragH);
    if (boardCase.getState() == NEW) {
        boardCase.render(g, mx + dragOffsetX, my + dragOffsetY);
    }
      }
  }
    }
View Full Code Here

Examples of pdp.scrabble.game.BoardCase

  }
    }

    @Override
    public BoardCase clone() {
  BoardCase boardCase = FACTORY.createBoardCase(
    this.getLetterMult(), this.getWordMult(),
    this.getV(), this.getH());

  boardCase.setAdjacentIgnorence(this.ignoreAdjacent);
  boardCase.setChecked(this.checked);
  boardCase.setIndex(this.getIndex());
  boardCase.setMultUsed(this.multUsed);
  boardCase.setState(this.getState());

  Letter l = this.getLetter();
  if (l != null) {
      boardCase.setLetter(l.clone());
  }

  return boardCase;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.