@Override public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: if (isAvailable(x, y) && background != DEFAULT_BACKGROUND && !game.isOk() && !game.isOver() && !game.isOnPause()) { // selected shape Rect selected = getSelectedShape(x, y); if (selected != null) { // save the map shape -> color mg.putShape(selected, background); // add color in the set chosenColors.add(background); // compute the painted area surface_painted += selected.width() * selected.height(); // true is the game is over boolean isOver = isAdjacentShapesWithSameColor(selected, background); if (isOver) { adjacent = getAdjacentShapesWithSameColor(selected, background); adjacent.add(selected); game.gameOver(); } else if (surface_painted < getWidth() * getHeight()) { game.updateScore(computeScore()); } // the entire surface is painted else if (surface_painted == getWidth() * getHeight()) { game.increaseGridNumber(); game.updateScore(computeScore()); game.gameSuccess(); } } } break; } return true; }