Updated print logic for second movement

This commit is contained in:
David Volovskiy 2025-07-09 07:48:59 -04:00
parent 0711622210
commit befa570a9a

View File

@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include "wordle_face.h" #include "wordle_face.h"
#include "watch_utility.h" #include "watch_utility.h"
#include "watch_common_display.h"
static uint32_t get_random(uint32_t max) { static uint32_t get_random(uint32_t max) {
#if __EMSCRIPTEN__ #if __EMSCRIPTEN__
@ -75,21 +76,21 @@ static void get_prev_letter(const uint8_t curr_pos, uint8_t *word_elements, cons
} }
static void display_letter(wordle_state_t *state, bool display_dash) { static void display_letter(wordle_state_t *state, bool display_dash) {
char buf[1 + 1]; char buf[3];
if (state->word_elements[state->position] >= WORDLE_NUM_VALID_LETTERS) { if (state->word_elements[state->position] >= WORDLE_NUM_VALID_LETTERS) {
if (display_dash) if (display_dash)
watch_display_string("-", state->position + 5); watch_display_character('-', state->position + 5);
else else
watch_display_string(" ", state->position + 5); watch_display_character(' ', state->position + 5);
return; return;
} }
sprintf(buf, "%c", _valid_letters[state->word_elements[state->position]]); sprintf(buf, "%c", _valid_letters[state->word_elements[state->position]]);
watch_display_string(buf, state->position + 5); watch_display_character(buf[0], state->position + 5);
} }
static void display_all_letters(wordle_state_t *state) { static void display_all_letters(wordle_state_t *state) {
uint8_t prev_pos = state->position; uint8_t prev_pos = state->position;
watch_display_string(" ", 4); watch_display_character(' ', 4);
for (size_t i = 0; i < WORDLE_LENGTH; i++) { for (size_t i = 0; i < WORDLE_LENGTH; i++) {
state->position = i; state->position = i;
display_letter(state, false); display_letter(state, false);
@ -100,13 +101,13 @@ static void display_all_letters(wordle_state_t *state) {
#if !WORDLE_ALLOW_NON_WORD_AND_REPEAT_GUESSES #if !WORDLE_ALLOW_NON_WORD_AND_REPEAT_GUESSES
static void display_not_in_dict(wordle_state_t *state) { static void display_not_in_dict(wordle_state_t *state) {
state->curr_screen = WORDLE_SCREEN_NO_DICT; state->curr_screen = WORDLE_SCREEN_NO_DICT;
watch_display_string("nodict", 4); watch_display_text(WATCH_POSITION_BOTTOM, "nodict");
state->ignore_btn_ticks = WORDLE_TICK_BAD_GUESS; state->ignore_btn_ticks = WORDLE_TICK_BAD_GUESS;
} }
static void display_already_guessed(wordle_state_t *state) { static void display_already_guessed(wordle_state_t *state) {
state->curr_screen = WORDLE_SCREEN_ALREADY_GUESSED; state->curr_screen = WORDLE_SCREEN_ALREADY_GUESSED;
watch_display_string("GUESSD", 4); watch_display_text(WATCH_POSITION_BOTTOM, "GUESSD");
state->ignore_btn_ticks = WORDLE_TICK_BAD_GUESS; state->ignore_btn_ticks = WORDLE_TICK_BAD_GUESS;
} }
@ -169,9 +170,9 @@ static bool check_word(wordle_state_t *state) {
static void show_skip_wrong_letter_indicator(bool skipping, wordle_screen curr_screen) { static void show_skip_wrong_letter_indicator(bool skipping, wordle_screen curr_screen) {
if (curr_screen >= WORDLE_SCREEN_PLAYING) return; if (curr_screen >= WORDLE_SCREEN_PLAYING) return;
if (skipping) if (skipping)
watch_display_string("H", 3); watch_display_character('H', 3);
else else
watch_display_string(" ", 3); watch_display_character(' ', 3);
} }
static void update_known_wrong_letters(wordle_state_t *state) { static void update_known_wrong_letters(wordle_state_t *state) {
@ -199,7 +200,7 @@ static void update_known_wrong_letters(wordle_state_t *state) {
static void display_attempt(uint8_t attempt) { static void display_attempt(uint8_t attempt) {
char buf[3]; char buf[3];
sprintf(buf, "%d", attempt+1); sprintf(buf, "%d", attempt+1);
watch_display_string(buf, 3); watch_display_character(buf[0], 3);
} }
static void display_playing(wordle_state_t *state) { static void display_playing(wordle_state_t *state) {
@ -247,7 +248,7 @@ static void reset_board(wordle_state_t *state) {
watch_clear_colon(); watch_clear_colon();
state->position = get_first_pos(state->word_elements_result); state->position = get_first_pos(state->word_elements_result);
display_playing(state); display_playing(state);
watch_display_string(" -", 4); watch_display_character('-', 5);
#if __EMSCRIPTEN__ #if __EMSCRIPTEN__
printf("ANSWER: %s\r\n", _valid_words[state->curr_answer]); printf("ANSWER: %s\r\n", _valid_words[state->curr_answer]);
#endif #endif
@ -255,35 +256,39 @@ static void reset_board(wordle_state_t *state) {
static void display_title(wordle_state_t *state) { static void display_title(wordle_state_t *state) {
state->curr_screen = WORDLE_SCREEN_TITLE; state->curr_screen = WORDLE_SCREEN_TITLE;
watch_display_string("WO WordLE", 0); watch_display_text(WATCH_POSITION_TOP_LEFT, "WO");
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
watch_display_text(WATCH_POSITION_BOTTOM, "WordLE");
show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen); show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
} }
#if WORDLE_USE_DAILY_STREAK != 2 #if WORDLE_USE_DAILY_STREAK != 2
static void display_continue_result(bool continuing) { static void display_continue_result(bool continuing) {
watch_display_string(continuing ? "y" : "n", 9); watch_display_character(continuing ? 'y' : 'n', 9);
} }
static void display_continue(wordle_state_t *state) { static void display_continue(wordle_state_t *state) {
state->curr_screen = WORDLE_SCREEN_CONTINUE; state->curr_screen = WORDLE_SCREEN_CONTINUE;
watch_display_string("Cont ", 4); watch_display_text(WATCH_POSITION_BOTTOM, "Cont ");
show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen); show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
display_continue_result(state->continuing); display_continue_result(state->continuing);
} }
#endif #endif
static void display_streak(wordle_state_t *state) { static void display_streak(wordle_state_t *state) {
char buf[12]; char buf[10];
state->curr_screen = WORDLE_SCREEN_STREAK; state->curr_screen = WORDLE_SCREEN_STREAK;
#if WORDLE_USE_DAILY_STREAK == 2 #if WORDLE_USE_DAILY_STREAK == 2
if (state->streak > 99) if (state->streak > 99)
sprintf(buf, "WO St--dy"); sprintf(buf, "St--dy");
else else
sprintf(buf, "WO St%2ddy", state->streak); sprintf(buf, "St%2ddy", state->streak);
#else #else
sprintf(buf, "WO St%4d", state->streak); sprintf(buf, "St%4d", state->streak);
#endif #endif
watch_display_string(buf, 0); watch_display_text(WATCH_POSITION_TOP_LEFT, "WO");
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
watch_display_text(WATCH_POSITION_BOTTOM, buf);
watch_set_colon(); watch_set_colon();
show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen); show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
} }
@ -292,13 +297,15 @@ static void display_streak(wordle_state_t *state) {
static void display_wait(wordle_state_t *state) { static void display_wait(wordle_state_t *state) {
state->curr_screen = WORDLE_SCREEN_WAIT; state->curr_screen = WORDLE_SCREEN_WAIT;
if (state->streak < 40) { if (state->streak < 40) {
char buf[13]; char buf[5];
sprintf(buf,"WO%2d WaIt ", state->streak); sprintf(buf,"%2d", state->streak);
watch_display_string(buf, 0); watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
} }
else { // Streak too long to display in top-right else { // Streak too long to display in top-right
watch_display_string("WO WaIt ", 0); watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
} }
watch_display_text(WATCH_POSITION_TOP_LEFT, "WO");
watch_display_text(WATCH_POSITION_BOTTOM, " WaIt ");
show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen); show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
} }
#endif #endif
@ -312,16 +319,18 @@ static uint32_t get_day_unix_time(void) {
} }
static void display_lose(wordle_state_t *state, uint8_t subsecond) { static void display_lose(wordle_state_t *state, uint8_t subsecond) {
char buf[WORDLE_LENGTH + 6]; char buf[10];
sprintf(buf,"L %s", subsecond % 2 ? _valid_words[state->curr_answer] : " "); sprintf(buf," %s", subsecond % 2 ? _valid_words[state->curr_answer] : " ");
watch_display_string(buf, 0); watch_display_text(WATCH_POSITION_TOP, "L ");
watch_display_text(WATCH_POSITION_BOTTOM, buf);
} }
static void display_win(wordle_state_t *state, uint8_t subsecond) { static void display_win(wordle_state_t *state, uint8_t subsecond) {
(void) state; (void) state;
char buf[13]; char buf[10];
sprintf(buf,"W %s ", subsecond % 2 ? "NICE" : "JOb "); sprintf(buf," %s ", subsecond % 2 ? "NICE" : "JOb ");
watch_display_string(buf, 0); watch_display_text(WATCH_POSITION_TOP, "W ");
watch_display_text(WATCH_POSITION_BOTTOM, buf);
} }
static bool is_playing(const wordle_state_t *state) { static bool is_playing(const wordle_state_t *state) {
@ -334,27 +343,28 @@ static bool is_playing(const wordle_state_t *state) {
} }
static void display_result(wordle_state_t *state, uint8_t subsecond) { static void display_result(wordle_state_t *state, uint8_t subsecond) {
char buf[WORDLE_LENGTH + 1]; char buf[10];
buf[0] = ' ';
for (size_t i = 0; i < WORDLE_LENGTH; i++) for (size_t i = 0; i < WORDLE_LENGTH; i++)
{ {
switch (state->word_elements_result[i]) switch (state->word_elements_result[i])
{ {
case WORDLE_LETTER_WRONG: case WORDLE_LETTER_WRONG:
buf[i] = '-'; buf[i+1] = '-';
break; break;
case WORDLE_LETTER_CORRECT: case WORDLE_LETTER_CORRECT:
buf[i] = _valid_letters[state->word_elements[i]]; buf[i+1] = _valid_letters[state->word_elements[i]];
break; break;
case WORDLE_LETTER_WRONG_LOC: case WORDLE_LETTER_WRONG_LOC:
if (subsecond % 2) if (subsecond % 2)
buf[i] = ' '; buf[i+1] = ' ';
else else
buf[i] = _valid_letters[state->word_elements[i]]; buf[i+1] = _valid_letters[state->word_elements[i]];
default: default:
break; break;
} }
} }
watch_display_string(buf, 5); watch_display_text(WATCH_POSITION_BOTTOM, buf);
} }
static bool act_on_btn(wordle_state_t *state, const wordle_pin_enum pin) { static bool act_on_btn(wordle_state_t *state, const wordle_pin_enum pin) {
@ -551,7 +561,7 @@ bool wordle_face_loop(movement_event_t event, void *context) {
if (event.subsecond % 2) { if (event.subsecond % 2) {
display_letter(state, true); display_letter(state, true);
} else { } else {
watch_display_string(" ", state->position + 5); watch_display_character(' ', state->position + 5);
} }
break; break;
case WORDLE_SCREEN_RESULT: case WORDLE_SCREEN_RESULT: