Projekt/snake_main.c
void game_over(){
  set_all_pixels_black();
  display_buffer();
  
  
  //check if its the first time we run the game is so set high score to 0
  uint8_t first_time_run = read_byte_from_eeprom(FIRST_TIME_LAUNCH_ADDRESS);
  if(first_time_run != 0xFF){
    //this is the first time we run the program
    write_byte_to_eeprom(FIRST_TIME_LAUNCH_ADDRESS,0xFF);//set first_time_run
    write_byte_to_eeprom(HIGH_SCORE_ADDRESS,0);//set high score
  }
  //read highscore
  uint8_t high_score = read_byte_from_eeprom(HIGH_SCORE_ADDRESS);
  

  char score_string[18]; //holds the score string
  char high_score_string[18]; //holds the score string
  sprintf(score_string, "Score: %d!",snake.num_apples_eaten); //format the score string
  sprintf(high_score_string, "High Score: %d!",snake.num_apples_eaten > high_score ? snake.num_apples_eaten : high_score); //format the score string
  bool new_high_score = false;
  //if we beat the high score update it
  if(snake.num_apples_eaten > high_score){
    write_byte_to_eeprom(HIGH_SCORE_ADDRESS,snake.num_apples_eaten);
    new_high_score = true;
  }
  
  while (true)
  {
      
      display_string(0, "game over!");
      display_string(1, score_string);
      display_string(2, high_score_string);
      if(new_high_score){
        display_string(3,"yay new record!");
      }
      
    
      
      //display_string(3, "highscore: %d",snake.num_apples_eaten);

  }
  
}
/*called when the player loses the game - just infinitly prints game over, the score and the high score*/
called when the player loses the game - just infinitly prints game over, the score and the high score
called when the player loses the game - just infinitly prints game over the score and the high score
void game_over(){
  set_all_pixels_black();
  display_buffer();
  uint8_t first_time_run = read_byte_from_eeprom(FIRST_TIME_LAUNCH_ADDRESS);
  if(first_time_run != 0xFF){
    write_byte_to_eeprom(FIRST_TIME_LAUNCH_ADDRESS,0xFF);
    write_byte_to_eeprom(HIGH_SCORE_ADDRESS,0);
  }
  uint8_t high_score = read_byte_from_eeprom(HIGH_SCORE_ADDRESS);
  char score_string[18]; 
  char high_score_string[18]; 
  sprintf(score_string, "Score: %d!",snake.num_apples_eaten); 
  sprintf(high_score_string, "High Score: %d!",snake.num_apples_eaten > high_score ? snake.num_apples_eaten : high_score); 
  bool new_high_score = false;
  if(snake.num_apples_eaten > high_score){
    write_byte_to_eeprom(HIGH_SCORE_ADDRESS,snake.num_apples_eaten);
    new_high_score = true;
  }
  while (true)
  {
      display_string(0, "game over!");
      display_string(1, score_string);
      display_string(2, high_score_string);
      if(new_high_score){
        display_string(3,"yay new record!");
      }
  }
}
void game_over ( ) { set_all_pixels_black ( ) ; display_buffer ( ) ; uint8_t first_time_run = read_byte_from_eeprom ( FIRST_TIME_LAUNCH_ADDRESS ) ; if ( first_time_run != 0xFF ) { write_byte_to_eeprom ( FIRST_TIME_LAUNCH_ADDRESS , 0xFF ) ; write_byte_to_eeprom ( HIGH_SCORE_ADDRESS , 0 ) ; } uint8_t high_score = read_byte_from_eeprom ( HIGH_SCORE_ADDRESS ) ; char score_string [ 18 ] ; char high_score_string [ 18 ] ; sprintf ( score_string , " " , snake . num_apples_eaten ) ; sprintf ( high_score_string , " " , snake . num_apples_eaten > high_score ? snake . num_apples_eaten : high_score ) ; bool new_high_score = false ; if ( snake . num_apples_eaten > high_score ) { write_byte_to_eeprom ( HIGH_SCORE_ADDRESS , snake . num_apples_eaten ) ; new_high_score = true ; } while ( true ) { display_string ( 0 , " " ) ; display_string ( 1 , score_string ) ; display_string ( 2 , high_score_string ) ; if ( new_high_score ) { display_string ( 3 , " " ) ; } } }
called when the player loses the game - just infinitly prints game over, the score and the high score
called when the player loses the game - just infinitly prints game over the score and the high score
//check if its the first time we run the game is so set high score to 0 //this is the first time we run the program //set first_time_run //set high score //read highscore //holds the score string //holds the score string //format the score string //format the score string //if we beat the high score update it //display_string(3, "highscore: %d",snake.num_apples_eaten);