Exemplo n.º 1
0
  /** Updates the gridLayout with the actual game data if existing. */
  private void updateGridView() {

    if (fieldCreationFragment == null || fieldCreationFragment.getZahlenschlange() == null) {
      return;
    }

    Zahlenschlange gameLogic = fieldCreationFragment.getZahlenschlange();

    int index = 0;
    for (int y = 0; y < difficulty; y++) {
      for (int x = 0; x < difficulty; x++) {

        View v = gameSquareGridLayout.getChildAt(index);
        if (v instanceof Field) {
          Field f = (Field) v;

          f.setNumber(gameLogic.getValue(x, y));
          f.setDirection(Field.DIRECTION_NONE);
          f.setDirection2(Field.DIRECTION_NONE);
          f.setBodyStyle(Field.BODY_NORMAL);
        }
        index++;
      }
    }

    Field first = (Field) gameSquareGridLayout.getChildAt(0);
    Field last = (Field) gameSquareGridLayout.getChildAt(index - 1);

    first.setBodyStyle(Field.BODY_TAIL);
    last.setBodyStyle(Field.BODY_HEAD);

    drawPath(gameLogic.getPath());
  }
Exemplo n.º 2
0
  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));
    }
  }