Пример #1
0
  public void roll(bowlingSymbol pin) {
    chanceToRoll++;
    numOfRemainedPins -= pin.getPin();
    if (endOfGame) {
      return;
    }

    setFrameSymbol(pin);

    setFrameScore();

    displayBoard();
  }
Пример #2
0
  private void setFrameSymbol(bowlingSymbol pin) {
    if (frameNumber != 10) {
      if ((chanceToRoll == 1) && (numOfRemainedPins == 0)) { // strike
        frame.get(frameNumber - 1).addSymbol(STRIKE);
        frame.get(frameNumber - 1).addSymbol(EMPTY);

        frameNumber++;
        chanceToRoll = 0;
        numOfRemainedPins = 10;
      }

      if ((chanceToRoll == 1) && (numOfRemainedPins > 0)) {
        frame.get(frameNumber - 1).addSymbol(pin);
      }

      if ((chanceToRoll == 2) && (numOfRemainedPins == 0)) {
        frame.get(frameNumber - 1).addSymbol(SPARE);
        frameNumber++;
        chanceToRoll = 0;
        numOfRemainedPins = 10;
      }

      if ((chanceToRoll == 2) && (numOfRemainedPins > 0)) {
        // open frame
        frame.get(frameNumber - 1).addSymbol(pin);
        frameNumber++;
        chanceToRoll = 0;
        numOfRemainedPins = 10;
      }
    } else { // last frame (10 frame)
      if (chanceToRoll == 1) {
        if (numOfRemainedPins == 0) { // first chance and strike
          frame.get(frameNumber - 1).addSymbol(STRIKE);
          numOfRemainedPins = 10;
          numRemainedChance = 2;
        } else { // open frame > just one more chance to roll
          frame.get(frameNumber - 1).addSymbol(pin);
          numRemainedChance = 1;
        }
      } else if (chanceToRoll == 2) {
        if (numOfRemainedPins == 0) { // spare you have additional chance
          if (pin.getPin() == 10) {
            frame.get(frameNumber - 1).addSymbol(STRIKE);
          } else {
            frame.get(frameNumber - 1).addSymbol(SPARE);
          }
          numOfRemainedPins = 10;
        } else { // open, there is no bonus shoot (end of this game)
          frame.get(frameNumber - 1).addSymbol(pin);
          if (numRemainedChance == 1) { // first frame is STRIKE, you have one more chance
            chanceToRoll = 0;
            numOfRemainedPins = 10;
            endOfGame = true;
          }
        }
      } else if (chanceToRoll == 3) {
        if (numOfRemainedPins == 0) {
          if (pin.getPin() == 10) {
            frame.get(frameNumber - 1).addSymbol(STRIKE);
          } else {
            frame.get(frameNumber - 1).addSymbol(SPARE);
          }
          numOfRemainedPins = 10;
        } else {
          frame.get(frameNumber - 1).addSymbol(pin);
          chanceToRoll = 0;
          numOfRemainedPins = 10;
          endOfGame = true;
        }
      }
    }
  }