Beispiel #1
0
void test_all_pieces_all_rotations() {

  std::cout << "=====================================================================" << std::endl;
  std::cout << "test_all_pieces_all_rotations()" << std::endl;

  Tetris tetris(20);
  // on a big board, insert the different 7 pieces each of 4 rotations
  char pieces[7] = { 'I', 'O', 'T', 'Z', 'S', 'L', 'J' };
  for (int i = 0; i < 7; i++) {
    tetris.add_piece(pieces[i],0,0);
    tetris.add_piece(pieces[i],90,5);
    tetris.add_piece(pieces[i],180,10);
    tetris.add_piece(pieces[i],270,15);
    assert (tetris.count_squares() == (i+1)*4*4);
    if      (i == 0) assert (tetris.get_max_height() == 4);
    else if (i == 1) assert (tetris.get_max_height() == 6);
    else if (i == 2) assert (tetris.get_max_height() == 8);
    else if (i == 3) assert (tetris.get_max_height() == 10);
    else if (i == 4) assert (tetris.get_max_height() == 12);
    else if (i == 5) assert (tetris.get_max_height() == 15);
    else if (i == 6) assert (tetris.get_max_height() == 18);
  }
  tetris.print();

  // cleanup
  tetris.destroy();
  std::cout << "done with test_all_pieces_all_rotations()" << std::endl;
}
Beispiel #2
0
void test_add_remove_columns() {

  std::cout << "=====================================================================" << std::endl;
  std::cout << "test_add_remove_columns()" << std::endl;

  std::cout << "start with a board of width 5 and a couple pieces:" << std::endl;
  Tetris tetris(5);
  tetris.add_piece('I',90,1);
  tetris.add_piece('O',0,0);
  tetris.print();
  assert (tetris.get_width() == 5);
  assert (tetris.count_squares() == 8);
  assert (tetris.get_max_height() == 3);

  std::cout << "add a column to the left, then right side of the board:" << std::endl;
  tetris.add_left_column();
  tetris.print();
  assert (tetris.get_width() == 6);
  tetris.add_right_column();
  tetris.print();
  assert (tetris.get_width() == 7);
  assert (tetris.count_squares() == 8);
  assert (tetris.get_max_height() == 3);

  std::cout << "add a few more pieces to the board:" << std::endl;
  tetris.add_piece('I',90,0);
  tetris.add_piece('O',0,5);
  tetris.print();
  assert (tetris.count_squares() == 16);
  assert (tetris.get_max_height() == 4);

  std::cout << "remove the leftmost the rightmost columns (and lose any squares in those columns):" << std::endl;
  tetris.remove_left_column();
  tetris.print();
  assert (tetris.get_width() == 6);
  tetris.remove_right_column();
  tetris.print();
  assert (tetris.get_width() == 5);
  assert (tetris.count_squares() == 13);
  assert (tetris.get_max_height() == 4);

  std::cout << "after dropping another column from the left, the board has a full row that can be scored:" << std::endl;
  tetris.remove_left_column();
  tetris.print();
  assert (tetris.get_width() == 4);
  int score = tetris.remove_full_rows();
  assert (score == 1);
  tetris.print();
  assert (tetris.count_squares() == 6);
  assert (tetris.get_max_height() == 3);

  // cleanup
  tetris.destroy();
  std::cout << "done with test_add_remove_columns()" << std::endl;
}
Beispiel #3
0
void test_example() {
  std::cout << "=====================================================================" << std::endl;
  std::cout << "test_example()" << std::endl;

  Tetris tetris(6);
  std::cout << "empty board with width = 6:" << std::endl;
  tetris.print();
  assert (tetris.get_width() == 6);

  tetris.add_piece('O',0,1);
  std::cout << "after adding first piece:" << std::endl;
  tetris.print();
  // The get_max_height Tetris member function returns the height of
  // the tallest column on the board.
  assert (tetris.get_max_height() == 2);
  // The count_squares Tetris member function returns the total number
  // of squares on the board (each piece has 4 squares).
  assert (tetris.count_squares() == 4);

  
  tetris.add_piece('I',90,2);
  tetris.add_piece('I',0,4);
  tetris.add_piece('O',0,3);
  std::cout << "after adding three more pieces:" << std::endl;
  tetris.print();

  tetris.add_piece('O',0,0);
  std::cout << "after adding another piece, we need to score to remove the third row:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 9);
  assert (tetris.count_squares() == 20);

  int score = tetris.remove_full_rows();
  assert (score == 1);
  std::cout << "after removing 1 full row:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 8);
  assert (tetris.count_squares() == 14);

  // cleanup
  // The destroy Tetris member function cleans up all dynamically
  // allocated memory for the Tetris board.  
  tetris.destroy();
  std::cout << "done with test_example()" << std::endl;
  

}
Beispiel #4
0
void additional_student_tests() {

  std::cout << "=====================================================================" << std::endl;
  std::cout << "additional_student_tests()" << std::endl;
  //add some pieces to see if they look good....
  Tetris tetris(14);
  std::cout << "First add somes pieces..."<<std::endl;
  tetris.add_piece('I',90,0);
  tetris.add_piece('T',90,3);
  tetris.add_piece('S',0,1);
  tetris.add_piece('L',0,5);
  tetris.add_piece('J',0,8);
  tetris.add_piece('O',270,10);
  tetris.add_piece('T',270,0);
  tetris.add_piece('Z',0,9);
  tetris.add_piece('I',0,12);
  //check if the heights is right
  assert (tetris.get_max_height() == 4);
  std::cout<< "The results look like....:"<<std::endl;
  tetris.print();
  std::cout<< "Let's remove the right column and see the result! "<<std::endl;
  tetris.remove_right_column();
  tetris.print();
  std::cout<< "It seems we almost have some full rows...? Add a piece now "<<std::endl;
  tetris.add_piece('T',0,6);
  tetris.print();
  tetris.remove_full_rows();
  std::cout<< "After removing: "<<std::endl;
  //check if the remove row work well
  assert (tetris.get_max_height() == 2);
  tetris.print();
  //create new tetris to have text rpi...
  Tetris tetris1(13);
  std::cout<< "print RPI "<<std::endl;
  tetris1.add_piece('I',0,1);
  tetris1.add_piece('J',270,1);
  tetris1.add_piece('J',0,6);
  tetris1.add_piece('I',0,6);
  tetris1.add_piece('O',180,7);
  tetris1.add_piece('I',0,11);
  tetris1.print();
  //clean up 2 tetris..
  tetris.destroy();
  tetris1.destroy();
  std::cout << "done with additional_student_tests()" << std::endl;
}
Beispiel #5
0
void test_score_multirow() {
  std::cout << "=====================================================================" << std::endl;
  std::cout << "test_score_multirow()" << std::endl;

  Tetris tetris(7);
  tetris.add_piece('I',90,3);
  tetris.add_piece('O',0,4);
  tetris.add_piece('O',0,0);
  tetris.add_piece('O',0,0);
  tetris.add_piece('O',0,5);
  tetris.add_piece('O',0,3);

  std::cout << "interesting board with 6 pieces:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 5);
  assert (tetris.count_squares() == 24);
  int score = 0;
  score += tetris.remove_full_rows();
  assert (score == 0);

  tetris.add_piece('I',0,2);
  std::cout << "after adding 7th piece, before scoring:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 5);
  assert (tetris.count_squares() == 28);

  score += tetris.remove_full_rows();
  assert (score == 2);
  std::cout << "after removing 2 rows:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 3);
  assert (tetris.count_squares() == 14);

  tetris.add_piece('I',0,0);
  tetris.add_piece('O',0,1);
  std::cout << "after adding 8th & 9th pieces,  before scoring:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 6);
  assert (tetris.count_squares() == 22);

  score += tetris.remove_full_rows();
  assert (score == 3);
  std::cout << "after removing 1 more row:" << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 5);
  assert (tetris.count_squares() == 15);

  tetris.add_piece('I',0,6);
  tetris.add_piece('O',0,1);
  tetris.add_piece('O',0,4);
  std::cout << "before scoring a quad row removal..." << std::endl;
  tetris.print();
  tetris.add_piece('I',0,3);
  score += tetris.remove_full_rows();
  assert (score == 7);
  std::cout << "after the quad row removal... " << std::endl;
  tetris.print();
  assert (tetris.get_max_height() == 1);
  assert (tetris.count_squares() == 3);

  // cleanup
  tetris.destroy();
  std::cout << "done with test_score_multirow()" << std::endl;
}
Beispiel #6
0
void display_loop(){
//	mcuf_serial_mode();

	mode = setjmp(newmode_jmpbuf);

#ifdef JOYSTICK_SUPPORT
	// in case we get here via mode jump, we (re)enable joystick queries
	waitForFire = 1;
#endif

	oldOldmode = oldMode;

#ifdef JOYSTICK_SUPPORT
	waitForFire = 1;
#endif

	for(;;){
#ifndef MENU_SUPPORT
		clear_screen(0);
#endif
		oldMode = mode;

		switch(mode++) {

#ifdef ANIMATION_SCROLLTEXT
		case 1:
			scrolltext(scrolltext_text);

	#ifdef RANDOM_SUPPORT
			{
				char a[28];
				sprintf(a,"</# counter == %lu  ",
					(unsigned long)percnt_get(&g_reset_counter, &g_reset_counter_idx));
				scrolltext(a);
			}
	#endif
#endif
#ifdef ANIMATION_TIME
#ifndef ANIMATION_SCROLLTEXT
		case 1:
#endif
			time_anim();
			break;
#else
#ifdef ANIMATION_SCROLLTEXT
			break;
#endif
#endif

#ifdef ANIMATION_SPIRAL
#		ifndef SPIRAL_DELAY
#			define SPIRAL_DELAY 5
#		endif

		case 2:
			spiral(SPIRAL_DELAY);
			break;
#endif

#ifdef ANIMATION_JOERN1
		case 3:
			joern1();
			break;
#endif

#ifdef ANIMATION_SNAKE
		case 4:
			snake_animation();
			break;
#endif

#ifdef ANIMATION_CHECKERBOARD
		case 5:
			checkerboard(20);
			break;
#endif

#ifdef ANIMATION_FIRE
		case 6:
			fire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 7:
			time_anim();
			break;
#endif

#ifdef ANIMATION_MATRIX
		case 8:
			matrix();
			break;
#endif

#ifdef ANIMATION_RANDOM_BRIGHT
		case 9:
			random_bright(30);
			break;
#endif

#ifdef ANIMATION_STONEFLY
		case 10:
			stonefly();
			break;
#endif

#ifdef ANIMATION_GAMEOFLIFE
		case 11:
			gameoflife();
			break;
#endif

#ifdef ANIMATION_FLYINGDOTS
		case 12:
			flyingdots();
			break;
#endif

#ifdef ANIMATION_BREAKOUT
		case 13:
			breakout_demo();
			break;
#endif

#ifdef ANIMATION_MHERWEG
		case 14:
			mherweg();
			break;
#endif

#ifdef ANIMATION_MOIRE
		case 15:
			moire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 16:
			time_anim();
			break;
#endif

#ifdef ANIMATION_LTN_ANT
		case 17:
			ltn_ant();
			break;
#endif

#ifdef ANIMATION_LABORLOGO
		case 18:
			laborlogo();
			break;
#endif

#ifdef ANIMATION_AMPHIBIAN
		case 19:
			amphibian();
			break;
#endif

#ifdef ANIMATION_LOGO_OOS
		case 20:
			logo_OutOfSpec();
			break;
#endif

#ifdef ANIMATION_FAIRYDUST
		case 21:
			fairydust();
			break;
#endif

#ifdef ANIMATION_PLASMA
		case 22:
			plasma();
			break;
#endif

#ifdef ANIMATION_PSYCHEDELIC
		case 23:
			psychedelic();
			break;
#endif

#ifdef ANIMATION_BLACKHOLE
		case 24:
			blackhole();
			break;
#endif

#ifdef ANIMATION_SQUARES
		case 25:
			squares();
			break;
#endif

#ifdef ANIMATION_DNA
		case 26:
			dna();
			break;
#endif

#ifdef ANIMATION_TESTS
		case 31:
			test_level(1, false);
			break;

		case 32:
			test_level(2, false);
			break;

		case 33:
			test_level(3, false);
			break;

		case 35:
			test_palette(false);
			test_palette2(false);
			break;
#endif

#ifdef SMALLANIMATION_ROWWALK
		case 36:
		  rowwalk(SMALLANIMATION_ROWWALK_COUNT,SMALLANIMATION_ROWWALK_SPEED);
		  break;
#endif

#ifdef SMALLANIMATION_COLWALK
		case 37:
		  colwalk(SMALLANIMATION_COLWALK_COUNT,SMALLANIMATION_COLWALK_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_COLBOUNCE
		case 38:
		  colbounce(SMALLANIMATION_COLBOUNCE_COUNT,SMALLANIMATION_COLBOUNCE_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_ROWBOUNCE
		case 39:
		  rowbounce(SMALLANIMATION_ROWBOUNCE_COUNT,SMALLANIMATION_ROWBOUNCE_SPEED);
		  break;
#endif

#ifdef MENU_SUPPORT
		case 0xFDu:
			mode = 1;
			break;

		case 0xFEu:
			menu();
			mode = oldOldmode;
			break;
#else

		case 0xFDu:
#ifdef JOYSTICK_SUPPORT
			if (JOYISFIRE)
				mode = 0xFEu;
			else
#endif
				mode = 1;
			break;

		case 0xFEu:
#ifdef JOYSTICK_SUPPORT
			waitForFire = 0;   // avoid circular jumps
			while (JOYISFIRE); // wait until user released the fire button
#endif
			wait(25);          // wait for button to settle

#  ifdef GAME_TETRIS
			tetris();
#  endif

#  ifdef GAME_BASTET
			tetris_bastet();
#  endif

#  ifdef GAME_TETRIS_FP
			tetris_fp();
#  endif

#  ifdef GAME_SPACE_INVADERS
			borg_invaders();
#  endif

#  ifdef GAME_SNAKE
			snake_game();
#  endif

#  ifdef GAME_BREAKOUT
			borg_breakout(0);
#  endif

#ifdef JOYSTICK_SUPPORT
			while (JOYISFIRE); // avoid an unwanted restart of the game loop
#endif
			wait(25);          // wait for button to settle
			mode = oldOldmode; // restore old animation mode
#ifdef JOYSTICK_SUPPORT
			waitForFire = 1;   // reenable joystick query of the wait() function
#endif
			break;
#endif

#ifdef ANIMATION_OFF
		case 0xFFu:
			off();
			break;
#endif
		default:
			if (reverseMode) {
				if (reverseMode-- == (mode - 1)) {
					mode -= 2;
				} else {
					reverseMode = 0;
				}
			}
			break;
		}
	}
}