예제 #1
0
  @Override
  public synchronized boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    GameState other = (GameState) obj;
    if (backBuffer == null) {
      if (other.backBuffer != null) return false;
    } else if (!backBuffer.equals(other.backBuffer)) return false;
    if (epoch != other.epoch) return false;
    if (frontBuffer == null) {
      if (other.frontBuffer != null) return false;
    } else if (!frontBuffer.equals(other.frontBuffer)) return false;
    if (successfulExits != other.successfulExits) return false;
    if (unsuccessfulExits != other.unsuccessfulExits) return false;

    // Compare frontBuffer
    Map<Character, Plane> o = other.getFrontBuffer();
    if (frontBuffer.size() != o.size()) return (false);
    Iterator<Character> it = frontBuffer.keySet().iterator();
    Iterator<Character> it2 = o.keySet().iterator();
    char c1, c2;
    while (it.hasNext()) {
      c1 = it.next();
      c2 = it2.next();
      if (c1 != c2 || !frontBuffer.get(c1).equals(o.get(c2))) return (false);
    }

    // Compare backBuffer
    o = other.getBackBuffer();
    if (backBuffer.size() != o.size()) return (false);
    it = backBuffer.keySet().iterator();
    it2 = o.keySet().iterator();
    while (it.hasNext()) {
      c1 = it.next().charValue();
      c2 = it2.next().charValue();
      if (c1 != c2 || !backBuffer.get(c1).equals(o.get(c2))) return (false);
    }

    // Compare board
    Board b = other.getBoard();
    if (b.getHeight() != board.getHeight()
        || b.getWidth() != board.getWidth()
        || b.getPorts().size() != board.getPorts().size()) return (false);
    it = board.getPorts().keySet().iterator();
    it2 = b.getPorts().keySet().iterator();
    while (it.hasNext()) {
      c1 = it.next().charValue();
      c2 = it.next().charValue();
      if (c1 != c2 || !b.getPorts().get(c1).equals(board.getPorts().get(c2))) return (false);
    }

    return true;
  }
예제 #2
0
  public synchronized NewPlane createRandomPlane() {
    // Get an ID
    Random rand = new Random();
    Character id = 'A';
    int roll = rand.nextInt(26);
    for (int i = 0; i <= roll || frontBuffer.containsKey(id); i++, id++) ;

    // Get an exit gate
    Gate eg =
        board
            .getPorts()
            .values()
            .toArray(new Gate[26])[rand.nextInt(board.getPorts().size())]
            .clone();

    // Get an entrance gate
    Gate ge;
    do
      ge =
          board
              .getPorts()
              .values()
              .toArray(new Gate[26])[rand.nextInt(board.getPorts().size())]
              .clone();
    while (ge.getSymbol() == eg.getSymbol());

    // Exit altitude
    int ea = rand.nextInt(9000);
    if (ea < 4000) ea = 3000;
    else ea = 7000;

    // Altitude
    int al = rand.nextInt(9000);
    if (al < 2667) al = 1000;
    else if (al < 5333) al = 5000;
    else al = 9000;

    // Set direction
    int di = 1;
    if (ge.getxCoord() == 0 && ge.getyCoord() == 0) di = 4;
    else if (ge.getxCoord() == 0 && ge.getyCoord() == board.getHeight() - 1) di = 2;
    else if (ge.getxCoord() == board.getWidth() - 1 && ge.getyCoord() == 0) di = 7;
    else if (ge.getxCoord() == board.getWidth() - 1 && ge.getyCoord() == board.getHeight() - 1)
      di = 9;
    else if (ge.getxCoord() == 0) di = 3;
    else if (ge.getxCoord() == board.getWidth() - 1) di = 8;
    else if (ge.getyCoord() == 0) di = 6;
    else if (ge.getyCoord() == board.getHeight() - 1) di = 1;

    // Return the new plane
    return (new NewPlane(ge.getSymbol(), eg.getSymbol(), di, ea, al));
  }
예제 #3
0
  public void setZoom(float i) {
    if (i < minZoom || i > 2.5F) return;
    int x_center, y_center;
    if (board.getLastMovew() != null) {
      x_center = board.getLastMovew().getColumn();
      y_center = board.getLastMovew().getRow();
    } else {
      x_center = (int) (position_x / (float) CELL_WIDTH + (getWidth() / (float) CELL_WIDTH) / 2);
      y_center = (int) (position_y / (float) CELL_HEIGHT + (getHeight() / (float) CELL_HEIGHT) / 2);
    }

    zoom = i;
    CELL_WIDTH = (int) (CELL_WIDTH_DEFAUTL * zoom);
    CELL_HEIGHT = (int) (CELL_HEIGHT_DEFAUTL * zoom);
    PIECE_WIDTH = (int) (PIECE_WIDTH_DEFAUTL * zoom);
    PIECE_HEIGHT = (int) (PIECE_HEIGHT_DEFAUTL * zoom);

    position_x = (int) ((x_center + 0.5F - (getWidth() / (float) CELL_WIDTH) / 2) * CELL_WIDTH);
    position_y = (int) ((y_center + 0.5F - (getHeight() / (float) CELL_HEIGHT) / 2) * CELL_HEIGHT);

    position_x = (position_x < 0) ? 0 : position_x;
    position_y = (position_y < 0) ? 0 : position_y;
    if (board.getWidth() * CELL_WIDTH <= getWidth()
        || board.getHeight() * CELL_HEIGHT <= getHeight()) {
      position_x = position_y = 0;
    }
    getbitbap();
    update();
  }
예제 #4
0
 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
   minZoom =
       Math.min(
           (getWidth() / (float) board.getWidth()) / (float) CELL_WIDTH_DEFAUTL,
           (getHeight() / (float) board.getHeight()) / (float) CELL_HEIGHT_DEFAUTL);
   super.onSizeChanged(w, h, oldw, oldh);
 }
예제 #5
0
  public BoardUI(Context c, final Board board) {
    super(c);
    this.board = board;

    /////////////////////////////////////////////
    this.listeners = new ArrayList<MoveListener>();

    minZoom =
        Math.min(
            (getWidth() / (float) board.getWidth()) / (float) CELL_WIDTH_DEFAUTL,
            (getHeight() / (float) board.getHeight()) / (float) CELL_HEIGHT_DEFAUTL);
    setZoom(1.5F);
    position_x = (board.getWidth() * CELL_WIDTH / 2 - getWidth()) / 2;
    position_y = (board.getHeight() * CELL_HEIGHT / 2 - getHeight()) / 2;
    getCol();
    update();
  }
  /**
   * Die Anzahl der Sterne für die Zeile werden hier zurückgegeben
   *
   * @param iY - Hier wird die Positon des Feldes auf der Zeile angegeben
   * @param isMedium - Hier wird angegeben ob die Schwirigkeit mittel ist
   * @return stars - Die anzahl der ausgerechneten Sterne für die Zeile wird hier zurückgegeben
   */
  public int getCalculatedRowStars(int iY, boolean isMedium) {
    int stars = _oBoard.getCountStarsForRow(iY);
    if (isMedium) {
      for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
        if (_tmpDiff[iY][iX] == eStatesDiff.ISSTAR) {
          stars--;
        }
      }
    }

    return stars;
  }
  /**
   * Gibt an ob das Board gelöst ist
   *
   * @return solved - Enthält den Status ob das Editor Board gelöst ist
   */
  public boolean isSolved() {
    boolean solved = true;
    for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
      for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
        if (_tmpDiff[iY][iX] != eStatesDiff.BLOCKED && _tmpDiff[iY][iX] != eStatesDiff.ISSTAR) {
          return false;
        }
      }
    }

    return solved;
  }
예제 #8
0
파일: GameView.java 프로젝트: avh4/xmlvm
  /**
   * Displays the given game board.
   *
   * @param board The board to display.
   */
  public void displayBoard(Board board) {
    int width = board.getWidth();
    int height = board.getHeight();
    int tileSize = determineTileSize(width, height);

    offsetTop = (boardView.getHeight() - (height * tileSize)) / 2;
    offsetLeft = (boardView.getWidth() - (width * tileSize)) / 2;

    // Start with an empty display.
    boardView.removeAllViews();

    Ball ball;
    Goal goal;
    Man man;

    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        switch (board.getBoardPiece(x, y)) {
          case Board.GOAL:
            goal = new Goal(this, tileSize, x, y);
            gameController.addGoal(goal);
            break;
          case Board.BALL:
            ball = new Ball(this, tileSize, x, y);
            gameController.addBall(ball);
            break;
          case Board.BALL_IN_GOAL:
            goal = new Goal(this, tileSize, x, y);
            gameController.addGoal(goal);
            ball = new Ball(this, tileSize, x, y);
            gameController.addBall(ball);
            break;
          case Board.MAN:
            man = new Man(this, tileSize, x, y);
            gameController.setMan(man);
            break;
          case Board.MAN_ON_GOAL:
            goal = new Goal(this, tileSize, x, y);
            gameController.addGoal(goal);
            man = new Man(this, tileSize, x, y);
            gameController.setMan(man);
            break;
          case Board.WALL:
            new Wall(this, tileSize, x, y);
            break;
        }
        if (board.isFloor(x, y)) {
          new Floor(this, tileSize, x, y);
        }
      }
    }
  }
  /** Die Sterne die unlösbar sind werden hier in eine HashMap eingetragen */
  public void calculatedUnsolvableStars() {
    HashMap<Integer, Integer> unsolvableStar = null;
    _unsolvableStars = new HashMap<Integer, HashMap<Integer, Integer>>();

    for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
      for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
        unsolvableStar = new HashMap<Integer, Integer>();
        Field oField = _oBoard.getField(iY, iX);
        if (oField.getState() == eStates.STAR && _tmpDiff[iY][iX] != eStatesDiff.ISSTAR) {
          unsolvableStar.put(iY, iX);
          _unsolvableStars.put(_unsolvableStars.size(), unsolvableStar);
        }
      }
    }
  }
예제 #10
0
  /**
   * Constructs a new GUI minesweeper board. This constructor requires your own Board class that
   * you've been working on, and it will render the arrays in that class on the screen.
   *
   * @param board A board object to display.
   */
  public MsGUI(Board board) {
    super("Minesweeper");
    this.board = board;
    this.isEnabled = true;

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(board.getWidth() * BUTTON_SIZE, board.getHeight() * BUTTON_SIZE);

    gamePanel = new JPanel(new GridLayout(board.getHeight(), board.getWidth()));
    buttons = new JButton[board.getHeight()][board.getWidth()];

    for (int col = 0; col < board.getHeight(); col++) {
      for (int row = 0; row < board.getWidth(); row++) {
        JButton b = new JButton("" + board.getValue(row, col));
        b.setBackground(new Color(200, 200, 200));
        b.addMouseListener(new MineSquareListener(row, col));
        buttons[row][col] = b;
        gamePanel.add(b);
      }
    }

    this.add(gamePanel);
    this.setVisible(true);
  }
예제 #11
0
  /** Draws the game */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */
    for (int row = 0; row < board.getHeight(); row++) {
      for (int column = 0; column < board.getWidth(); column++) {
        if (board.getSquareType(row, column) != SquareType.OUTSIDE) {
          Shape tetrominoBlock =
              new RoundRectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        } else {
          Shape tetrominoBlock =
              new Rectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        }
      }
    }

    Poly tempPoly = board.getFalling();
    if (tempPoly != null) {

      for (int row = 0; row < tempPoly.getSize(); row++) {
        for (int column = 0; column < tempPoly.getSize(); column++) {
          if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) {
            Shape tetrominoBlock =
                new RoundRectangle2D.Double(
                    (column + board.getFallingPosX()) * SQUARE_WIDTH,
                    (row + board.getFallingPosY()) * SQUARE_HEIGHT,
                    SQUARE_WIDTH,
                    SQUARE_HEIGHT,
                    5,
                    5);
            g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column)));
            g2.fill(tetrominoBlock);
            g2.draw(tetrominoBlock);
          }
        }
      }
    }
  }
예제 #12
0
 /**
  * Take a single step of the simulation. This is done by walking through each cell and calculating
  * its new state by applying the rules in their order until either one applies and yields a new
  * state, or not apply (hence, the original state is retained).
  */
 public void step() {
   int width = board.getWidth();
   int height = board.getHeight();
   // nCells holds the updated state for each cell on the board.
   int[] nCells = new int[width * height];
   /*
    * Now visit each cell and compute it's updated cell. Note that we don't update the board
    * yet. This is to prevent one cell from seeing the updated state of another cell in the
    * same step.
    */
   for (int x = 0; x < width; ++x) {
     for (int y = 0; y < height; ++y) {
       nCells[(y * width) + x] = board.getCellState(x, y);
       Point p = new Point(x, y);
       for (Rule r : rules) {
         // Apply the rule
         Integer result = r.apply(new Pair<Point, Board>(p, board));
         if (result != null && result >= 0 && result <= 9) {
           /*
            * Yes, the rule was successfully applied. Therefore, update the cell's
            * state and move onto the next cell.
            */
           nCells[(y * width) + x] = result;
           break;
         }
       }
     }
   }
   // Finally, go through and update each cell on the board with its new state.
   for (int x = 0; x < width; ++x) {
     for (int y = 0; y < height; ++y) {
       int nState = nCells[(y * width) + x];
       board.setCellState(x, y, nState);
     }
   }
 }
예제 #13
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      LastTouch.x = (int) event.getX();
      LastTouch.y = (int) event.getY();

      float x = LastTouch.x + position_x - LEFT_MARGIN;
      float y = LastTouch.y + position_y - TOP_MARGIN;
      celltouch.x = (int) (x / CELL_WIDTH);
      celltouch.y = (int) (y / CELL_WIDTH);
      mButtonPressed = true;
      update();
    }
    if (event.getAction() == MotionEvent.ACTION_MOVE) {
      final float x = event.getX() + position_x - LEFT_MARGIN;
      final float y = event.getY() + position_y - TOP_MARGIN;
      if ((int) (x / CELL_WIDTH) == (int) ((LastTouch.x + position_x - LEFT_MARGIN) / CELL_WIDTH)
          && (int) (y / CELL_HEIGHT)
              == (int) ((LastTouch.y + position_y - TOP_MARGIN) / CELL_HEIGHT)
          && mButtonPressed == true) {
        return true;
      }
      mButtonPressed = false;
      // Calculate the distance moved
      final float dx = event.getX() - LastTouch.x;
      final float dy = event.getY() - LastTouch.y;

      // Move
      position_x -= dx;
      position_y -= dy;

      // Remember this touch position for the next move event
      LastTouch.x = (int) event.getX();
      LastTouch.y = (int) event.getY();

      position_x = (position_x < 0) ? 0 : position_x;
      position_y = (position_y < 0) ? 0 : position_y;

      position_x =
          (position_x + getWidth() > board.getWidth() * CELL_WIDTH - LEFT_MARGIN)
              ? (board.getWidth() * CELL_WIDTH + LEFT_MARGIN * 2 - getWidth())
              : position_x;
      position_y =
          (position_y + getHeight() > board.getHeight() * CELL_HEIGHT - TOP_MARGIN)
              ? (board.getHeight() * CELL_HEIGHT + TOP_MARGIN * 2 - getHeight())
              : position_y;

      position_x = (getWidth() > board.getWidth() * CELL_WIDTH - LEFT_MARGIN) ? 0 : position_x;
      position_y = (getHeight() > board.getHeight() * CELL_HEIGHT - TOP_MARGIN) ? 0 : position_y;

      update();
      return true;
    }
    if (event.getAction() == MotionEvent.ACTION_UP) {
      if (mButtonPressed == false) return true;
      mButtonPressed = false;
      update();
      if (celltouch.x >= board.getWidth() || celltouch.y >= board.getHeight()) return true;
      fireMoveMade(new Move(celltouch.y, celltouch.x, board.getCurrentPiece()));
      return super.onTouchEvent(event);
    }
    return super.onTouchEvent(event);
  }
  public boolean isArrowPointingAtField(int yPos, int xPos) {
    int adder = 0;
    // is there a north arrow pointing at me?
    for (int iY = yPos + 1; iY < _oBoard.getHeight(); iY++) {
      if (_oBoard.getField(iY, xPos).getState() == eStates.ARROW_N) {
        return true;
      }
    }

    // is there a south arrow pointing at me?
    for (int iY = 0; iY < yPos; iY++) {
      if (_oBoard.getField(iY, xPos).getState() == eStates.ARROW_S) {
        return true;
      }
    }

    // is there a west arrow pointing at me?
    for (int iX = xPos + 1; iX < _oBoard.getWidth(); iX++) {
      if (_oBoard.getField(yPos, iX).getState() == eStates.ARROW_W) {
        return true;
      }
    }

    // is there a east arrow pointing at me?
    for (int iX = 0; iX < xPos; iX++) {
      if (_oBoard.getField(yPos, iX).getState() == eStates.ARROW_E) {
        return true;
      }
    }

    // is there a northeast arrow pointing at me?
    adder = 1;
    while (((yPos - adder) >= 0) && ((xPos + adder) < _oBoard.getWidth())) {
      if (_oBoard.getField((yPos - adder), (xPos + adder)).getState() == eStates.ARROW_SW) {
        return true;
      }
      adder++;
    }

    // is there a southeast arrow pointing at me?
    adder = 1;
    while (((yPos + adder) < _oBoard.getHeight()) && ((xPos + adder) < _oBoard.getWidth())) {
      if (_oBoard.getField((yPos + adder), (xPos + adder)).getState() == eStates.ARROW_NW) {
        return true;
      }
      adder++;
    }

    // is there a northwest arrow pointing at me?
    adder = 1;
    while (((yPos - adder) >= 0) && ((xPos - adder) >= 0)) {
      if (_oBoard.getField((yPos - adder), (xPos - adder)).getState() == eStates.ARROW_SE) {
        return true;
      }
      adder++;
    }

    // is there a southwest arrow pointing at me?
    adder = 1;
    while (((yPos + adder) < _oBoard.getHeight()) && ((xPos - adder) >= 0)) {
      if (_oBoard.getField((yPos + adder), (xPos - adder)).getState() == eStates.ARROW_NE) {
        return true;
      }
      adder++;
    }

    return false;
  }
예제 #15
0
  /**
   * Handles the events for keypresses
   *
   * @param e the pressed key
   */
  public void keyPressed(KeyEvent e) {
    if (activePentomino != null) {
      // Keys for moveing the pentomino sideways
      if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
        // Initialize direction to 0 to make sure we don't get null pointer exception
        // or do something weird with the movement
        int direction = 0;
        if (e.getKeyCode() == KeyEvent.VK_LEFT) direction = -1;
        if (e.getKeyCode() == KeyEvent.VK_RIGHT) direction = 1;
        // +1 right, -1 left

        // Check if we are allowed to actually move the pentomino to the new position
        boolean legalMove = true;
        for (Point p : activePentomino.getLocation()) {
          int newX = (int) (p.getX() + pentominoLocation.getX() + direction);
          int newY = (int) (p.getY() + pentominoLocation.getY());

          // Check only if the pentomino is not above the board
          if (newY >= 0) {
            // Check that we are horizontally within the board and not trying to overlap another
            // piece
            if (newX < 0
                || newX >= gameBoard.getBoard().length
                || gameBoard.getBoard()[newX][newY] != -1) legalMove = false;
          }
        }
        // Check passed so we do the actual movement of the pentomino
        if (legalMove) {
          pentominoLocation.setLocation(
              (pentominoLocation.getX() + direction), pentominoLocation.getY());
          predictDrop();
          updateMatrix();
        }
      }

      // Key for rotating the pentomino
      if (e.getKeyCode() == KeyEvent.VK_UP) {
        // Create a temporary pentomino to check if the rotated position free
        Pentomino tmpPentomino = activePentomino.copy();
        tmpPentomino.rotate();
        boolean legalMove = true;
        // For reach block of the position check that it's free and within the grid
        // ignoring the check if we're above the grid
        for (Point p : tmpPentomino.getLocation()) {
          int newX = (int) (p.getX() + pentominoLocation.getX());
          int newY = (int) (p.getY() + pentominoLocation.getY());
          if (newY > 0) {
            if (newY >= gameBoard.getBoard()[0].length
                || newX < 0
                || newX >= gameBoard.getBoard().length
                || gameBoard.getBoard()[newX][newY] != -1) {
              legalMove = false;
            }
          }
        }
        // If the check passed then simply do the rotation
        if (legalMove) {
          activePentomino.rotate();
          predictDrop();
        }
        // Update the matrix so we don't have lag in display
        updateMatrix();
      }

      // Key for speeding up the fall
      if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        // If next position is available, put the current pentomino to it
        if (nextDropLegal(activePentomino, gameBoard.getBoard(), pentominoLocation)) {
          pentominoLocation.setLocation(pentominoLocation.getX(), pentominoLocation.getY() + 1);
        }
        // Update to avoid lag
        updateMatrix();
      }

      // Key for entirely dropping the pentomino
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        // We make the pentomino fall as many times as it can
        while (nextDropLegal(activePentomino, gameBoard.getBoard(), pentominoLocation)) {
          pentominoLocation.setLocation(pentominoLocation.getX(), pentominoLocation.getY() + 1);
        }
        // Update to avoid lag
        updateMatrix();
      }

      // Key for flipping the pentomino
      if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        // Create a temporary pentomino for checking the flipped position
        Pentomino tmpPentomino = activePentomino.copy();
        tmpPentomino.reflect();
        // Check that each position in the temporary pentomino is available and within the matrix
        boolean legalMove = true;
        for (Point p : tmpPentomino.getLocation()) {
          int newX = (int) (p.getX() + pentominoLocation.getX());
          int newY = (int) (p.getY() + pentominoLocation.getY());
          if (newY < 0
              || newY >= gameBoard.getBoard()[0].length
              || newX < 0
              || newX >= gameBoard.getBoard().length
              || gameBoard.getBoard()[newX][newY] != -1) {
            legalMove = false;
          }
        }
        // Flip the pentomino if check is passed
        if (legalMove) {
          activePentomino.reflect();
          predictDrop();
        }
        // Update to avoid lag
        updateMatrix();
      }

      // Key for storing the currently falling pentomino
      if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
        // If we haven't stored after fixing the pentomino to the grid
        if (storageable) {
          // Change the active and stored pentomino and set the location to the top of the screen
          pentominoLocation = new Point(gameBoard.getWidth() / 2, 0);
          Pentomino tmp = activePentomino;
          activePentomino = storagedPentomino;
          storagedPentomino = tmp;
          storageable = false;
          // Get new prediction
          predictDrop();
          // Update to avoid lag
          updateMatrix();
        }
      }

      // Key for a chect for testing purposes
      if (e.getKeyCode() == KeyEvent.VK_X) {
        // If pressed enough, add score
        cheat++;
        if (cheat > 10) {
          cheat = 0;
          addScore(12);
        }
      }
    }
  }
  private boolean blockSpecialAlgorigthm() {
    boolean hasChanged = false;
    boolean containsUpwardArrow = false;
    boolean containsDownwardArrow = false;

    for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
      System.out.println("1");
      int columnStars = getCalculatedColumnStars(iX, true);
      if (1 == columnStars) {
        containsUpwardArrow = false;
        containsDownwardArrow = false;
        for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
          System.out.println("2");
          Field oField = _oBoard.getField(iY, iX);
          if (oField.getState() == eStates.ARROW_N) {
            containsDownwardArrow = true;
          }

          if (oField.getState() == eStates.ARROW_S) {
            containsUpwardArrow = true;
          }
        }

        if (containsUpwardArrow) {
          // collect Fields that are Pointed by Arrow
          for (int iY = _oBoard.getHeight() - 1; iY >= 0; iY--) {
            System.out.println("3");
            Field oField = _oBoard.getField(iY, iX);
            if (oField.getState() == eStates.ARROW_S) {
              for (int iY2 = iY; iY2 >= 0; iY2--) {
                System.out.println("4");
                boolean tmpChanged = updateTmpFields(iY2, iX, eStatesDiff.BLOCKED);
                if (!hasChanged) {
                  hasChanged = tmpChanged;
                }
              }
              break;
            }
          }
        }

        if (containsDownwardArrow) {
          // collect Fields that are Pointed by Arrow
          for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
            System.out.println("5");
            Field oField = _oBoard.getField(iY, iX);
            if (oField.getState() == eStates.ARROW_N) {
              for (int iY2 = iY; iY2 < _oBoard.getHeight(); iY2++) {
                System.out.println("6");
                boolean tmpChanged = updateTmpFields(iY2, iX, eStatesDiff.BLOCKED);
                if (!hasChanged) {
                  hasChanged = tmpChanged;
                }
              }
              break;
            }
          }
        }
      }
    }

    for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
      int rowStars = getCalculatedColumnStars(iY, true);
      if (1 == rowStars) {
        containsUpwardArrow = false;
        containsDownwardArrow = false;
        for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
          Field oField = _oBoard.getField(iY, iX);
          if (oField.getState() == eStates.ARROW_W) {
            containsDownwardArrow = true;
          }

          if (oField.getState() == eStates.ARROW_E) {
            containsUpwardArrow = true;
          }
        }

        if (containsUpwardArrow) {
          // collect Fields that are Pointed by Arrow
          for (int iX = _oBoard.getWidth() - 1; iX >= 0; iX--) {
            Field oField = _oBoard.getField(iY, iX);
            if (oField.getState() == eStates.ARROW_E) {
              for (int iX2 = iX; iX2 >= 0; iX2--) {
                boolean tmpChanged = updateTmpFields(iY, iX2, eStatesDiff.BLOCKED);
                if (!hasChanged) {
                  hasChanged = tmpChanged;
                }
              }
              break;
            }
          }
        }

        if (containsDownwardArrow) {
          // collect Fields that are Pointed by Arrow
          for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
            Field oField = _oBoard.getField(iY, iX);
            if (oField.getState() == eStates.ARROW_W) {
              for (int iX2 = iX; iX2 < _oBoard.getHeight(); iX2++) {
                boolean tmpChanged = updateTmpFields(iY, iX2, eStatesDiff.BLOCKED);
                if (!hasChanged) {
                  hasChanged = tmpChanged;
                }
              }
              break;
            }
          }
        }
      }
    }

    return hasChanged;
  }
  /**
   * Konstruktor der Klasse CheckEditorBoardDifficulty Das Editor Board wird nach der Schwirigkeit
   * geprüft
   *
   * @return BOARD_DIFFICULTY_EASY = "einfach" - Hier wird angegeben, dass das Board die
   *     Schwirigkeit leicht hat
   * @return BOARD_DIFFICULTY_MEDIUM = Hier wird angegeben, dass das Board die Schwirigkeit mittel
   *     hat
   * @return BOARD_DIFFICULTY_HARD = Hier wird angegeben, dass das Board die Schwirigkeit schwer hat
   * @return BOARD_DIFFICULTY_NOT_SOLVABLE = Hier wird angegeben, dass das Board die Schwirigkeit
   *     unlösbar hat
   */
  public String checkDifficulty() {
    /** Dekleration der Variabeln für die Funktion checkDifficulty */
    _tmpDiff = new eStatesDiff[_oBoard.getHeight()][_oBoard.getWidth()];

    boolean isSolvable = false;
    boolean doMediumSearch = false;
    boolean doHardSearch = false;
    boolean isSolved = false;
    boolean hasChanged = true;
    int tmpStarCount = 0;
    int tmpEmptyFields = 0;
    int counter = 0;
    boolean foundEmptySpot = false;
    int foundSpotX = -1;
    int foundSpotY = -1;
    int adder = 0;

    // go through logicuntil game is solved or stop when no changes were made in last run
    while (!isSolved && hasChanged) {
      hasChanged = false;
      for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
        int rowStars = getCalculatedRowStars(iY, doMediumSearch);

        for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
          int columnStars = getCalculatedColumnStars(iX, doMediumSearch);
          Field oField = _oBoard.getField(iY, iX);

          if (0 == columnStars || 0 == rowStars || isArrow(oField.getState())) {

            boolean tmpChanged = updateTmpFields(iY, iX, eStatesDiff.BLOCKED);
            if (!hasChanged) {
              hasChanged = tmpChanged;
            }
          }

          if (!isArrowPointingAtField(iY, iX)) {
            boolean tmpChanged = updateTmpFields(iY, iX, eStatesDiff.BLOCKED);
            if (!hasChanged) {
              hasChanged = tmpChanged;
            }
          }
        }

        tmpEmptyFields = 0;
        for (int iX2 = 0; iX2 < _oBoard.getWidth(); iX2++) {
          if (_tmpDiff[iY][iX2] != eStatesDiff.BLOCKED && _tmpDiff[iY][iX2] != eStatesDiff.ISSTAR) {
            tmpEmptyFields++;
          }
        }

        if (tmpEmptyFields == rowStars) {
          for (int iX2 = 0; iX2 < _oBoard.getWidth(); iX2++) {
            if (_tmpDiff[iY][iX2] != eStatesDiff.BLOCKED) {
              boolean tmpChanged = updateTmpFields(iY, iX2, eStatesDiff.ISSTAR);
              if (!hasChanged) {
                hasChanged = tmpChanged;
              }
            }
          }
        }
      }

      tmpEmptyFields = 0;
      for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
        tmpEmptyFields = 0;

        int columnStars = getCalculatedColumnStars(iX, doMediumSearch);
        for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
          if (_tmpDiff[iY][iX] != eStatesDiff.BLOCKED && _tmpDiff[iY][iX] != eStatesDiff.ISSTAR) {
            tmpEmptyFields++;
          }
        }

        if (tmpEmptyFields == columnStars) {
          for (int iY2 = 0; iY2 < _oBoard.getWidth(); iY2++) {
            if (_tmpDiff[iY2][iX] != eStatesDiff.BLOCKED) {
              boolean tmpChanged = updateTmpFields(iY2, iX, eStatesDiff.ISSTAR);
              if (!hasChanged) {
                hasChanged = tmpChanged;
              }
            }
          }
        }
      }

      // cross calculation
      for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
        tmpEmptyFields = 0;

        for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
          foundEmptySpot = false;
          foundSpotX = -1;
          foundSpotY = -1;
          Field oField = _oBoard.getField(iY, iX);

          if (oField.getState() == eStates.ARROW_SW) {
            adder = 1;
            while (((iY + adder) < _oBoard.getHeight()) && ((iX - adder) >= 0)) {
              if (_tmpDiff[iY + adder][iX - adder] != eStatesDiff.BLOCKED
                  && _tmpDiff[iY + adder][iX - adder] != eStatesDiff.ISSTAR) {
                if (!foundEmptySpot) {
                  foundSpotX = iX - adder;
                  foundSpotY = iY + adder;
                  foundEmptySpot = true;
                } else {
                  foundSpotX = -1;
                  foundSpotY = -1;
                  foundEmptySpot = false;
                  break;
                }
              }
              adder++;
            }
          } else if (oField.getState() == eStates.ARROW_SE) {
            adder = 1;
            while (((iY + adder) < _oBoard.getHeight()) && ((iX + adder) < _oBoard.getWidth())) {
              if (_tmpDiff[iY + adder][iX + adder] != eStatesDiff.BLOCKED
                  && _tmpDiff[iY + adder][iX + adder] != eStatesDiff.ISSTAR) {
                if (!foundEmptySpot) {
                  foundSpotX = iX + adder;
                  foundSpotY = iY + adder;
                  foundEmptySpot = true;
                } else {
                  foundSpotX = -1;
                  foundSpotY = -1;
                  foundEmptySpot = false;
                  break;
                }
              }
              adder++;
            }
          } else if (oField.getState() == eStates.ARROW_NW) {
            adder = 1;
            while (((iY - adder) >= 0) && ((iX - adder) >= 0)) {
              if (_tmpDiff[iY - adder][iX - adder] != eStatesDiff.BLOCKED
                  && _tmpDiff[iY - adder][iX - adder] != eStatesDiff.ISSTAR) {
                if (!foundEmptySpot) {
                  foundSpotX = iX - adder;
                  foundSpotY = iY - adder;
                  foundEmptySpot = true;
                } else {
                  foundSpotX = -1;
                  foundSpotY = -1;
                  foundEmptySpot = false;
                  break;
                }
              }
              adder++;
            }
          } else if (oField.getState() == eStates.ARROW_NE) {
            adder = 1;
            while (((iY - adder) >= 0) && ((iX + adder) < _oBoard.getWidth())) {
              if (_tmpDiff[iY - adder][iX + adder] != eStatesDiff.BLOCKED
                  && _tmpDiff[iY - adder][iX + adder] != eStatesDiff.ISSTAR) {
                if (!foundEmptySpot) {
                  foundSpotX = iX + adder;
                  foundSpotY = iY - adder;
                  foundEmptySpot = true;
                } else {
                  foundSpotX = -1;
                  foundSpotY = -1;
                  foundEmptySpot = false;
                  break;
                }
              }
              adder++;
            }
          }

          if (foundEmptySpot) {
            boolean tmpChanged = updateTmpFields(foundSpotY, foundSpotX, eStatesDiff.ISSTAR);
            if (!hasChanged) {
              hasChanged = tmpChanged;
            }

            foundSpotX = -1;
            foundSpotY = -1;
          }
        }
      }

      if (doHardSearch) {
        boolean upCheckDone = false;
        boolean downCheckDone = false;
        foundEmptySpot = false;
        foundSpotX = -1;
        foundSpotY = -1;

        for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
          upCheckDone = false;
          downCheckDone = false;
          int columnStars = getCalculatedColumnStars(iX, doHardSearch);
          if (1 <= columnStars) {
            // up check
            for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
              foundEmptySpot = false;
              Field oField = _oBoard.getField(iY, iX);

              if (!upCheckDone && oField.getState() == eStates.ARROW_N) {
                upCheckDone = true;
                for (int iTmpY = 0; iTmpY < iY; iTmpY++) {
                  if (_tmpDiff[iTmpY][iX] != eStatesDiff.BLOCKED
                      && _tmpDiff[iTmpY][iX] != eStatesDiff.ISSTAR) {
                    if (!foundEmptySpot) {
                      foundSpotX = iX;
                      foundSpotY = iTmpY;
                      foundEmptySpot = true;
                    } else {
                      foundSpotX = -1;
                      foundSpotY = -1;
                      foundEmptySpot = false;
                      break;
                    }
                  }
                }

                if (foundEmptySpot) {
                  boolean tmpChanged = updateTmpFields(foundSpotY, foundSpotX, eStatesDiff.ISSTAR);
                  if (!hasChanged) {
                    hasChanged = tmpChanged;
                  }

                  foundSpotX = -1;
                  foundSpotY = -1;
                }
              }
            }

            // down check
            for (int iY = _oBoard.getHeight() - 1; iY >= 0; iY--) {
              foundEmptySpot = false;
              Field oField = _oBoard.getField(iY, iX);

              if (!downCheckDone && oField.getState() == eStates.ARROW_S) {
                downCheckDone = true;
                for (int iTmpY = iY + 1; iTmpY < _oBoard.getHeight(); iTmpY++) {
                  if (_tmpDiff[iTmpY][iX] != eStatesDiff.BLOCKED
                      && _tmpDiff[iTmpY][iX] != eStatesDiff.ISSTAR) {
                    if (!foundEmptySpot) {
                      foundSpotX = iX;
                      foundSpotY = iTmpY;
                      foundEmptySpot = true;
                    } else {
                      foundSpotX = -1;
                      foundSpotY = -1;
                      foundEmptySpot = false;
                      break;
                    }
                  }
                }

                if (foundEmptySpot) {
                  boolean tmpChanged = updateTmpFields(foundSpotY, foundSpotX, eStatesDiff.ISSTAR);
                  if (!hasChanged) {
                    hasChanged = tmpChanged;
                  }

                  foundSpotX = -1;
                  foundSpotY = -1;
                }
              }
            }
          }
        }

        for (int iY = 0; iY < _oBoard.getHeight(); iY++) {
          upCheckDone = false;
          downCheckDone = false;
          int rowStars = getCalculatedRowStars(iY, doHardSearch);
          if (1 <= rowStars) {
            // up check
            for (int iX = 0; iX < _oBoard.getWidth(); iX++) {
              foundEmptySpot = false;
              Field oField = _oBoard.getField(iY, iX);

              if (!upCheckDone && oField.getState() == eStates.ARROW_W) {
                upCheckDone = true;
                for (int iTmpX = 0; iTmpX < iX; iTmpX++) {
                  if (_tmpDiff[iY][iTmpX] != eStatesDiff.BLOCKED
                      && _tmpDiff[iY][iTmpX] != eStatesDiff.ISSTAR) {
                    if (!foundEmptySpot) {
                      foundSpotX = iTmpX;
                      foundSpotY = iY;
                      foundEmptySpot = true;
                    } else {
                      foundSpotX = -1;
                      foundSpotY = -1;
                      foundEmptySpot = false;
                      break;
                    }
                  }
                }

                if (foundEmptySpot) {
                  boolean tmpChanged = updateTmpFields(foundSpotY, foundSpotX, eStatesDiff.ISSTAR);
                  if (!hasChanged) {
                    hasChanged = tmpChanged;
                  }

                  foundSpotX = -1;
                  foundSpotY = -1;
                }
              }
            }

            // up check
            for (int iX = _oBoard.getWidth() - 1; iX >= 0; iX--) {
              foundEmptySpot = false;
              Field oField = _oBoard.getField(iY, iX);

              if (!downCheckDone && oField.getState() == eStates.ARROW_E) {
                downCheckDone = true;
                for (int iTmpX = iX + 1; iTmpX < _oBoard.getWidth(); iTmpX++) {
                  if (_tmpDiff[iY][iTmpX] != eStatesDiff.BLOCKED
                      && _tmpDiff[iY][iTmpX] != eStatesDiff.ISSTAR) {
                    if (!foundEmptySpot) {
                      foundSpotX = iTmpX;
                      foundSpotY = iY;
                      foundEmptySpot = true;
                    } else {
                      foundSpotX = -1;
                      foundSpotY = -1;
                      foundEmptySpot = false;
                      break;
                    }
                  }
                }

                if (foundEmptySpot) {
                  boolean tmpChanged = updateTmpFields(foundSpotY, foundSpotX, eStatesDiff.ISSTAR);
                  if (!hasChanged) {
                    hasChanged = tmpChanged;
                  }

                  foundSpotX = -1;
                  foundSpotY = -1;
                }
              }
            }
          }
        }

        if (!hasChanged) {
          boolean tmpChanged = blockSpecialAlgorigthm();
          if (!hasChanged) {
            hasChanged = tmpChanged;
          }
        }
      }

      isSolved = isSolved();
      counter++;

      if (!isSolved && !doMediumSearch && (counter > 1 || !hasChanged)) {
        // its medium
        doMediumSearch = true;
        hasChanged = true;
      }

      if (!isSolved && doMediumSearch && !doHardSearch && (counter > 5 || !hasChanged)) {
        // its medium
        doHardSearch = true;
        hasChanged = true;
      }
    }

    if (isSolved && !doMediumSearch && counter < 2) {
      return BOARD_DIFFICULTY_EASY;
    } else if (isSolved && counter < 6) {
      return BOARD_DIFFICULTY_MEDIUM;
    } else if (isSolved) {
      return BOARD_DIFFICULTY_HARD;
    } else {
      calculatedUnsolvableStars();
      return BOARD_DIFFICULTY_NOT_SOLVABLE;
    }
  }
예제 #18
0
 public void center() {
   position_x = (board.getWidth() * CELL_WIDTH - getWidth()) / 2;
   position_y = (board.getHeight() * CELL_HEIGHT - getHeight()) / 2;
 }
예제 #19
0
  private synchronized void processTick(Tick tick) {
    int x, y;

    // Fazer as opera��es primeiro por causa dos observers no swapBuffers()
    // Por os avi�es a marchar
    for (Plane p : backBuffer.values()) p.move();

    // Remover os avi�es que saem do mapa
    boolean succ = false;
    Set<Character> remover = new TreeSet<Character>();

    for (Plane p :
        backBuffer
            .values()) { // A diferen�a entre tirar logo quando ele chega na porta ou tirar depois
                         // de ter passado um epoch na porta
      x = p.getxCoord();
      y = p.getyCoord();

      if (x <= 0 || y <= 0 || y >= board.getHeight() || x >= board.getWidth()) {
        for (Gate g : board.getPorts().values())
          if (g.getxCoord() == x && g.getyCoord() == y && p.getExitAltitude() == p.getAltitude()) {
            this.successfulExits++;
            succ = true;
            break;
          }
        if (succ) succ = false;
        else this.unsuccessfulExits++;
        remover.add(p.getID());
      }
    }
    for (Character id : remover) backBuffer.remove(id);

    // Remover avi�es que colidiram no epoch anterior - est�o marcados com um '+'
    for (Plane p : frontBuffer.values())
      if (p.getSymbol() == '+') {
        backBuffer.remove(p.getID());
        this.unsuccessfulExits++;
      }

    // Testar colis�es
    for (Plane p : backBuffer.values()) {
      x = p.getxCoord();
      y = p.getyCoord();
      for (Plane p2 : backBuffer.values()) {
        int x2 = p2.getxCoord();
        int y2 = p2.getyCoord();
        if (p != p2
            && Math.abs(x - x2) <= 1
            && Math.abs(y - y2) <= 1
            && Math.abs(p.getAltitude() - p2.getAltitude()) <= 1000) {
          p.setSymbol('+');
          p2.setSymbol('+');
        } // N�o fazer 'continue;' pq pode haver 3 ou mais avi�es a colidirem
      }
    }

    // Reset avioes adicionados
    previousAdds = actualAdds;
    actualAdds = new HashMap<Gate, Integer>();

    // Trocar os buffers
    epoch++;
    swapBuffers();
  }
예제 #20
0
  @Override
  protected void onDraw(Canvas canvas) {
    Move m = board.getLastMovew();
    // Background
    canvas.drawColor(colBackground);
    Paint myPen = new Paint();

    for (int r = 0; r <= board.getHeight(); r++) {
      drawLine(
          LEFT_MARGIN - position_x,
          (TOP_MARGIN + r * CELL_HEIGHT) - position_y,
          (LEFT_MARGIN + board.getWidth() * CELL_WIDTH) - position_x,
          (TOP_MARGIN + r * CELL_HEIGHT) - position_y,
          canvas,
          myPen);
    }
    for (int c = 0; c <= board.getWidth(); c++) {
      drawLine(
          (LEFT_MARGIN + c * CELL_WIDTH) - position_x,
          TOP_MARGIN - position_y,
          (LEFT_MARGIN + c * CELL_WIDTH) - position_x,
          (TOP_MARGIN + board.getHeight() * CELL_HEIGHT) - position_y,
          canvas,
          myPen);
    }
    myPen.setColor(colBorder);
    myPen.setStrokeWidth(3);
    canvas.drawRect(
        LEFT_MARGIN - position_x,
        TOP_MARGIN - position_y,
        LEFT_MARGIN + board.getWidth() * CELL_WIDTH - position_x,
        (TOP_MARGIN + board.getHeight() * CELL_HEIGHT) - position_y,
        myPen);

    for (int r = 0; r < board.getHeight(); r++) {
      for (int c = 0; c < board.getWidth(); c++) {
        int x_in = 0, y_in = 0;
        if (m != null) {
          x_in = (int) ((m.getColumn() - c) / (float) board.getWidth() * PIECE_WIDTH);
          y_in = (int) ((m.getRow() - r) / (float) board.getWidth() * PIECE_HEIGHT);
          x_in = (x_in > PIECE_WIDTH / 2) ? PIECE_WIDTH / 2 : x_in;
          y_in = (y_in > PIECE_HEIGHT / 2) ? PIECE_HEIGHT / 2 : y_in;
        }
        byte piece = board.getPiece(r, c);
        if (piece == Board.WHITE) {
          if (board.lastmovew(new Move(r, c, Board.WHITE))) {
            drawWhiteLast(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2,
                canvas);
          } else {
            drawShadowWhite(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2 - x_in,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2 - y_in,
                canvas);
            drawWhite(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2,
                canvas);
          }
        }
        if (piece == Board.BLACK) {
          if (board.lastmovew(new Move(r, c, Board.BLACK))) {
            drawBlackLast(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2,
                canvas);
          } else {
            drawShadowBlack(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2 - x_in,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2 - y_in,
                canvas);
            drawBlack(
                LEFT_MARGIN - position_x + c * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2,
                TOP_MARGIN - position_y + r * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2,
                canvas);
          }
        }
      }
    }
    if (m != null) {
      drawHigh(
          LEFT_MARGIN - position_x + m.getColumn() * CELL_WIDTH + (CELL_WIDTH - PIECE_WIDTH) / 2,
          TOP_MARGIN - position_y + m.getRow() * CELL_HEIGHT + (CELL_HEIGHT - PIECE_HEIGHT) / 2,
          canvas);
    }

    if (mButtonPressed == true) {
      if (celltouch.x < board.getWidth()
          && celltouch.y
              < board.getHeight() /*&&board.getPiece(celltouch.x,celltouch.y)==Board.BLACK*/) {
        myPen.setColor(colSelect);
        myPen.setStrokeWidth(3);
        myPen.setStyle(Paint.Style.STROKE);
        canvas.drawRect(
            LEFT_MARGIN - position_x + celltouch.x * CELL_WIDTH,
            TOP_MARGIN - position_y + celltouch.y * CELL_WIDTH,
            LEFT_MARGIN - position_x + (celltouch.x + 1) * CELL_WIDTH,
            TOP_MARGIN - position_y + (celltouch.y + 1) * CELL_HEIGHT,
            myPen);
      }
    }
    super.onDraw(canvas);
  }