Skip to content

Commit

Permalink
Merge pull request #114 from john0312/chiffon-tetris
Browse files Browse the repository at this point in the history
Fix tetris's testing binary and scoring function
  • Loading branch information
ktpss95112 authored Aug 17, 2024
2 parents 1c60fd4 + ad1b11e commit 30accc3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
5 changes: 3 additions & 2 deletions fw/Core/Hitcon/App/TetrisGame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ void TetrisGame::clear_full_line() {
int to = BOARD_HEIGHT - 1;
int cleared_lines = 0;
for (; from >= 0; from--) {
if (board[from] && board[from] != 0b11111111u) {
if (board[from] == 0b11111111u) {
cleared_lines++;
} else {
board[to] = board[from];
if (to != from) {
board[from] = 0;
cleared_lines++;
}
to--;
}
Expand Down
83 changes: 42 additions & 41 deletions fw/Core/Hitcon/App/test-tetris.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ std::mutex game_mutex;
hitcon::tetris::TetrisGame game([]() { return static_cast<unsigned>(rand()); });

void print_buf_90(display_buf_t* buf_) {
printf("Score: %d\n", game.game_get_score());

// will rotate 90 degree since tetris is portrait
uint8_t buf[DISPLAY_WIDTH * DISPLAY_HEIGHT];
display_buf_unpack(buf, buf_);
Expand Down Expand Up @@ -63,6 +65,7 @@ void gameFunction() {
game.game_fall_down_tetromino();
prev_update = now;
if (game.game_get_state() == hitcon::tetris::GAME_STATE_GAME_OVER) {
exit(0);
break;
}
}
Expand All @@ -89,48 +92,46 @@ void ioFunction() {
}
}

if (std::fgetc(stdin) != EOF) {
char ch = std::fgetc(stdin);
switch (ch) {
case 'a': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_LEFT);
break;
}

case 'd': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_RIGHT);
break;
}

case 's': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_DOWN);
break;
}

case 'w': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_UP);
break;
}

case 't': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_enemy_attack(2);
break;
}

case 'f': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_FAST_DOWN);
break;
}

default:
break;
char ch = std::fgetc(stdin);
switch (ch) {
case 'a': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_LEFT);
break;
}

case 'd': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_RIGHT);
break;
}

case 's': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_DOWN);
break;
}

case 'w': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_UP);
break;
}

case 't': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_enemy_attack(2);
break;
}

case 'f': {
std::lock_guard<std::mutex> lock(game_mutex);
game.game_on_input(hitcon::tetris::DIRECTION_FAST_DOWN);
break;
}

default:
break;
}
}
}
Expand Down

0 comments on commit 30accc3

Please sign in to comment.