This commit is contained in:
parent
cec70bc43b
commit
d2a5f139de
1 changed files with 26 additions and 14 deletions
|
@ -26,7 +26,6 @@ pub struct App {
|
|||
binary_search_hint: BinarySearchHint,
|
||||
tab: Tab,
|
||||
current_effect: Effect,
|
||||
failed_guesses: usize,
|
||||
}
|
||||
|
||||
const SPLASH: &str = r#"
|
||||
|
@ -70,7 +69,6 @@ impl App {
|
|||
number_guess_responses: String::new(),
|
||||
tab: Tab::Passcode,
|
||||
current_effect: fx::fade_from_fg(Color::Black, (200000, Interpolation::CircIn)),
|
||||
failed_guesses: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,8 +132,8 @@ impl App {
|
|||
let layout = Layout::new(
|
||||
Direction::Vertical,
|
||||
[
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(0),
|
||||
|
@ -179,7 +177,7 @@ impl App {
|
|||
block,
|
||||
);
|
||||
}
|
||||
if self.failed_guesses >= 10 {
|
||||
if self.binary_search_hint.failed_guesses >= 20 {
|
||||
frame.render_widget(
|
||||
Paragraph::new("Search the binary")
|
||||
.alignment(ratatui::layout::Alignment::Center)
|
||||
|
@ -241,7 +239,7 @@ impl App {
|
|||
self.binary_search_hint.guess_hint = Some((number, guess_hint));
|
||||
self.binary_search_hint.numbers_guessed.clear();
|
||||
self.binary_search_hint.number_to_guess += 1;
|
||||
self.failed_guesses += 1;
|
||||
self.binary_search_hint.failed_guesses += 1;
|
||||
if self.binary_search_hint.number_to_guess == NUMBERS.len() {
|
||||
self.binary_search_hint.number_to_guess = 0;
|
||||
}
|
||||
|
@ -294,6 +292,7 @@ struct BinarySearchHint {
|
|||
guess_hint: Option<(u32, u32)>,
|
||||
range: Range<u32>,
|
||||
number_to_guess: usize,
|
||||
failed_guesses: usize,
|
||||
}
|
||||
|
||||
impl Default for BinarySearchHint {
|
||||
|
@ -303,6 +302,7 @@ impl Default for BinarySearchHint {
|
|||
range: 0..10,
|
||||
guess_hint: None,
|
||||
number_to_guess: OsRng.unwrap_err().random_range(0..2),
|
||||
failed_guesses: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ impl Widget for &BinarySearchHint {
|
|||
if !self.range.contains(&number_on) {
|
||||
style = style.fg(Color::Rgb(117, 97, 42));
|
||||
}
|
||||
buf.set_string(x, area.y, measures, style);
|
||||
buf.set_string(x, area.y + 1, measures, style);
|
||||
}
|
||||
|
||||
for number_guessed in &self.numbers_guessed {
|
||||
|
@ -332,21 +332,33 @@ impl Widget for &BinarySearchHint {
|
|||
let style = Style::default()
|
||||
.fg(Color::Rgb(226, 190, 89))
|
||||
.bg(PASSWORD_BACKGROUND);
|
||||
buf.set_string(number_x, area.y, "|", style);
|
||||
match NUMBERS[self.number_to_guess].cmp(number_guessed) {
|
||||
Ordering::Less => buf.set_string(number_x, area.y + 1, "<", style),
|
||||
Ordering::Greater => buf.set_string(number_x, area.y + 1, ">", style),
|
||||
Ordering::Equal => buf.set_string(number_x, area.y + 1, "=", style),
|
||||
buf.set_string(number_x, area.y + 1, "|", style);
|
||||
if self.failed_guesses >= 30 {
|
||||
buf.set_string(number_x, area.y, format!("{}", *number_guessed), style);
|
||||
}
|
||||
match NUMBERS[self.number_to_guess].cmp(number_guessed) {
|
||||
Ordering::Less => buf.set_string(number_x, area.y + 2, "<", style),
|
||||
Ordering::Greater => buf.set_string(number_x, area.y + 2, ">", style),
|
||||
Ordering::Equal => buf.set_string(number_x, area.y + 2, "=", style),
|
||||
}
|
||||
}
|
||||
|
||||
if self.failed_guesses >= 30 {
|
||||
let guess_hint = self.range.start + ((self.range.end - self.range.start) / 2);
|
||||
let number_x = area.x + (guess_hint as f64 / ruler_scale) as u16;
|
||||
let style = Style::default()
|
||||
.fg(Color::Rgb(226, 190, 89))
|
||||
.bg(PASSWORD_BACKGROUND);
|
||||
buf.set_string(number_x, area.y + 2, "↑", style);
|
||||
}
|
||||
|
||||
if let Some((last_guessed, guess_hint)) = self.guess_hint {
|
||||
let number_x = area.x + (last_guessed as f64 / ruler_scale) as u16;
|
||||
let style = Style::default().fg(Color::Red).bg(PASSWORD_BACKGROUND);
|
||||
buf.set_string(number_x, area.y, "✗", style);
|
||||
buf.set_string(number_x, area.y + 1, "✗", style);
|
||||
let number_x = area.x + (guess_hint as f64 / ruler_scale) as u16;
|
||||
let style = Style::default().fg(Color::Green).bg(PASSWORD_BACKGROUND);
|
||||
buf.set_string(number_x, area.y, "✓", style);
|
||||
buf.set_string(number_x, area.y + 1, "✓", style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue