Пример #1
0
void test_complete_rows(void) {
  TrnGame* game;
  int numberOfRows = 5;
  int numberOfColumns = 4;
  int actual_score;
  int expected_score = 1200;
  int expected_level = 1;
  int delay = 500 ;
  int rowIndex, columnIndex;
  TrnPositionInGrid pos;

  game = trn_game_new(numberOfRows, numberOfColumns, delay);
  game->lines_count = 19;
  for (rowIndex = 0 ; rowIndex < 4; rowIndex++) {
    pos.rowIndex = rowIndex;
    for (columnIndex = 0 ; columnIndex < numberOfColumns ;columnIndex++ ) {
      pos.columnIndex = columnIndex;
      trn_grid_set_cell(game->grid, pos,TRN_TETROMINO_I);
    }
  }

  trn_game_check_complete_rows(game);
  printf("score: %d\n", game->score);
  printf("lines_count: %d\n", game->lines_count);


  CU_ASSERT_EQUAL(game->score, expected_score);
  CU_ASSERT_EQUAL(game->level, expected_level);
  trn_game_destroy(game);
}
Пример #2
0
void test_game_new_destroy()
{
    // Create a game.
    int numberOfRows = 3;
    int numberOfColumns = 2;
    int delay = 500;
    TrnGame* game = trn_game_new(numberOfRows, numberOfColumns, delay);

    // Destroy the game.
    trn_game_destroy(game);
}
Пример #3
0
void test_game_update_score()
{

  int numberOfRows = 10;
  int numberOfColumns = 10;
  int delay = 500;
  TrnGame* game;
  int lines_count = 1;
  int actual_score;
  int expected_score = 40;

  game = trn_game_new(numberOfRows, numberOfColumns, delay);
  trn_game_update_score(game, lines_count);
  
  actual_score = game->score;

  CU_ASSERT_EQUAL(actual_score, expected_score);
  trn_game_destroy(game);

}
Пример #4
0
void stack_some_pieces()
{
    int numberOfRows = 20;
    int numberOfColumns = 10;
    int delay = 500;
    int imove;
    TrnGame* game = trn_game_new(numberOfRows, numberOfColumns, delay);
    
    // TrnPiece 0. While the piece is falling:
    // Rotate it 3 times.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    }

    // Move piece to left.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 1. While the piece is falling:
    // Rotate it 1 times.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );

    // Move piece to left.
    for (imove = 0; imove < 4; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 2. While the piece is falling:
    // Rotate it 1 times.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    // Move piece to left.
    for (imove = 0; imove < 2; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 3. While the piece is falling:
    // Rotate it 3 times.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    }
    // Move piece to left.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }

    int rowIndex;
    int columnIndex;
    TrnPositionInGrid pos;
    TrnGrid* expected_grid = trn_grid_new(numberOfRows, numberOfColumns);

    // Expected expected_grid type for pieces 0 and 2
    for (rowIndex = numberOfRows-4 ; rowIndex < numberOfRows ; rowIndex++) {
        pos.rowIndex = rowIndex;
        for (columnIndex = 2 ; columnIndex < 4 ; columnIndex++) {
            pos.columnIndex = columnIndex;
            trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_J);
        }
    }

    // Expected expected_grid type for pieces 1 and 3
    for (rowIndex = numberOfRows-4 ; rowIndex < numberOfRows ; rowIndex++) {
        pos.rowIndex = rowIndex;
        for (columnIndex = 0 ; columnIndex < 2 ; columnIndex++) {
            pos.columnIndex = columnIndex;
            trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_L);
        }
    }
/*
    CU_ASSERT_TRUE( trn_grid_equal(game->grid, expected_grid) );
*/
    trn_game_destroy(game);
}