Fix bulls_cows.yab UI layout/scrolling and index engmenu items 1 to 7
This commit is contained in:
1 parent
6d31efd796
commit
ebdb0f8ee2
4 files changed
+90
-94
No files matched your search
@@ -10,9 +10,9 @@
|
||||
// Controls:
|
||||
// 0-9 keys : Append a digit to your guess (duplicates rejected)
|
||||
// OK (Enter): Submit your guess / confirm a dialog choice
|
||||
// Space / Right Softkey (F2): Delete last digit, or Quit if guess is empty
|
||||
// Space / * / Right Softkey (F2): Delete last digit, or Quit if empty
|
||||
// Left Softkey (F1): Open the Action Menu (New Game / About / Quit)
|
||||
// Up / Down: Scroll the guess history
|
||||
// Up / Down: Scroll the guess history up (older) or down (newer)
|
||||
//
|
||||
// Note: this build of yabasic has no function returns and no RNG seeding,
|
||||
// so randomness uses a small LCG seeded from the wall clock (time$).
|
||||
@@ -30,6 +30,7 @@ fi
|
||||
// ----------------------------------------------------------------------------
|
||||
MAX_GUESSES = 10
|
||||
CODE_LEN = 4
|
||||
VISIBLE_HISTORY = 4
|
||||
|
||||
secret$ = ""
|
||||
guess_count = 0
|
||||
@@ -190,6 +191,7 @@ sub submit_guess()
|
||||
history_result$(guess_count) = result$
|
||||
guess_count = guess_count + 1
|
||||
current_guess$ = ""
|
||||
history_scroll = 0
|
||||
|
||||
if ev_bulls = CODE_LEN then
|
||||
won = 1
|
||||
@@ -207,7 +209,7 @@ sub submit_guess()
|
||||
end sub
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Rendering
|
||||
// Rendering (240x296 window: header 0..34, content 36..266, softbar 270..296)
|
||||
// ----------------------------------------------------------------------------
|
||||
sub render_header()
|
||||
local badge$
|
||||
@@ -220,71 +222,82 @@ sub render_header()
|
||||
end sub
|
||||
|
||||
sub render_secret_area()
|
||||
local y, i, mask$
|
||||
y = 40
|
||||
local y, i, mask$, col
|
||||
y = 36
|
||||
if game_over then
|
||||
if won then
|
||||
col = neoui.TEXT_GREEN
|
||||
else
|
||||
col = neoui.TEXT_RED
|
||||
fi
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
|
||||
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_GREEN, 8, y + 16, 22, secret$, 224)
|
||||
neoui_draw_text(neoui.FONT_LARGE, col, 8, y + 14, 20, secret$, 224)
|
||||
else
|
||||
mask$ = ""
|
||||
for i = 1 to CODE_LEN
|
||||
mask$ = mask$ + "?"
|
||||
next i
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
|
||||
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_LIGHT, 8, y + 16, 22, mask$, 224)
|
||||
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_LIGHT, 8, y + 14, 20, mask$, 224)
|
||||
fi
|
||||
end sub
|
||||
|
||||
sub render_input_area()
|
||||
local y, prompt$
|
||||
y = 84
|
||||
local y, prompt$, focused
|
||||
y = 74
|
||||
focused = 0
|
||||
if game_over then
|
||||
prompt$ = "Game finished"
|
||||
else
|
||||
prompt$ = "Your guess (4 unique digits)"
|
||||
if modal_mode = 0 and len(current_guess$) > 0 then
|
||||
focused = 1
|
||||
fi
|
||||
fi
|
||||
neoui_draw_input_box(8, y, 224, 40, 0, prompt$, current_guess$, "0-9 keys to type", 0)
|
||||
neoui_draw_input_box(8, y, 224, 38, focused, prompt$, current_guess$, "0-9 keys to type", 0)
|
||||
end sub
|
||||
|
||||
sub render_history()
|
||||
local y, i, start_idx, end_idx, visible, result$
|
||||
y = 136
|
||||
local y, i, start_idx, end_idx, max_off, result$
|
||||
y = 118
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 8, y, 14, "Guess history:", 224)
|
||||
|
||||
y = y + 20
|
||||
visible = 4
|
||||
if guess_count <= visible then
|
||||
y = 136
|
||||
if guess_count <= VISIBLE_HISTORY then
|
||||
start_idx = 0
|
||||
else
|
||||
start_idx = guess_count - visible + history_scroll
|
||||
max_off = guess_count - VISIBLE_HISTORY
|
||||
start_idx = max_off + history_scroll
|
||||
if start_idx < 0 then start_idx = 0 fi
|
||||
if start_idx > guess_count - visible then start_idx = guess_count - visible fi
|
||||
if start_idx > max_off then start_idx = max_off fi
|
||||
fi
|
||||
end_idx = start_idx + visible - 1
|
||||
end_idx = start_idx + VISIBLE_HISTORY - 1
|
||||
if end_idx > guess_count - 1 then end_idx = guess_count - 1 fi
|
||||
|
||||
for i = start_idx to end_idx
|
||||
if i >= 0 and i < guess_count then
|
||||
result$ = history_result$(i)
|
||||
neoui_draw_list_row(i - start_idx, y, 26, 0, neoui_icon$("list"), neoui.TEXT_BLUE, "#" + str$(i + 1) + " " + history_guess$(i), result$, "")
|
||||
neoui_draw_list_row(i - start_idx, y, 26, 0, neoui_icon$("list"), neoui.TEXT_BLUE, "#" + str$(i + 1) + " " + history_guess$(i) + " " + result$, "", "")
|
||||
y = y + 26
|
||||
fi
|
||||
next i
|
||||
|
||||
if guess_count > visible then
|
||||
neoui_draw_scrollbar(234, 156, 104, guess_count, visible, -history_scroll)
|
||||
if guess_count > VISIBLE_HISTORY then
|
||||
neoui_draw_scrollbar(234, 136, 104, guess_count, VISIBLE_HISTORY, start_idx)
|
||||
fi
|
||||
end sub
|
||||
|
||||
sub render_hint()
|
||||
local y
|
||||
y = 248
|
||||
if game_over then
|
||||
if won then
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, 264, 224, 16, "Solved in " + str$(guess_count) + " tries! OK = New game")
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, y, 224, 16, "Solved in " + str$(guess_count) + " tries! OK = New game")
|
||||
else
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_RED, 8, 264, 224, 16, "Out of tries! Code was " + secret$ + " - OK = New game")
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_RED, 8, y, 224, 16, "Out of tries! OK = New game")
|
||||
fi
|
||||
else
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, 264, 224, 16, "0-9 type OK go Up/Dn scroll")
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 224, 16, "0-9 type OK go Up/Dn scroll")
|
||||
fi
|
||||
end sub
|
||||
|
||||
@@ -302,16 +315,20 @@ sub render_all()
|
||||
neoui_draw_softkeys("Close", "Select", "Back")
|
||||
elsif modal_mode = 2 then
|
||||
neoui_draw_confirm_dialog("Start New Game?", "Abandon the current", "round and guess a new code?", "Cancel", "New Game", confirm_new)
|
||||
neoui_draw_softkeys("Cancel", "Confirm", "Back")
|
||||
neoui_draw_softkeys("New Game", "Confirm", "Cancel")
|
||||
elsif modal_mode = 3 then
|
||||
if won then
|
||||
neoui_draw_confirm_dialog("You Win!", "Cracked the code in", str$(guess_count) + " tries!", "Quit", "Play Again", confirm_new)
|
||||
else
|
||||
neoui_draw_confirm_dialog("Game Over", "The code was " + secret$, "Better luck next time!", "Quit", "Play Again", confirm_new)
|
||||
fi
|
||||
neoui_draw_softkeys("Quit", "Confirm", "Back")
|
||||
neoui_draw_softkeys("Again", "Confirm", "Close")
|
||||
else
|
||||
neoui_draw_softkeys("Menu", "Submit", "Del/Quit")
|
||||
if game_over then
|
||||
neoui_draw_softkeys("Menu", "New Game", "Quit")
|
||||
else
|
||||
neoui_draw_softkeys("Menu", "Submit", "Del/Quit")
|
||||
fi
|
||||
fi
|
||||
|
||||
neoui_end_frame()
|
||||
@@ -337,6 +354,9 @@ while running
|
||||
if modal_mode = 0 then
|
||||
modal_mode = 1
|
||||
menu_sel = 0
|
||||
elsif modal_mode = 2 or modal_mode = 3 then
|
||||
reset_game()
|
||||
neoui_show_toast("New game started!", 1500)
|
||||
else
|
||||
modal_mode = 0
|
||||
fi
|
||||
@@ -377,7 +397,11 @@ while running
|
||||
render_all()
|
||||
|
||||
elsif modal_mode = 2 then
|
||||
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
|
||||
if k = neoui.KEY_LEFT then
|
||||
confirm_new = 0
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
confirm_new = 1
|
||||
elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then
|
||||
confirm_new = 1 - confirm_new
|
||||
elsif k = neoui.KEY_BACK then
|
||||
modal_mode = 0
|
||||
@@ -391,7 +415,11 @@ while running
|
||||
render_all()
|
||||
|
||||
elsif modal_mode = 3 then
|
||||
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
|
||||
if k = neoui.KEY_LEFT then
|
||||
confirm_new = 0
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
confirm_new = 1
|
||||
elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then
|
||||
confirm_new = 1 - confirm_new
|
||||
elsif k = neoui.KEY_BACK then
|
||||
modal_mode = 0
|
||||
@@ -408,18 +436,23 @@ while running
|
||||
|
||||
else
|
||||
if k = neoui.KEY_OK then
|
||||
submit_guess()
|
||||
if game_over then
|
||||
reset_game()
|
||||
neoui_show_toast("New game started!", 1500)
|
||||
else
|
||||
submit_guess()
|
||||
fi
|
||||
elsif k = neoui.KEY_BACK then
|
||||
running = 0
|
||||
elsif k = neoui.KEY_UP then
|
||||
if guess_count > VISIBLE_HISTORY and history_scroll > -(guess_count - VISIBLE_HISTORY) then
|
||||
history_scroll = history_scroll - 1
|
||||
fi
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
if history_scroll < 0 then
|
||||
history_scroll = history_scroll + 1
|
||||
fi
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
if guess_count > 5 and history_scroll > -(guess_count - 5) then
|
||||
history_scroll = history_scroll - 1
|
||||
fi
|
||||
elsif k = neoui.KEY_SPACE then
|
||||
elsif k = neoui.KEY_SPACE or k = neoui.KEY_STAR then
|
||||
backspace_guess()
|
||||
elsif k = neoui.KEY_0 then
|
||||
append_digit(0)
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user