private void onFieldClick(Field f) { if (f == null || fieldCreationFragment == null || fieldCreationFragment.getZahlenschlange() == null) { return; } if (clickCount < MAX_CLICKS) { clickCount++; } updateClickCount(); Zahlenschlange gameLogic = fieldCreationFragment.getZahlenschlange(); int index = f.getIndex(); int y = index / difficulty; index = index % difficulty; int x = index; Position end = gameLogic.getPathEnd(); if (end.getX() == x && end.getY() == y) { gameLogic.undo(); updateGridView(); return; } Result res = gameLogic.makeStepTo(x, y); if (res.isOk() || res.isGameFinished()) { updateGridView(); if (res.isGameFinished()) { finishGame(true); } } else if (res.isNotAllowed()) { showToast(getString(R.string.operation_not_allowed)); } }