Пример #1
0
/**
 * @brief  Step through the main stages in the code.
 * @return Void
 */
void md14_main() {
  switch(md14_next_state) {
    case MD14_STATE_INTRO:
    	lang_fileset = LANG_FILESET;
		mode_fileset = MODE_FILESET;
    	play_mp3(MODE_FILESET, "WELC");
		md14_next_state = MD14_STATE_LVLSEL;
		srand(timer_rand());
		break;

	case MD14_STATE_LVLSEL:
        md14_last_dot = create_dialog("LVL3", (DOT_1 | DOT_2 | DOT_3));
        if (md14_last_dot == NO_DOTS)
        	break;
        switch (md14_last_dot) {
        	case '1':
				play_mp3(LANGUAGE, "EASY");
   				strings_to_wordlist(easy, ARRAYLEN(easy), &md14_dict);
   				break;
        	case '2':
				play_mp3(LANGUAGE, "MED");
  				strings_to_wordlist(medium, ARRAYLEN(medium), &md14_dict);
  				break;
        	case '3':
				play_mp3(LANGUAGE, "HARD");
    			strings_to_wordlist(hard, ARRAYLEN(hard), &md14_dict);
    			break;
        }
		print_words_in_list(&md14_dict);
    	play_mp3(MODE_FILESET, "INST");
    	md14_next_state = MD14_STATE_GENQUES;
    	break;

	case MD14_STATE_GENQUES:
		md14_reset();
		get_next_word_in_wordlist(&md14_dict, &md14_chosen_word);
		log_msg("[MD14] Next word: %s\n\r", md14_chosen_word->name);
		
		md14_next_state = MD14_STATE_PROMPT;
	  	break;

	 case MD14_STATE_PROMPT:
	 	play_mp3(LANGUAGE, "SPEL");
	 	speak_word(md14_chosen_word);
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	case MD14_STATE_INPUT:
		md14_cell = get_cell();
		if (md14_cell == NO_DOTS) {
			break;
		}
		md14_cell_pattern = GET_CELL_PATTERN(md14_cell);
		md14_cell_control = GET_CELL_CONTROL(md14_cell);
		switch (md14_cell_control) {
			case WITH_ENTER:
			md14_user_cell.pattern = md14_cell_pattern;
			md14_next_state = MD14_STATE_CHECK;
			log_msg("[MD14] Checking answer\n\r");
			break;
			case WITH_LEFT:
			md14_next_state = MD14_STATE_REPROMPT;
			break;
			case WITH_RIGHT:
			md14_next_state = MD14_STATE_GENQUES;
			break;
			case WITH_CANCEL:
			break;
		}
		break;

	case MD14_STATE_CHECK:
		md14_speak_inputted_cell();
		get_next_cell_in_word(md14_chosen_word, &md14_curr_cell);
		log_msg("Target cell: %x, inputted cell: %x.\n\r", md14_curr_cell.pattern, md14_user_cell.pattern);
		

		if (cell_equals(&md14_curr_cell, &md14_user_cell)) {
			if (md14_chosen_word->curr_letter == md14_chosen_word->num_letters - 1) { // done
				md14_correct_answer();
			  	md14_next_state = MD14_STATE_GENQUES;
			}
			else {// correct but not done
				play_mp3(LANGUAGE, "GOOD");
				play_mp3(LANGUAGE, "NLET");
				md14_curr_mistakes = 0;
				md14_next_state = MD14_STATE_INPUT;
			}
		}
		else {
			md14_incorrect_answer();
			md14_next_state = MD14_STATE_REPROMPT;
		}
		break;

	case MD14_STATE_REPROMPT:
		if (md14_curr_mistakes >= MAX_INCORRECT_GUESS) {
			play_mp3(LANGUAGE, "PRSS");
			char* letter_name = get_eng_letter_name_by_cell(&md14_curr_cell);
			play_mp3(LANGUAGE, letter_name);
			if (md14_curr_mistakes >= MAX_INCORRECT_GUESS + 1)
				play_pattern(md14_curr_cell.pattern);
		}
		else {
			play_mp3(LANGUAGE, "SPEL");
	 		speak_word(md14_chosen_word);
	 		if (md14_chosen_word->curr_glyph > -1) {// not at beginning of word
	 			play_mp3(MODE_FILESET, "SPLS");
	 			speak_letters_so_far(md14_chosen_word);
	 			play_mp3(LANGUAGE, "NLET");
	 		}
	 	}
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	default:
		break;
  }
}
Пример #2
0
/**
 * @brief  Step through the main stages in the code.
 * @return Void
 */
void mode_14_main() {
  switch(current_state) {

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

    case CHOOSE_LEVEL:
        last_dot = create_dialog(MP3_CHOOSE_LEVELS_3, (DOT_1 | DOT_2 | DOT_3 | CANCEL));
        switch (last_dot) {
            case '1':
                play_direction(MP3_EASY_MODE);
                strings_to_wordlist(easy, ARRAYLEN(easy), &mode_14_dict);
                current_state = GENERATE_QUESTION;
                break;

            case '2':
                play_direction(MP3_MEDIUM_MODE);
                strings_to_wordlist(medium, ARRAYLEN(medium), &mode_14_dict);
                current_state = GENERATE_QUESTION;
                break;

            case '3':
                play_direction(MP3_HARD_MODE);
                strings_to_wordlist(hard, ARRAYLEN(hard), &mode_14_dict);
                current_state = GENERATE_QUESTION;
                break;

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

            default:
                break;
        }        
        break;

    case GENERATE_QUESTION:
        print_words_in_list(&mode_14_dict);
        play_direction(MP3_INSTRUCTIONS_WORD);
        curr_mistakes = 0;
        get_next_word_in_wordlist(&mode_14_dict, &mode_14_chosen_word);
        log_msg("[mode_14] Next word: %s", mode_14_chosen_word->name);
        current_state = PROMPT;
        break;

     case PROMPT:
        play_direction(MP3_SPELL_WORD);
        speak_word(mode_14_chosen_word);
        current_state = GET_INPUT;
        break;

    case GET_INPUT:
        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:
            current_state = CHECK_ANSWER;
            break;

            case WITH_LEFT:
            current_state = REPROMPT;
            break;

            case WITH_RIGHT:
            current_state = GENERATE_QUESTION;
            break;

            case WITH_CANCEL:
            break;
        }
        break;

    case CHECK_ANSWER:
        mode_14_curr_cell = get_next_cell_in_word(mode_14_chosen_word);
        log_msg("Target cell: %x, inputted cell: %x.", mode_14_curr_cell, cell_pattern);
        

        if (cell_pattern == mode_14_curr_cell) {
            if (mode_14_chosen_word->curr_letter == mode_14_chosen_word->num_letters - 1) { // done
                mode_14_correct_answer();
                current_state = GENERATE_QUESTION;
            }
            else {  // correct but not done
                play_feedback(MP3_GOOD);
                play_direction(MP3_NEXT_LETTER);
                curr_mistakes = 0;
                current_state = GET_INPUT;
            }
        }
        else {
            mode_14_incorrect_answer();
            current_state = REPROMPT;
        }
        break;

    case REPROMPT:
        if (curr_mistakes >= max_mistakes) {
            play_direction(MP3_PLEASE_PRESS);
            char* letter_name = get_eng_letter_name_by_cell(mode_14_curr_cell);
            play_lang_audio(letter_name);
            if (curr_mistakes >= max_mistakes + 1)
                play_cell(mode_14_curr_cell);
        }
        else {
            play_direction(MP3_SPELL_WORD);
            speak_word(mode_14_chosen_word);
            if (mode_14_chosen_word->curr_glyph > -1) { // not at beginning of word
                play_feedback(MP3_SPELLING_SO_FAR);
                speak_letters_so_far(mode_14_chosen_word);
                play_direction(MP3_NEXT_LETTER);
            }
        }
        current_state = GET_INPUT;
        break;

    default:
        log_msg("Invalid state_t %d", current_state);
        quit_mode();
        break;
  }
}
Пример #3
0
/**
 * @brief  Step through the main stages in the code.
 * @return Void
 */
void md14_main() {
  switch(md14_next_state)
  {
    case MD14_STATE_INTRO:
    	PRINTF("In intro state\n\r");
    	play_mp3(MODE_FILESET, "WELC");
    	lang_fileset = "ENG_";
		mode_fileset = "MD14";
		md14_next_state = MD14_STATE_LVLSEL;
		srand(timer_rand());
		break;

	case MD14_STATE_LVLSEL:
        md14_last_dot = create_dialog("LVLS", (DOT_1 | DOT_2));
        switch (md14_last_dot) {

        	case NO_DOTS:
        		break;

        	case '1':
        		play_mp3(LANGUAGE, "EASY");
        		strings_to_wordlist(easy, ARRAYLEN(easy), &md14_dict);
				print_words_in_list(&md14_dict);
        		play_mp3(MODE_FILESET, "INST");
        		md14_next_state = MD14_STATE_GENQUES;
        		break;

        	case '2':
        		play_mp3(LANGUAGE, "HARD");
        		strings_to_wordlist(medium, ARRAYLEN(medium), &md14_dict);
				print_words_in_list(&md14_dict);
        		play_mp3(MODE_FILESET, "INST");
        		md14_next_state = MD14_STATE_GENQUES;
        		break;

        	// todo: add case 3; figure out too-long words

        	default:
        		play_mp3(LANGUAGE, "INVP");
        		PRINTF("Invalid entry.");
				break;
		}
		break;

	case MD14_STATE_GENQUES:
		PRINTF("In genques state\n\r");
		md14_curr_mistakes = 0;
		get_next_word_in_wordlist(&md14_dict, &md14_chosen_word);
		sprintf(dbgstr, "[MD14] Next word: %s\n\r", md14_chosen_word->name);
		PRINTF(dbgstr);
		md14_next_state = MD14_STATE_PROMPT;
	  	break;

	 case MD14_STATE_PROMPT:
	 	PRINTF("In prompt state\n\r");
	 	play_mp3(LANGUAGE, "SPEL");
	 	speak_word(md14_chosen_word);
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	case MD14_STATE_INPUT:
		md14_cell = get_cell();
		if (md14_cell == NO_DOTS) {
			break;
		}
		md14_cell_pattern = GET_CELL_PATTERN(md14_cell);
		md14_cell_control = GET_CELL_CONTROL(md14_cell);
		switch (md14_cell_control) {
			case WITH_ENTER:
			md14_user_cell.pattern = md14_cell_pattern;
			md14_next_state = MD14_STATE_CHECK;
			PRINTF("[MD14] Checking answer\n\r");
			break;
			case WITH_LEFT:
			md14_next_state = MD14_STATE_REPROMPT;
			break;
			case WITH_RIGHT:
			stats();
			md14_next_state = MD14_STATE_GENQUES;
			break;
			case WITH_CANCEL:
			break;
		}
		break;

	case MD14_STATE_CHECK:
		get_next_cell_in_word(md14_chosen_word, &md14_curr_cell);
		sprintf(dbgstr, "In check state. Current cell: %x, user cell: %x.\n\r", md14_curr_cell.pattern, md14_user_cell.pattern);
		PRINTF(dbgstr);

		if (cell_equals(&md14_curr_cell, &md14_user_cell)) {
			md14_curr_mistakes = 0;
			if (md14_chosen_word->curr_letter == md14_chosen_word->num_letters - 1) { // done
				correct_answer();
			  	md14_next_state = MD14_STATE_GENQUES;
			}
			else {// correct but not done
				play_mp3(LANGUAGE, "GOOD");
				play_mp3(LANGUAGE, "NLET");
				md14_next_state = MD14_STATE_INPUT;
			}
		}
		else {// incorrect letter
			incorrect_answer(); // @todo mark invalid letters invalid
			md14_next_state = MD14_STATE_REPROMPT;
		}
		break;

	case MD14_STATE_REPROMPT:
		PRINTF("In reprompt state\n\r");

		if (md14_curr_mistakes >= MAX_INCORRECT_GUESS) {
			play_mp3(LANGUAGE, "PRSS");
			play_pattern(md14_curr_cell.pattern);
		}
		else {
			play_mp3(LANGUAGE, "SPEL");
	 		speak_word(md14_chosen_word);
	 		if (md14_chosen_word->curr_glyph > -1) {// not at beginning of word
	 			play_mp3(MODE_FILESET, "SPLS");
	 			speak_letters_so_far(md14_chosen_word);
	 		}
	 	}
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	default:
		break;
  }
}