Skip to content

Commit

Permalink
fix(terminal): maintain idx when shuffling code_lines
Browse files Browse the repository at this point in the history
closes #14
  • Loading branch information
Lioness100 committed Aug 16, 2022
1 parent d2982b4 commit da6b56b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "guess-that-lang"
version = "1.0.17"
version = "1.0.18"
rust-version = "1.63"
authors = ["Lioness100 <[email protected]>"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Game {
thread::scope(|s| {
let display = s.spawn(|| {
self.terminal
.start_showing_code(code, &available_points, receiver)
.start_showing_code(&code, &available_points, receiver)
});

let input = s.spawn(|| {
Expand Down
6 changes: 4 additions & 2 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ impl Terminal {
/// `available_points` every 1.5 seconds.
pub fn start_showing_code(
&self,
mut code_lines: Vec<(String, String)>,
code_lines: &[(String, String)],
available_points: &Mutex<f32>,
receiver: Receiver<()>,
) -> Result<()> {
let mut code_lines: Vec<_> = code_lines.iter().enumerate().collect();

if ARGS.shuffle {
code_lines.shuffle(&mut thread_rng());
};
Expand All @@ -325,7 +327,7 @@ impl Terminal {
// Consume receiver.
let receiver = receiver;

for (idx, (raw, line)) in code_lines.iter().enumerate() {
for (idx, (raw, line)) in code_lines {
if raw == "\n" {
continue;
}
Expand Down

0 comments on commit da6b56b

Please sign in to comment.