Просмотр исходного кода

Squashed 'yatzee/' changes from a7961c15b..57420f5ef

57420f5ef fix catalog versions
357a9962d categories part 1
1a1ee6bc0 more manifestos, xbox controller and videopoker ufbt fixes
630ed1477 Add Screenshots
2ca302599 API 31 / unzip sources
REVERT: a7961c15b Update README.md
REVERT: d4fcc0b66 Update README.md
REVERT: f5d30350d Update README.md
REVERT: 3b321de9e Update README.md
REVERT: 246d69162 Update README.md
REVERT: 2a3f5bd66 cleanup
REVERT: 0f839056f add_files
REVERT: 222c0c2bb Update README.md
REVERT: fec8cfc85 Update README.md
REVERT: e8b90a1db Update README.md
REVERT: 981d1751f Update README.md
REVERT: c7170c38b Update README.md
REVERT: 276dc25bb Initial commit

git-subtree-dir: yatzee
git-subtree-split: 57420f5efc6ce02bdccb52a5669fee2c74396b94
Willy-JL 2 лет назад
Родитель
Сommit
daab8c5369
4 измененных файлов с 505 добавлено и 455 удалено
  1. 4 1
      application.fam
  2. BIN
      img/1.png
  3. BIN
      img/2.png
  4. 501 454
      yatzee.c

+ 4 - 1
application.fam

@@ -9,5 +9,8 @@ App(
     fap_icon="images/yatzee_icon_10px.png",
     fap_category="Games",
     fap_icon_assets="images",
-
+    fap_author="@emfleak",
+    fap_weburl="https://github.com/emfleak/flipperzero-yatzee",
+    fap_version="1.1",
+    fap_description="Yahtzee game",
 )



+ 501 - 454
yatzee.c

@@ -32,14 +32,13 @@ typedef struct {
     uint8_t y;
 } ImagePosition;
 
-
 typedef struct {
-  char* name;
-  uint32_t value;
-  bool used;
-  int8_t row;
-  int8_t col;
-  uint8_t (*fn)(); // pointer to function that calculates score
+    char* name;
+    uint32_t value;
+    bool used;
+    int8_t row;
+    int8_t col;
+    uint8_t (*fn)(); // pointer to function that calculates score
 } Score;
 
 typedef struct {
@@ -55,49 +54,43 @@ typedef struct {
 
 // locations for the dice images
 ImagePosition position[5] = {
-  {.x = BASE_X-DICE_OFFSET, .y = BASE_Y},
-  {.x = BASE_X*2-DICE_OFFSET, .y = BASE_Y},
-  {.x = BASE_X*3-DICE_OFFSET, .y = BASE_Y},
-  {.x = BASE_X*4-DICE_OFFSET, .y = BASE_Y},
-  {.x = BASE_X*5-DICE_OFFSET, .y = BASE_Y},
+    {.x = BASE_X - DICE_OFFSET, .y = BASE_Y},
+    {.x = BASE_X * 2 - DICE_OFFSET, .y = BASE_Y},
+    {.x = BASE_X * 3 - DICE_OFFSET, .y = BASE_Y},
+    {.x = BASE_X * 4 - DICE_OFFSET, .y = BASE_Y},
+    {.x = BASE_X * 5 - DICE_OFFSET, .y = BASE_Y},
 };
 
 // these are the positions that the score cursor will cycle through
 ImagePosition score_positions[13] = {
-  {.x=15, .y=0},
-  {.x=15, .y=9},
-  {.x=15, .y=18},
-  {.x=15, .y=27},
-  {.x=44, .y=0},
-  {.x=44, .y=9},
-  {.x=44, .y=18},
-  {.x=44, .y=27},
-  {.x=77, .y=0},
-  {.x=77, .y=9},
-  {.x=77, .y=18},
-  {.x=77, .y=27},
-  {.x=91, .y=21},
+    {.x = 15, .y = 0},
+    {.x = 15, .y = 9},
+    {.x = 15, .y = 18},
+    {.x = 15, .y = 27},
+    {.x = 44, .y = 0},
+    {.x = 44, .y = 9},
+    {.x = 44, .y = 18},
+    {.x = 44, .y = 27},
+    {.x = 77, .y = 0},
+    {.x = 77, .y = 9},
+    {.x = 77, .y = 18},
+    {.x = 77, .y = 27},
+    {.x = 91, .y = 21},
 };
 
 // cursor to select dice
-Cursor cursor = {
-  .index = 0,
-  .symbol = "^"
-};
+Cursor cursor = {.index = 0, .symbol = "^"};
 
 // cursor to select score
-Cursor scoreCursor = {
-  .index = -1,
-  .symbol = "_"
-};
+Cursor scoreCursor = {.index = -1, .symbol = "_"};
 
 // setup array to store dice info
 Die die[5] = {
-  {.index = 0, .value = 1, .isHeld = false},
-  {.index = 1, .value = 1, .isHeld = false},
-  {.index = 2, .value = 1, .isHeld = false},
-  {.index = 3, .value = 1, .isHeld = false},
-  {.index = 4, .value = 1, .isHeld = false},
+    {.index = 0, .value = 1, .isHeld = false},
+    {.index = 1, .value = 1, .isHeld = false},
+    {.index = 2, .value = 1, .isHeld = false},
+    {.index = 3, .value = 1, .isHeld = false},
+    {.index = 4, .value = 1, .isHeld = false},
 };
 
 uint8_t upperScore = 0;
@@ -111,63 +104,63 @@ uint8_t totalrolls = 0;
 // # whichever number is mentioned.            #
 // #############################################
 static uint8_t ones() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 1) {
-      sum++;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 1) {
+            sum++;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 static uint8_t twos() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 2) {
-      sum = sum+2;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 2) {
+            sum = sum + 2;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 static uint8_t threes() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 3) {
-      sum = sum+3;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 3) {
+            sum = sum + 3;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 static uint8_t fours() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 4) {
-      sum = sum+4;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 4) {
+            sum = sum + 4;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 static uint8_t fives() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 5) {
-      sum = sum+5;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 5) {
+            sum = sum + 5;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 static uint8_t sixes() {
-  uint8_t sum = 0;
-  for (uint8_t i = 0; i < 5; i++) {
-    if (die[i].value == 6) {
-      sum = sum+6;
+    uint8_t sum = 0;
+    for(uint8_t i = 0; i < 5; i++) {
+        if(die[i].value == 6) {
+            sum = sum + 6;
+        }
     }
-  }
-  return sum;
+    return sum;
 }
 
 // ####################################################
@@ -183,14 +176,15 @@ static uint8_t sixes() {
 // #    output: true if score.used = true
 // # # # # # # # # # # # # # # # # # # # # # # # # # #
 int8_t add_dice() {
-  int8_t sum = 0;
-  for (int8_t i=0; i<MAX_DICE; i++) {
-    sum+=die[i].value;
-  } return sum;
+    int8_t sum = 0;
+    for(int8_t i = 0; i < MAX_DICE; i++) {
+        sum += die[i].value;
+    }
+    return sum;
 }
 
 bool check_if_score_used(Score score) {
-    if (score.used == true) {
+    if(score.used == true) {
         return true;
     } else {
         return false;
@@ -204,87 +198,88 @@ bool check_if_score_used(Score score) {
 // # chance & yatzee.                          #
 // #############################################
 static uint8_t threekind() {
-  int8_t score = 0;
-  for (int8_t num=1; num<7; num++) {
-    int8_t sum = 0;
+    int8_t score = 0;
+    for(int8_t num = 1; num < 7; num++) {
+        int8_t sum = 0;
 
-    for (int8_t i=0; i<MAX_DICE; i++) {
-      if (die[i].value == num) {
-        sum++;
-      }
-      if (sum > 2) {
-        score = add_dice();
-      }
+        for(int8_t i = 0; i < MAX_DICE; i++) {
+            if(die[i].value == num) {
+                sum++;
+            }
+            if(sum > 2) {
+                score = add_dice();
+            }
+        }
     }
-  }
-  return score;
+    return score;
 }
 
 static uint8_t fourkind() {
-  int8_t score = 0;
-  for (int8_t num=1; num<7; num++) {
-    int8_t sum = 0;
+    int8_t score = 0;
+    for(int8_t num = 1; num < 7; num++) {
+        int8_t sum = 0;
 
-    for (int8_t i=0; i<MAX_DICE; i++) {
-      if (die[i].value == num) {
-        sum++;
-      }
-      if (sum > 3) {
-        score = add_dice();
-      }
+        for(int8_t i = 0; i < MAX_DICE; i++) {
+            if(die[i].value == num) {
+                sum++;
+            }
+            if(sum > 3) {
+                score = add_dice();
+            }
+        }
     }
-  }
-  return score;
+    return score;
 }
 
 static uint8_t fullhouse() {
-
-  bool check1 = false;
-  bool check2 = false;
-  int8_t val1 = 0;
-  int8_t val2 = 0;
-  UNUSED(val2);
-  UNUSED(val1);
-
-  //check 1 for three of a kind
-  for (int8_t num=1; num<7; num++) {
-    int8_t sum = 0;
-
-    for (int8_t i=0; i<MAX_DICE; i++) {
-      if (die[i].value == num) {
-        sum++;
-      }
-      if (sum > 2) {
-        val1 = die[i].value;
-        check1 = true;
-      }
+    bool check1 = false;
+    bool check2 = false;
+    int8_t val1 = 0;
+    int8_t val2 = 0;
+    UNUSED(val2);
+    UNUSED(val1);
+
+    //check 1 for three of a kind
+    for(int8_t num = 1; num < 7; num++) {
+        int8_t sum = 0;
+
+        for(int8_t i = 0; i < MAX_DICE; i++) {
+            if(die[i].value == num) {
+                sum++;
+            }
+            if(sum > 2) {
+                val1 = die[i].value;
+                check1 = true;
+            }
+        }
     }
-  }
 
-  // return if check 1 failed
-  if (check1 == false) {
-    return 0;
-  }
+    // return if check 1 failed
+    if(check1 == false) {
+        return 0;
+    }
 
-  // check 2 for two of a kind.
-  for (int8_t num=1; num<7; num++) {
-    if (num==val1) {continue;}
-    int8_t sum = 0;
+    // check 2 for two of a kind.
+    for(int8_t num = 1; num < 7; num++) {
+        if(num == val1) {
+            continue;
+        }
+        int8_t sum = 0;
 
-    for (int8_t i=0; i<MAX_DICE; i++) {
-      if (die[i].value == num) {
-        sum++;
-      }
-      if (sum > 1) {
-        val2 = die[i].value;
-        check2 = true;
-      }
-    }
-    if (check1 && check2) {
-      return 25;
+        for(int8_t i = 0; i < MAX_DICE; i++) {
+            if(die[i].value == num) {
+                sum++;
+            }
+            if(sum > 1) {
+                val2 = die[i].value;
+                check2 = true;
+            }
+        }
+        if(check1 && check2) {
+            return 25;
+        }
     }
-  }
-  return 0;
+    return 0;
 }
 
 // # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -296,23 +291,24 @@ static uint8_t smallstraight() {
     // Create a new array with the frequencies of the different die faces
     int8_t frequencies[6] = {0};
 
-    for (int8_t i = 0; i < 5; i++) {
-      int8_t face = die[i].value;
-      frequencies[face - 1]++;
+    for(int8_t i = 0; i < 5; i++) {
+        int8_t face = die[i].value;
+        frequencies[face - 1]++;
     }
 
     // Check if there is a sequence of 4 consecutive die faces with at least one die
     bool found_small_straight = false;
-    for (int i = 0; i < 3 && !found_small_straight; i++) {
-      if (frequencies[i] > 0 && frequencies[i + 1] > 0 && frequencies[i + 2] > 0 && frequencies[i + 3] > 0) {
-        found_small_straight = true;
-      }
+    for(int i = 0; i < 3 && !found_small_straight; i++) {
+        if(frequencies[i] > 0 && frequencies[i + 1] > 0 && frequencies[i + 2] > 0 &&
+           frequencies[i + 3] > 0) {
+            found_small_straight = true;
+        }
     }
 
-    if (found_small_straight) {
-      return 30;
+    if(found_small_straight) {
+        return 30;
     } else {
-      return 0;
+        return 0;
     }
 }
 
@@ -320,49 +316,50 @@ static uint8_t largestraight() {
     // Create a new array with the frequencies of the different die faces
     int8_t frequencies[6] = {0};
 
-    for (int8_t i = 0; i < 5; i++) {
-      int8_t face = die[i].value;
-      frequencies[face - 1]++;
+    for(int8_t i = 0; i < 5; i++) {
+        int8_t face = die[i].value;
+        frequencies[face - 1]++;
     }
 
     // Check if there is a sequence of 4 consecutive die faces with at least one die
     bool found_large_straight = false;
-    for (int i = 0; i < 3 && !found_large_straight; i++) {
-      if (frequencies[i] > 0 && frequencies[i + 1] > 0 && frequencies[i + 2] > 0 && frequencies[i + 3] > 0 && frequencies[i + 4] > 0) {
-        found_large_straight = true;
-      }
+    for(int i = 0; i < 3 && !found_large_straight; i++) {
+        if(frequencies[i] > 0 && frequencies[i + 1] > 0 && frequencies[i + 2] > 0 &&
+           frequencies[i + 3] > 0 && frequencies[i + 4] > 0) {
+            found_large_straight = true;
+        }
     }
 
-    if (found_large_straight) {
-      return 40;
+    if(found_large_straight) {
+        return 40;
     } else {
-      return 0;
+        return 0;
     }
 }
 
 static uint8_t chance() {
-  // chance allows your roll to count for the raw number of pips showing
-  int8_t sum = 0;
-  for (int8_t i = 0; i<MAX_DICE; i++) {
-    sum+=die[i].value;
-  }
-  return sum;
+    // chance allows your roll to count for the raw number of pips showing
+    int8_t sum = 0;
+    for(int8_t i = 0; i < MAX_DICE; i++) {
+        sum += die[i].value;
+    }
+    return sum;
 }
 
 static uint8_t yatzee() {
-  // checks if all die.values are equal to the first die
-  int8_t val = die[0].value;
-  for (int8_t i=1; i<MAX_DICE; i++) {
-    // if value is the same as the first die, continue to next
-    if (die[i].value == val){
-      continue;
-    } else {
-      // if any value is not equal to the first die,
-      // this is not a yatzee and we return 0
-      return 0;
+    // checks if all die.values are equal to the first die
+    int8_t val = die[0].value;
+    for(int8_t i = 1; i < MAX_DICE; i++) {
+        // if value is the same as the first die, continue to next
+        if(die[i].value == val) {
+            continue;
+        } else {
+            // if any value is not equal to the first die,
+            // this is not a yatzee and we return 0
+            return 0;
+        }
     }
-  }
-  return 50;
+    return 50;
 }
 
 // # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -380,22 +377,21 @@ static uint8_t yatzee() {
 // Scorecard defined here so that we can use pointers to the functions
 // defined above
 Score scorecard[13] = {
-  {.name = "1", .value = 0, .used = false,  .row=0, .col=0, .fn = &ones},
-  {.name = "2", .value = 0, .used = false,  .row=1, .col=0, .fn = &twos},
-  {.name = "3", .value = 0, .used = false,.row=2, .col=0, .fn = &threes},
-  {.name = "4", .value = 0, .used = false, .row=3, .col=0, .fn = &fours},
-  {.name = "5", .value = 0, .used = false, .row=0, .col=1, .fn = &fives},
-  {.name = "6", .value = 0, .used = false, .row=1, .col=1, .fn = &sixes},
-  {.name = "3k", .value = 0, .used = false, .row=2, .col=1, .fn = &threekind},
-  {.name = "4k", .value = 0, .used = false, .row=3, .col=1, .fn = &fourkind},
-  {.name = "Fh", .value = 0, .used = false, .row=0, .col=2, .fn = &fullhouse},
-  {.name = "Sm", .value = 0, .used = false, .row=1, .col=2, .fn = &smallstraight},
-  {.name = "Lg", .value = 0, .used = false, .row=2, .col=2, .fn = &largestraight},
-  {.name = "Ch", .value = 0, .used = false, .row=3, .col=2, .fn = &chance},
-  {.name = "Yz", .value = 0, .used = false, .row = 2, .col = 3, .fn = &yatzee},
+    {.name = "1", .value = 0, .used = false, .row = 0, .col = 0, .fn = &ones},
+    {.name = "2", .value = 0, .used = false, .row = 1, .col = 0, .fn = &twos},
+    {.name = "3", .value = 0, .used = false, .row = 2, .col = 0, .fn = &threes},
+    {.name = "4", .value = 0, .used = false, .row = 3, .col = 0, .fn = &fours},
+    {.name = "5", .value = 0, .used = false, .row = 0, .col = 1, .fn = &fives},
+    {.name = "6", .value = 0, .used = false, .row = 1, .col = 1, .fn = &sixes},
+    {.name = "3k", .value = 0, .used = false, .row = 2, .col = 1, .fn = &threekind},
+    {.name = "4k", .value = 0, .used = false, .row = 3, .col = 1, .fn = &fourkind},
+    {.name = "Fh", .value = 0, .used = false, .row = 0, .col = 2, .fn = &fullhouse},
+    {.name = "Sm", .value = 0, .used = false, .row = 1, .col = 2, .fn = &smallstraight},
+    {.name = "Lg", .value = 0, .used = false, .row = 2, .col = 2, .fn = &largestraight},
+    {.name = "Ch", .value = 0, .used = false, .row = 3, .col = 2, .fn = &chance},
+    {.name = "Yz", .value = 0, .used = false, .row = 2, .col = 3, .fn = &yatzee},
 };
 
-
 // #############################################
 // # begin draw callback                       #
 // #                                           #
@@ -413,168 +409,222 @@ static void app_draw_callback(Canvas* canvas, void* ctx) {
     canvas_clear(canvas);
 
     // if new_game, show user instructions
-    if (new_game) {
-      canvas_set_font(canvas, FontPrimary);
-      elements_multiline_text_aligned(canvas, 64,0, AlignCenter, AlignTop, "Yatzee!");
-      canvas_set_font(canvas, FontSecondary);
-      snprintf(bigbuffer, sizeof(bigbuffer), "Up: Roll\nLeft/Right: Move cursor\nOK: Hold Die\nDown: Score");
-      elements_multiline_text_aligned(canvas, 0, 8, AlignLeft, AlignTop, bigbuffer);
-      elements_button_center(canvas, "Start!");
-      return;
-
+    if(new_game) {
+        canvas_set_font(canvas, FontPrimary);
+        elements_multiline_text_aligned(canvas, 64, 0, AlignCenter, AlignTop, "Yatzee!");
+        canvas_set_font(canvas, FontSecondary);
+        snprintf(
+            bigbuffer,
+            sizeof(bigbuffer),
+            "Up: Roll\nLeft/Right: Move cursor\nOK: Hold Die\nDown: Score");
+        elements_multiline_text_aligned(canvas, 0, 8, AlignLeft, AlignTop, bigbuffer);
+        elements_button_center(canvas, "Start!");
+        return;
 
     } else {
+        // draw border lines
+        canvas_draw_line(canvas, 0, 37, 104, 37);
+        canvas_draw_line(canvas, 104, 0, 104, 64);
+
+        // iterate through dice and draw icon that correlates to die[n].value, and the x,y position indicated by position[die[i].index]
+        for(int8_t i = 0; i < 5; i++) {
+            if(die[i].value == 1) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_1);
+            } else if(die[i].value == 2) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_2);
+            } else if(die[i].value == 3) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_3);
+            } else if(die[i].value == 4) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_4);
+            } else if(die[i].value == 5) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_5);
+            } else if(die[i].value == 6) {
+                canvas_draw_icon(
+                    canvas,
+                    position[die[i].index].x % 128,
+                    position[die[i].index].y % 64,
+                    &I_die_6);
+            }
+        }
+
+        // Puts an '*' above the die if hold is selected.
+        int8_t holdOffsetX = 8;
+        int8_t holdOffsetY = -5;
+        for(int8_t i = 0; i < 5; i++) {
+            if(die[i].isHeld == 1) {
+                elements_multiline_text_aligned(
+                    canvas,
+                    position[die[i].index].x + holdOffsetX,
+                    position[die[i].index].y + holdOffsetY,
+                    AlignCenter,
+                    AlignTop,
+                    HOLD);
+            }
+        }
+
+        // Update die cursor location
+        if(cursor.index != -1) {
+            elements_multiline_text_aligned(
+                canvas,
+                position[cursor.index].x + selectorOffsetX,
+                position[cursor.index].y + selectorOffsetY,
+                AlignCenter,
+                AlignTop,
+                cursor.symbol);
+        }
+
+        // Update score cursor location
+        if(scoreCursor.index != -1) {
+            elements_multiline_text_aligned(
+                canvas,
+                score_positions[scoreCursor.index].x,
+                score_positions[scoreCursor.index].y + 1,
+                AlignLeft,
+                AlignTop,
+                scoreCursor.symbol);
+        }
+
+        // Update Roll
+
+        // Scores are updated in groups on screen to help with formatting
+        // first group is scorecard[0:7], second group is [8:12]
+        // Cycle through first 8 scores, if cursor at score, update to show possible score
+        // otherwise, show current scores value.
+        for(int8_t i = 0; i < 8; i++) {
+            if(scoreCursor.index == i && scorecard[i].used == false) {
+                int possiblescore = (int)(*scorecard[i].fn)();
+
+                snprintf(buffer, sizeof(buffer), "%s: %3u ", scorecard[i].name, possiblescore);
+                canvas_draw_str_aligned(
+                    canvas,
+                    23 + 29 * scorecard[i].col,
+                    9 * scorecard[i].row,
+                    AlignRight,
+                    AlignTop,
+                    buffer);
+            } else {
+                uint8_t currentscore = scorecard[i].value;
+                snprintf(buffer, sizeof(buffer), "%s: %3u ", scorecard[i].name, currentscore);
+                canvas_draw_str_aligned(
+                    canvas,
+                    23 + 29 * scorecard[i].col,
+                    9 * scorecard[i].row,
+                    AlignRight,
+                    AlignTop,
+                    buffer);
+            }
+            if(scorecard[i].used) {
+                canvas_draw_dot(canvas, 23 + 29 * scorecard[i].col, 3 + 9 * scorecard[i].row);
+            }
+        }
+
+        // cycle through lower scores
+        // NUM_SCORES minus one because the yatzee is 12 and is handled separately
+        for(int8_t i = 8; i < NUM_SCORES - 1; i++) {
+            if(scoreCursor.index == i && scorecard[i].used == false) {
+                int possiblescore = (int)(*scorecard[i].fn)();
+
+                snprintf(buffer, sizeof(buffer), " %s: %3u ", scorecard[i].name, possiblescore);
+                canvas_draw_str_aligned(
+                    canvas,
+                    31 + 27 * scorecard[i].col,
+                    9 * scorecard[i].row,
+                    AlignRight,
+                    AlignTop,
+                    buffer);
+            } else {
+                uint8_t currentscore = scorecard[i].value;
+                snprintf(buffer, sizeof(buffer), " %s: %3u ", scorecard[i].name, currentscore);
+                canvas_draw_str_aligned(
+                    canvas,
+                    31 + 27 * scorecard[i].col,
+                    9 * scorecard[i].row,
+                    AlignRight,
+                    AlignTop,
+                    buffer);
+            }
+            if(scorecard[i].used) {
+                canvas_draw_dot(canvas, 31 + 27 * scorecard[i].col, 3 + 9 * scorecard[i].row);
+            }
+        }
+
+        // update yatzee score
+        if(scoreCursor.index == 12 && scorecard[12].used == false) {
+            int possiblescore = (int)(*scorecard[12].fn)();
+
+            snprintf(buffer, sizeof(buffer), "Yz\n%u", possiblescore);
+            elements_multiline_text_aligned(canvas, 93, 10, AlignCenter, AlignTop, buffer);
+        } else {
+            snprintf(buffer, sizeof(buffer), "Yz\n%ld", scorecard[12].value);
+            elements_multiline_text_aligned(canvas, 93, 10, AlignCenter, AlignTop, buffer);
+        }
+
+        // Scores and roll number updated
+
+        // sub score shows the 1-6 scores only. If this is >63 at the end of the game,
+        // a 35 point bonus is added to the total score
+        snprintf(buffer, sizeof(buffer), "Sub\n%u", upperScore);
+        elements_multiline_text_aligned(canvas, 117, 0, AlignCenter, AlignTop, buffer);
+
+        snprintf(buffer, sizeof(buffer), "Total\n%ld", totalScore);
+        elements_multiline_text_aligned(canvas, 117, 22, AlignCenter, AlignTop, buffer);
+
+        if(totalrolls == 0) {
+            snprintf(buffer, sizeof(buffer), "Roll\n%s", " ");
+            elements_multiline_text_aligned(canvas, 117, 64, AlignCenter, AlignBottom, buffer);
+        } else {
+            snprintf(buffer, sizeof(buffer), "Roll\n%u", totalrolls);
+            elements_multiline_text_aligned(canvas, 117, 64, AlignCenter, AlignBottom, buffer);
+        }
+
+        // Check for then handle end of game
+
+        // add num_bonus_yatzees to total rounds so that multiple
+        // yatzees can be scored without impacting the number of rounds before
+        // the game is over
+        int8_t total_rounds = num_bonus_yatzees;
+        // add up number of scores counted so far
+        for(int8_t i = 0; i < NUM_SCORES; i++) {
+            if(scorecard[i].used) {
+                total_rounds++;
+            }
+        }
 
-      // draw border lines
-      canvas_draw_line(canvas, 0, 37, 104, 37);
-      canvas_draw_line(canvas, 104, 0, 104, 64);
-
-      // iterate through dice and draw icon that correlates to die[n].value, and the x,y position indicated by position[die[i].index]
-      for (int8_t i = 0; i < 5; i++) {
-          if (die[i].value == 1) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_1);
-          } else if (die[i].value == 2) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_2);
-          } else if (die[i].value == 3) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_3);
-          } else if (die[i].value == 4) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_4);
-          } else if (die[i].value == 5) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_5);
-          } else if (die[i].value == 6) {
-              canvas_draw_icon(canvas, position[die[i].index].x % 128, position[die[i].index].y % 64, &I_die_6);
-          }
-      }
-
-      // Puts an '*' above the die if hold is selected.
-      int8_t holdOffsetX = 8;
-      int8_t holdOffsetY = -5;
-      for (int8_t i = 0; i < 5; i++) {
-          if (die[i].isHeld == 1) {
-              elements_multiline_text_aligned(
-                  canvas, position[die[i].index].x+holdOffsetX,
-                    position[die[i].index].y+holdOffsetY, AlignCenter, AlignTop, HOLD);
-          }
-      }
-
-      // Update die cursor location
-      if (cursor.index != -1) {
-          elements_multiline_text_aligned(
-              canvas, position[cursor.index].x+selectorOffsetX,
-                position[cursor.index].y+selectorOffsetY, AlignCenter, AlignTop, cursor.symbol);
-      }
-
-      // Update score cursor location
-      if (scoreCursor.index != -1) {
-          elements_multiline_text_aligned(
-              canvas, score_positions[scoreCursor.index].x,
-                score_positions[scoreCursor.index].y+1, AlignLeft, AlignTop, scoreCursor.symbol);
-      }
-
-      // Update Roll
-
-
-      // Scores are updated in groups on screen to help with formatting
-      // first group is scorecard[0:7], second group is [8:12]
-      // Cycle through first 8 scores, if cursor at score, update to show possible score
-      // otherwise, show current scores value.
-      for (int8_t i = 0; i < 8; i++) {
-          if (scoreCursor.index == i && scorecard[i].used == false) {
-              int possiblescore = (int)(*scorecard[i].fn)();
-
-              snprintf(buffer, sizeof(buffer), "%s: %3u ", scorecard[i].name, possiblescore);
-              canvas_draw_str_aligned(canvas, 23+29*scorecard[i].col,
-                    9*scorecard[i].row, AlignRight, AlignTop, buffer);
-          } else {
-
-              uint8_t currentscore = scorecard[i].value;
-              snprintf(buffer, sizeof(buffer), "%s: %3u ", scorecard[i].name, currentscore);
-              canvas_draw_str_aligned(canvas, 23+29*scorecard[i].col,
-                    9*scorecard[i].row, AlignRight, AlignTop, buffer);
-          }
-          if (scorecard[i].used) {
-              canvas_draw_dot(canvas, 23+29*scorecard[i].col, 3+9*scorecard[i].row);
-          }
-      }
-
-      // cycle through lower scores
-      // NUM_SCORES minus one because the yatzee is 12 and is handled separately
-      for (int8_t i = 8; i < NUM_SCORES-1; i++) {
-          if (scoreCursor.index == i && scorecard[i].used == false) {
-              int possiblescore = (int)(*scorecard[i].fn)();
-
-              snprintf(buffer, sizeof(buffer), " %s: %3u ", scorecard[i].name, possiblescore);
-              canvas_draw_str_aligned(canvas, 31+27*scorecard[i].col,
-                    9*scorecard[i].row, AlignRight, AlignTop, buffer);
-          } else {
-              uint8_t currentscore = scorecard[i].value;
-              snprintf(buffer, sizeof(buffer), " %s: %3u ", scorecard[i].name, currentscore);
-              canvas_draw_str_aligned(canvas, 31+27*scorecard[i].col,
-                    9*scorecard[i].row, AlignRight, AlignTop, buffer);
-          }
-          if (scorecard[i].used) {
-              canvas_draw_dot(canvas, 31+27*scorecard[i].col, 3+9*scorecard[i].row);
-          }
-      }
-
-      // update yatzee score
-      if (scoreCursor.index == 12 && scorecard[12].used == false) {
-          int possiblescore = (int)(*scorecard[12].fn)();
-
-          snprintf(buffer, sizeof(buffer), "Yz\n%u", possiblescore);
-          elements_multiline_text_aligned(canvas, 93, 10, AlignCenter, AlignTop, buffer);
-      } else {
-          snprintf(buffer, sizeof(buffer), "Yz\n%ld", scorecard[12].value);
-          elements_multiline_text_aligned(canvas, 93, 10, AlignCenter, AlignTop, buffer);
-      }
-
-
-      // Scores and roll number updated
-
-      // sub score shows the 1-6 scores only. If this is >63 at the end of the game,
-      // a 35 point bonus is added to the total score
-      snprintf(buffer, sizeof(buffer), "Sub\n%u", upperScore);
-      elements_multiline_text_aligned(canvas, 117, 0, AlignCenter, AlignTop, buffer);
-
-      snprintf(buffer, sizeof(buffer), "Total\n%ld", totalScore);
-      elements_multiline_text_aligned(canvas, 117, 22, AlignCenter, AlignTop, buffer);
-
-      if (totalrolls == 0) {
-          snprintf(buffer, sizeof(buffer), "Roll\n%s", " ");
-          elements_multiline_text_aligned(canvas, 117, 64, AlignCenter, AlignBottom, buffer);
-      } else {
-          snprintf(buffer, sizeof(buffer), "Roll\n%u", totalrolls);
-          elements_multiline_text_aligned(canvas, 117, 64, AlignCenter, AlignBottom, buffer);
-      }
-
-      // Check for then handle end of game
-
-      // add num_bonus_yatzees to total rounds so that multiple
-      // yatzees can be scored without impacting the number of rounds before
-      // the game is over
-      int8_t total_rounds = num_bonus_yatzees;
-      // add up number of scores counted so far
-      for (int8_t i = 0; i<NUM_SCORES; i++) {
-          if (scorecard[i].used) {
-              total_rounds++;
-          }
-      }
-
-      // if total rounds is 13 + the number of bonus rounds,
-      // thats it, game over.
-      if (total_rounds == NUM_SCORES+num_bonus_yatzees) {
-          // if scores of 1-6 add up to 63, a 35 point bonus is bonus_added
-          // bonus_added = true keeps the game loop from
-          // adding bonuses indefinetly
-          if (upperScore >= 63 && bonus_added == false) {
-            totalScore+=35;
-            bonus_added = true;
-          }
-          // set game over to true and tell the user the game is over
-          game_over = true;
-          elements_button_center(canvas, "Game Over");
+        // if total rounds is 13 + the number of bonus rounds,
+        // thats it, game over.
+        if(total_rounds == NUM_SCORES + num_bonus_yatzees) {
+            // if scores of 1-6 add up to 63, a 35 point bonus is bonus_added
+            // bonus_added = true keeps the game loop from
+            // adding bonuses indefinetly
+            if(upperScore >= 63 && bonus_added == false) {
+                totalScore += 35;
+                bonus_added = true;
+            }
+            // set game over to true and tell the user the game is over
+            game_over = true;
+            elements_button_center(canvas, "Game Over");
+        }
     }
-  }
 }
 
 // define the callback for helping ViewPort get InputEvent and place it in the event_queue defined in the main method
@@ -589,9 +639,9 @@ static void app_input_callback(InputEvent* input_event, void* ctx) {
 static void roll_dice() {
     // increment roll count
     totalrolls++;
-    for (uint8_t i = 0; i < MAX_DICE; i++) {
+    for(uint8_t i = 0; i < MAX_DICE; i++) {
         // dont reroll if the dice is being held
-        if (die[i].isHeld == false) {
+        if(die[i].isHeld == false) {
             die[i].value = 1 + rand() % 6;
         }
     }
@@ -602,46 +652,47 @@ static void roll_dice() {
 }
 
 static void clear_board() {
-  // reset board after adding score
-  totalrolls = 0;
-  for (int8_t i=0; i < MAX_DICE; i++) {
-      die[i].isHeld = false;
-  }
-  scoreCursor.index = -1;
-  cursor.index = 0;
+    // reset board after adding score
+    totalrolls = 0;
+    for(int8_t i = 0; i < MAX_DICE; i++) {
+        die[i].isHeld = false;
+    }
+    scoreCursor.index = -1;
+    cursor.index = 0;
 }
 
 static void add_score() {
     // return when scoring is not possible
-    if (cursor.index != -1 || totalrolls == 0 || (scorecard[scoreCursor.index].used && strcmp(scorecard[scoreCursor.index].name,"Yz")!=0)){
+    if(cursor.index != -1 || totalrolls == 0 ||
+       (scorecard[scoreCursor.index].used &&
+        strcmp(scorecard[scoreCursor.index].name, "Yz") != 0)) {
         return;
     }
 
     // extra yatzee scores
-    if (scoreCursor.index == 12 && scorecard[scoreCursor.index].used) {
-              uint8_t yatzee_score = (*scorecard[12].fn)();
-              scorecard[12].value += 2*yatzee_score;
-              lowerScore+=100;
-              num_bonus_yatzees++;
-      }
-
+    if(scoreCursor.index == 12 && scorecard[scoreCursor.index].used) {
+        uint8_t yatzee_score = (*scorecard[12].fn)();
+        scorecard[12].value += 2 * yatzee_score;
+        lowerScore += 100;
+        num_bonus_yatzees++;
+    }
 
     // upper score
-    for (int8_t i = 0; i < 6; i++) {
-        if (scoreCursor.index == i && scorecard[scoreCursor.index].used == false) {
-            scorecard[i].value =(*scorecard[i].fn)();
-            upperScore+=scorecard[i].value;
+    for(int8_t i = 0; i < 6; i++) {
+        if(scoreCursor.index == i && scorecard[scoreCursor.index].used == false) {
+            scorecard[i].value = (*scorecard[i].fn)();
+            upperScore += scorecard[i].value;
             scorecard[i].used = true;
         }
     }
 
     // lower score
-    for (int8_t i = 6; i < 13; i++) {
-        if (scoreCursor.index == i && scorecard[scoreCursor.index].used == false) {
+    for(int8_t i = 6; i < 13; i++) {
+        if(scoreCursor.index == i && scorecard[scoreCursor.index].used == false) {
             scorecard[i].value = (*scorecard[i].fn)();
-            lowerScore+=scorecard[i].value;
+            lowerScore += scorecard[i].value;
             scorecard[i].used = true;
-      }
+        }
     }
 
     // recalculate total score
@@ -649,9 +700,6 @@ static void add_score() {
     clear_board();
 }
 
-
-
-
 // Entry Point
 int32_t yatzee_main(void* p) {
     UNUSED(p);
@@ -679,90 +727,89 @@ int32_t yatzee_main(void* p) {
     bool isRunning = true;
 
     while(isRunning) {
-
-      if (totalrolls == 3) {
-        cursor.index = -1;
-      }
+        if(totalrolls == 3) {
+            cursor.index = -1;
+        }
         if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
             if((event.type == InputTypePress) || event.type == InputTypeRepeat) {
                 switch(event.key) {
-                    case InputKeyLeft:
-                        if(cursor.index == -1) {
-                            if(scoreCursor.index == 0 && totalrolls == 3){
-                              scoreCursor.index = NUM_SCORES-1;
-                            } else if (scoreCursor.index==0) {
-                                scoreCursor.index = -1;
-                                cursor.index = 4;
-                            } else {
-                                scoreCursor.index--;
-                            }
+                case InputKeyLeft:
+                    if(cursor.index == -1) {
+                        if(scoreCursor.index == 0 && totalrolls == 3) {
+                            scoreCursor.index = NUM_SCORES - 1;
+                        } else if(scoreCursor.index == 0) {
+                            scoreCursor.index = -1;
+                            cursor.index = 4;
                         } else {
-                            if(cursor.index == 0) {
-                                cursor.index = -1;
-                                scoreCursor.index = NUM_SCORES-1;
-                            } else {
-                                cursor.index--;
-                            }
+                            scoreCursor.index--;
                         }
-                        break;
-                    case InputKeyRight:
-                        // cursor.index == -1 means that scoreCursor is active
-                        if(cursor.index == -1) {
-                            if(scoreCursor.index == NUM_SCORES-1 && totalrolls == 3){
-                                scoreCursor.index = 0;
-                            } else if (scoreCursor.index == NUM_SCORES-1) {
-                                scoreCursor.index = -1;
-                                cursor.index = 0;
-                            } else {
-                                scoreCursor.index++;
-                            }
-                        // if cursor.index is not -1, then dice cursor is active
+                    } else {
+                        if(cursor.index == 0) {
+                            cursor.index = -1;
+                            scoreCursor.index = NUM_SCORES - 1;
                         } else {
-                            if(cursor.index == 4) {
-                                cursor.index = -1;
-                                scoreCursor.index = 0;
-                            } else {
-                                cursor.index++;
-                            }
-                        }
-                        break;
-                    case InputKeyUp:
-
-                        if (totalrolls < 3) {
-                            roll_dice();
-                        }
-                        // if (check_for_bonus_yatzee() && scorecard[13].used) {
-                        //   num_bonus_yatzees++;
-                        //   totalScore+=100;
-                        //
-                        //   clear_board();
-                        // }
-                        break;
-                    case InputKeyDown:
-                        add_score();
-                        break;
-                    case InputKeyOk:
-                        if (new_game) {
-                          new_game = false;
-                          break;
-                        }
-                        if (game_over) {
-                          isRunning = false;
+                            cursor.index--;
                         }
-                        if (cursor.index == -1 || totalrolls == 0) {
-                            break;
+                    }
+                    break;
+                case InputKeyRight:
+                    // cursor.index == -1 means that scoreCursor is active
+                    if(cursor.index == -1) {
+                        if(scoreCursor.index == NUM_SCORES - 1 && totalrolls == 3) {
+                            scoreCursor.index = 0;
+                        } else if(scoreCursor.index == NUM_SCORES - 1) {
+                            scoreCursor.index = -1;
+                            cursor.index = 0;
+                        } else {
+                            scoreCursor.index++;
                         }
-                        if (die[cursor.index].isHeld == false) {
-                            die[cursor.index].isHeld = true;
+                        // if cursor.index is not -1, then dice cursor is active
+                    } else {
+                        if(cursor.index == 4) {
+                            cursor.index = -1;
+                            scoreCursor.index = 0;
                         } else {
-                            die[cursor.index].isHeld = false;
+                            cursor.index++;
                         }
-                      break;
-                    default:
+                    }
+                    break;
+                case InputKeyUp:
+
+                    if(totalrolls < 3) {
+                        roll_dice();
+                    }
+                    // if (check_for_bonus_yatzee() && scorecard[13].used) {
+                    //   num_bonus_yatzees++;
+                    //   totalScore+=100;
+                    //
+                    //   clear_board();
+                    // }
+                    break;
+                case InputKeyDown:
+                    add_score();
+                    break;
+                case InputKeyOk:
+                    if(new_game) {
+                        new_game = false;
+                        break;
+                    }
+                    if(game_over) {
                         isRunning = false;
+                    }
+                    if(cursor.index == -1 || totalrolls == 0) {
                         break;
+                    }
+                    if(die[cursor.index].isHeld == false) {
+                        die[cursor.index].isHeld = true;
+                    } else {
+                        die[cursor.index].isHeld = false;
+                    }
+                    break;
+                default:
+                    isRunning = false;
+                    break;
+                }
             }
-          }
         }
         // after every event, update view_port
         // uses app_draw_callback which is set before the game loop begins.