Exemplo n.º 1
0
std::string SquareNMCS::get_best_string()
{
	if (text.size() == length)
		return text;

	while (text.size() < length)
		text += get_next_letter();

	return text;
}
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;
    }
}