Exemplo n.º 1
0
  private boolean CheckVertical() {
    if (isGameOver()) return true;
    System.out.println("Vertical");
    Counter _occurrence = new Counter(3, 0);
    /*
     * Horizontal scan
     */
    for (int y = 0; y < BOARD_HEIGHT; y++) {
      _occurrence.reset(0);
      int _prevState = _board[0][y];
      for (int x = 0; x < BOARD_HEIGHT; x++) {
        int _currentState = _board[x][y];

        if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) {
          if (_occurrence.isAtMax()) {
            System.out.println("Game over, VERTICALSTAGE0");
            GameOver(_prevState);
            return true;
          }
        }
        _prevState = _currentState;
      }
    }
    return false;
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    /* The following test code is just an example of how you can write
     * a simple test program to check the basic functionality of your class
     * works as you expect. The primary aim is to test each constructor and
     * method - there are many combinations of how you could go about this.
     * For more complex classes and/or methods you may write several different
     * tests for each method to check boundary cases for example.
     */

    System.out.println("Testing default constructor initialisation and get method...");
    Counter c = new Counter();
    System.out.println("Expected 0: Actual: " + c.getCount());

    System.out.println("Testing increment method...");
    c.increment();
    c.increment();
    System.out.println("Expected 2: Actual: " + c.getCount());

    System.out.println("Testing set method...");
    c.setCount(10);
    System.out.println("Expected 10: Actual: " + c.getCount());

    System.out.println("Testing custom constructor initialisation...");
    Counter c1 =
        new Counter(
            5); // Note: creating a second object instance of the Counter class (which has its own
                // state)
    System.out.println("Expected 5: Actual: " + c1.getCount());

    System.out.println("Testing reset method...");
    c1.reset();
    System.out.println("Expected 0: Actual: " + c1.getCount());

    System.out.println("Testing toString method...");
    System.out.println("Expected count=0: Actual: " + c1.toString());

    System.out.println("Testing decrement method..");
    c.decrement();
    c.decrement();
    System.out.println("Expected 1: Actual:" + c.getCount());

    Counter launch = new Counter();

    launch.incremendBy(10);

    while (!launch.isZero()) {
      System.out.print(launch.getCount() + " ");
      launch.decrement();
    }

    System.out.print("Blast off!");
  }
Exemplo n.º 3
0
  private boolean CheckDiagonal() {
    if (isGameOver()) return true;
    System.out.println("Diagonal");
    Counter _occurrence = new Counter(3, 0);
    /** ******************************************** */
    /** Diagonal lines starting from topmost row * */
    /** ******************************************** */
    /** Stage 1 - Right bottom diagonal check */
    /** ******************************************** */
    /** - Starting from leftmost */
    /** - Iterating to rightmost point */
    /** ******************************************** */
    for (int baseX = 0; baseX < BOARD_WIDTH; baseX++) {
      /* Assign starting point's state to the previous state */
      int _prevState = _board[baseX][0];
      _occurrence.reset(0);
      for (int x = baseX, y = 0; (x < BOARD_WIDTH) && (y < BOARD_HEIGHT); x++, y++) {
        int _currentState = _board[x][y];

        if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) {
          if (_occurrence.isAtMax()) {
            System.out.println("Game over, DLTOPSTAGE1");
            GameOver(_prevState);
            return true;
          }
        }
        _prevState = _currentState;
      }
    }

    _occurrence.reset(0);
    /** ******************************************** */
    /** Stage 2 - Left bottom diagonal check */
    /** ******************************************** */
    /** - Starting from rightmost */
    /** - Iterating to leftmost point */
    /** ******************************************** */
    for (int baseX = BOARD_WIDTH - 1; baseX >= 0; baseX--) {
      /* Assign starting point's state to the previous state */
      int _prevState = _board[baseX][0];
      _occurrence.reset(0);
      for (int x = baseX, y = 0; (x >= 0) && (y < BOARD_HEIGHT); x--, y++) {
        int _currentState = _board[x][y];
        if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) {
          if (_occurrence.isAtMax()) {
            System.out.println("Game over, DLTOPSTAGE2");
            GameOver(_prevState);
            return true;
          }
        }
        _prevState = _currentState;
      }
    }

    _occurrence.reset(0);
    /** ******************************************** */
    /** Diagonal lines starting from bottom row * */
    /** ******************************************** */
    /** Stage 1 - Right top diagonal check */
    /** ******************************************** */
    /** - Starting from leftmost */
    /** - Iterating to rightmost point */
    /** ******************************************** */
    for (int baseX = 0; baseX < BOARD_WIDTH; baseX++) {
      /* Assign starting point's state to the previous state */
      int _prevState = _board[baseX][BOARD_HEIGHT - 1];
      _occurrence.reset(0);
      for (int x = baseX, y = BOARD_HEIGHT - 1; (x < BOARD_WIDTH) && (y > 0); x++, y--) {
        int _currentState = _board[x][y];

        if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) {
          if (_occurrence.isAtMax()) {
            System.out.println("Game over, DLBOTSTAGE1");
            GameOver(_prevState);
            return true;
          }
        }
        _prevState = _currentState;
      }
    }

    _occurrence.reset(0);
    /** ******************************************** */
    /** Stage 2 - Left top diagonal check */
    /** ******************************************** */
    /** - Starting from leftmost */
    /** - Iterating to rightmost point */
    /** ******************************************** */
    for (int baseX = BOARD_WIDTH - 1; baseX > 0; baseX--) {
      /* Assign starting point's state to the previous state */
      int _prevState = _board[baseX][BOARD_HEIGHT - 1];
      _occurrence.reset(0);
      for (int x = baseX, y = BOARD_HEIGHT - 1; (x > 0) && (y > 0); x--, y--) {

        int _currentState = _board[x][y];

        if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) {
          if (_occurrence.isAtMax()) {
            System.out.println("Game over, DLBOTSTAGE2");
            GameOver(_prevState);
            return true;
          }
        }
        _prevState = _currentState;
      }
    }
    return false;
  }
Exemplo n.º 4
0
 public void resetCounter() {
   counter.reset();
 }