Skip to content

Commit 2864e46

Browse files
authored
Merge pull request #133 from DevMilanIan/unleashed
Feature: game_2048 hold center to restart
2 parents 5f51e0d + b110f4e commit 2864e46

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

applications/game2048/game_2048.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,21 @@ static void game_2048_process_move(GameState* const game_state) {
323323
// </debug>
324324
}
325325

326+
static void game_2048_restart(GameState* const game_state) {
327+
// clear all cells
328+
for(uint8_t y = 0; y < 4; y++) {
329+
for(uint8_t x = 0; x < 4; x++) {
330+
game_state->field[y][x] = 0;
331+
}
332+
}
333+
334+
// start next game
335+
game_2048_set_new_number(game_state);
336+
game_2048_set_new_number(game_state);
337+
}
338+
326339
int32_t game_2048_app(void* p) {
340+
UNUSED(p);
327341
int32_t return_code = 0;
328342

329343
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
@@ -377,7 +391,7 @@ int32_t game_2048_app(void* p) {
377391
GameState* game_state = (GameState*)acquire_mutex_block(&state_mutex);
378392

379393
if(event_status == FuriStatusOk) {
380-
if(event.type == InputTypePress) {
394+
if(event.type == InputTypeShort) {
381395
switch(event.key) {
382396
case InputKeyUp:
383397
game_state->direction = DirectionUp;
@@ -399,12 +413,18 @@ int32_t game_2048_app(void* p) {
399413
game_2048_process_move(game_state);
400414
game_2048_set_new_number(game_state);
401415
break;
402-
case InputKeyOk:; // TODO: reinit in game ower state
416+
case InputKeyOk:
417+
game_state->direction = DirectionIdle;
403418
break;
404419
case InputKeyBack:
405420
loop = false;
406421
break;
407422
}
423+
} else if(event.type == InputTypeLong) {
424+
if(event.key == InputKeyOk) {
425+
game_state->direction = DirectionIdle;
426+
game_2048_restart(game_state);
427+
}
408428
}
409429
}
410430

@@ -423,4 +443,4 @@ int32_t game_2048_app(void* p) {
423443
furi_message_queue_free(event_queue);
424444

425445
return return_code;
426-
}
446+
}

0 commit comments

Comments
 (0)