Ejemplo n.º 1
0
void md12_main(void) {
	switch (next_state) {
		
		case STATE_MENU:
			switch(create_dialog(MP3_MENU, DOT_1 | DOT_2 | ENTER_CANCEL)) {
				
				case NO_DOTS:
					break;

				case '1':
					PRINTF("[MD12] Submode: Learn\n\r");
					play_mp3(MODE_FILESET, MP3_INSTRUCTIONS);
					submode = SUBMODE_LEARN;
					next_state = STATE_GENQUES;
					break;

				case '2':
					PRINTF("[MD12] Submode: Play\n\r");
					play_mp3(MODE_FILESET, MP3_INSTRUCTIONS);
					submode = SUBMODE_PLAY;
					next_state = STATE_GENQUES;
					break;

				case CANCEL:
					PRINTF("[MD12] Quitting to main menu\n\r");
					quit_mode();
					break;

				case ENTER:
					PRINTF("[MD12] Re-issuing main menu prompt\n\r");
					next_state = STATE_MENU;
					break;

				default:
					break;			
			}
			break;

		case STATE_GENQUES:
			switch (submode) {

				case SUBMODE_LEARN:
					curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
					if (curr_glyph == NULL) {
						reset_script_indices(SCRIPT_ADDRESS);
						next_state = STATE_GENQUES;
						break;
					}
					break;

				case SUBMODE_PLAY:
					curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
					break;

				default:
					break;

			}
			sprintf(dbgstr, "[MD12] Next glyph: %s\n\r", curr_glyph->sound);
			PRINTF(dbgstr);
			play_mp3(LANG_FILESET, MP3_NEXT_LETTER);
			next_state = STATE_PROMPT;
			break;

		case STATE_PROMPT:
			switch(submode) {

				case SUBMODE_LEARN:
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					break;

				case SUBMODE_PLAY:
					play_silence(500);
					play_glyph(curr_glyph);
					break;

				default:
					break;
			}
			next_state = STATE_INPUT;
			break;

		case STATE_INPUT:
			if (io_user_abort == true) {
				PRINTF("[MD12] User aborted input\n\r");
				next_state = STATE_REPROMPT;
				io_init();
			}
			if (get_character(&user_glyph) == true) {
				PRINTF("[MD12] Valid character received\n\r");
				next_state = STATE_CHECK;
				io_init();
			}
			break;

		case STATE_CHECK:
			if (glyph_equals(curr_glyph, user_glyph)) {
				incorrect_tries = 0;
				PRINTF("[MD12] User answered correctly\n\r");
				play_mp3(LANG_FILESET, MP3_CORRECT);
				play_mp3(SYS_FILESET, MP3_TADA);
				next_state = STATE_GENQUES;
			} else {
				incorrect_tries++;
				PRINTF("[MD12] User answered incorrectly\n\r");
				play_mp3(LANG_FILESET, MP3_INCORRECT);
				play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
				next_state = STATE_PROMPT;
				if (incorrect_tries >= MAX_INCORRECT_TRIES) {
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
					next_state = STATE_INPUT;
				}
			}
			break;

		case STATE_REPROMPT:
			switch(create_dialog(MP3_REPROMPT,
				DOT_1 | DOT_2 | DOT_3 | ENTER_CANCEL | LEFT_RIGHT)) {
				case NO_DOTS:
					break;

				case '1':
					PRINTF("[MD12] Skipping character\n\r");
					next_state = STATE_GENQUES;
					break;

				case '2':
					PRINTF("[MD12] Playing pattern\n\r");
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
					next_state = STATE_INPUT;
					break;

				case '3':
					PRINTF("[MD12] Reissuing prompt\n\r");
					next_state = STATE_PROMPT;
					break;

				case CANCEL:
					PRINTF("[MD12] Cancelling to submode menu\n\r");
					md12_reset();
					break;

				case ENTER:
					PRINTF("[MD12] Reissuing prompt\n\r");
					next_state = STATE_PROMPT;
					break;

				case LEFT:
					PRINTF("[MD12] Previous letter\n\r");
					switch (submode) {
						case SUBMODE_LEARN:
							curr_glyph = get_prev_glyph(SCRIPT_ADDRESS);
							if (curr_glyph == NULL) {
								curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
							}
							break;
						case SUBMODE_PLAY:
							curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
							break;
						default:
							break;
					}
					play_glyph(curr_glyph);
					break;

				case RIGHT:
					PRINTF("[MD12] Next letter\n\r");
					switch (submode) {
						case SUBMODE_LEARN:
							curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
							if (curr_glyph == NULL) {
								curr_glyph = get_prev_glyph(SCRIPT_ADDRESS);
							}
							break;
						case SUBMODE_PLAY:
							curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
							break;
						default:
							break;
					}
					play_glyph(curr_glyph);
					break;

				default:
					break;
			}
			break;

		default:
			break;
	}
}
Ejemplo n.º 2
0
/**
 * @brief  Step through the main stages in the code.
 * @return Void
 */
void sound_game_main(script_t* SCRIPT_ADDRESS, char* LANG_FILESET, char* MODE_FILESET)
{
  switch(next_state)
  {
    case STATE_MENU:
	  if (io_user_abort == true) {
		  PRINTF("[MD3] Quitting to main menu\n\r");
		  quit_mode();
		  io_init();
	  }
	  cell = get_cell();
	  if (cell == NO_DOTS) {
		  break;	
	  }
	  cell_pattern = GET_CELL_PATTERN(cell);
	  cell_control = GET_CELL_CONTROL(cell);
	  switch (cell_control) {
		  /*If user input is A, enter SUBMODE_PLAY; if input is B, enter SUBMODE_LEARN; 
			else go back to menu*/
		  case WITH_ENTER:
		    user_glyph = search_script(this_script, cell_pattern);
			if (cell_pattern == ENG_A) {
			    play_glyph(user_glyph);
				submode = SUBMODE_PLAY;
				next_state = STATE_GENQUES;
			} else if (cell_pattern == ENG_B) {
				play_glyph(user_glyph);
				submode = SUBMODE_LEARN;
				next_state = STATE_GENQUES;
			} else {
				play_mp3(lang_fileset, MP3_INVALID_PATTERN);
				next_state = STATE_MENU;
			}
		  break;
		  case WITH_LEFT:case WITH_RIGHT:case WITH_CANCEL:
		  break;
	  }
	break;
	  
	case STATE_GENQUES:
	  length_entered_word = 0;
	  current_word_index = 0;
	  sound_source = sound_source_list[choose_sound_source()];
	  user_glyph = NULL;
	  curr_glyph = NULL;
      user_word = free_word(user_word);
	  curr_word = free_word(curr_word);
	  next_state = STATE_PROMPT;
	  break;
	  
    case STATE_PROMPT:
	  switch(submode)
	  {
        case SUBMODE_PLAY:
		  play_mp3(MODE_FILESET, "PLSA");
		  play_sound(MODE_FILESET, sound_source, false);
		  break;
		
		case SUBMODE_LEARN:
	      play_mp3(MODE_FILESET, "PLSB");
		  play_sound(MODE_FILESET, sound_source, true);
		  break;
	    
		default:
		  break;  
	  }
	next_state = STATE_INPUT;
	break;
	
	case STATE_INPUT:
	if (io_user_abort == true) {
		PRINTF("[MD3] User aborted input\n\r");
		next_state = STATE_REPROMPT;
		io_init();
	}
	cell = get_cell();
	if (cell == NO_DOTS) {
		break;
	}
	cell_pattern = GET_CELL_PATTERN(cell);
	cell_control = GET_CELL_CONTROL(cell);
	switch (cell_control) {
		case WITH_ENTER:
		user_glyph = search_script(this_script, cell_pattern);
		next_state = STATE_CHECK;
		PRINTF("[MD3] Checking answer\n\r");
		break;
		case WITH_LEFT:
		next_state = STATE_PROMPT;
		break;
		case WITH_RIGHT:
		next_state = STATE_REPROMPT;
		break;
		case WITH_CANCEL:
		break;
	}
	break;

	case STATE_CHECK:
		curr_glyph = search_script(this_script, get_bits_from_letter(sound_source[length_entered_word]));
		if (glyph_equals(curr_glyph, user_glyph)) {
			play_glyph(curr_glyph);
			incorrect_tries = 0;
			length_entered_word++;
			user_word = add_glyph_to_word(user_word, user_glyph);
			if(length_entered_word != strlen(sound_source)) {
			  play_mp3(lang_fileset, "GOOD");
			  next_state = STATE_INPUT;
			} else { 
			  play_mp3(lang_fileset,  "GOOD");
			  play_mp3(lang_fileset, "NCWK");
			  switch (submode){
				  case SUBMODE_LEARN:
				  play_sound(MODE_FILESET, sound_source, true);
				  play_mp3(MODE_FILESET, "SAYS");
				  play_sound(MODE_FILESET, sound_source, false);
				  break;
				  
				  case SUBMODE_PLAY:
				  play_word(user_word);
				  play_sound(MODE_FILESET, sound_source, true);
			  }
			  next_state = STATE_GENQUES;
			}
		} else {
			play_glyph(user_glyph);
			incorrect_tries++;
			PRINTF("[MD3] User answered incorrectly\n\r");
			play_mp3(lang_fileset, "NO");
			play_mp3(lang_fileset, MP3_TRY_AGAIN);
			play_word(user_word);
			if (incorrect_tries == MAX_INCORRECT_TRIES_1) {
				play_mp3(MODE_FILESET, "PLWR");
				play_sound(MODE_FILESET, sound_source, true);
				curr_word = word_to_glyph_word(this_script, sound_source);
				play_word(curr_word);
			} else if (incorrect_tries >= 6) {
				play_glyph(curr_glyph);
				play_mp3(MODE_FILESET, "PRSS");
				play_dot_sequence(curr_glyph);
			}
			next_state = STATE_INPUT;
		}
		break;
	
	case STATE_REPROMPT:
	switch(create_dialog("SKIP",
	ENTER_CANCEL | LEFT_RIGHT)) {
		case NO_DOTS:
		break;

		case CANCEL:
		PRINTF("[MD3] Reissuing prompt");
		next_state = STATE_PROMPT;
		scrolled = false;
		break;

		case ENTER:
		PRINTF("[MD3] Skipping sound_source");
		if (scrolled)
		next_state = STATE_PROMPT;
		else
		next_state = STATE_GENQUES;
		scrolled = false;
		break;

		case RIGHT: case LEFT:
			PRINTF("[MD3] Next sound_source");
			length_entered_word = 0;
			current_word_index = 0;
			sound_source = sound_source_list[choose_sound_source()];
			user_word = NULL;
			switch(submode)
			{
				case SUBMODE_PLAY:
				play_sound(MODE_FILESET, sound_source, false);
				break;
				
				case SUBMODE_LEARN:
				play_sound(MODE_FILESET, sound_source, true);
				break;
				
				default:
				break;
			}
			scrolled = true;
		break;

		default:
		break;
	}
	break;

	default:
	break;
  }
}
void mode_letter_game_main() {
    switch (current_state) {

        case INITIAL:
            play_welcome();
            play_submode_choice();
            current_state = CHOOSE_LEVEL;
            break;

        case CHOOSE_LEVEL:

            switch(create_dialog(NULL, DOT_1 | DOT_2 | ENTER_CANCEL)) {
                case '1':
                    log_msg("Submode: Learn");
                    play_letter_instructions();
                    submode = SUBMODE_LEARN;
                    sort(this_script->letters, this_script->num_letters);
                    current_state = GENERATE_QUESTION;
                    break;

                case '2':
                    log_msg("Submode: Play");
                    play_letter_instructions();
                    shuffle(this_script->letters, this_script->num_letters);
                    should_shuffle = true;
                    current_state = GENERATE_QUESTION;
                    break;

                case CANCEL:
                    log_msg("Quitting to main menu");                    
                    quit_mode();
                    break;

                case ENTER:
                    log_msg("Re-issuing main menu prompt");
                    play_submode_choice();
                    current_state = CHOOSE_LEVEL;
                    break;

                default:
                    break;
            }
            break;


        case GENERATE_QUESTION:
            curr_glyph = get_next_letter(this_script, should_shuffle);
            log_msg("Next glyph: %s", curr_glyph->sound);
            play_next_letter_prompt();
            current_state = PROMPT;
            break;


        case PROMPT:
            play_glyph(curr_glyph);
            switch(submode) {
                case SUBMODE_LEARN:
                    play_dot_prompt();
                    play_dot_sequence(curr_glyph);
                    break;

                case SUBMODE_PLAY:
                default:
                    break;
            }
            current_state = GET_INPUT;
            break;

        case GET_INPUT:
            if (io_user_abort == true) {
                log_msg("User aborted input");
                current_state = PROMPT;
                io_init();
            }

            cell = get_cell();
            if (cell == NO_DOTS)
                break;
            cell_pattern = GET_CELL_PATTERN(cell);
            cell_control = GET_CELL_CONTROL(cell);
            log_msg("Pattern %d, control %d.", cell_pattern, cell_control);
            
            switch (cell_control) {
                case WITH_ENTER:
                    user_glyph = search_script(this_script, cell_pattern);
                    current_state = CHECK_ANSWER;
                    break;
                case WITH_LEFT:
                    current_state = PROMPT;
                    break;
                case WITH_RIGHT:
                    current_state = GENERATE_QUESTION;
                    break;
                case WITH_CANCEL:
                default:
                    break;

            }
            break;

        case CHECK_ANSWER:
            if (glyph_equals(curr_glyph, user_glyph)) {
                if (curr_glyph -> next == NULL) {
                    mistakes = 0;
                    log_msg("User answered correctly");
                    play_right();
                    current_state = GENERATE_QUESTION;
                }
                else {
                    curr_glyph = curr_glyph->next;
                    play_next_cell_prompt();                    
                    if (submode == SUBMODE_LEARN)
                        play_dot_sequence(curr_glyph);
                    else
                        play_glyph(curr_glyph);
                    current_state = GET_INPUT;
                }
            }
            else {
                mistakes++;
                log_msg("User answered incorrectly");
                play_wrong();
                curr_glyph = get_root(this_script, curr_glyph);  
                current_state = PROMPT;
                if (mistakes >= max_mistakes) {
                    play_glyph(curr_glyph);
                    play_dot_prompt();
                    play_dot_sequence(curr_glyph);
                    current_state = GET_INPUT;
                }
            }
        break;

        default:
            log_msg("Invalid state_t %d", current_state);
            quit_mode();
            break;
    }
}