Closed christianh814 closed 1 year ago
Is this from your own implementation (following along from the course), or from the code in this repository?
My own implementation following the course. Although I'm comparing it to my code and I can't seem to see where I went wrong
Your nested curly braces { }
are matched up incorrectly in src/invaders.rs
. There should be another closing brace between lines 44-45, and the closing brace at line 52 (53 after the earlier change) should be deleted. Then the code from line 45-52 should be unindented one level (4 spaces).
Here is what the change diff looks like:
diff --git a/src/invaders.rs b/src/invaders.rs
index 342707c..cf2b0f8 100644
--- a/src/invaders.rs
+++ b/src/invaders.rs
@@ -42,14 +42,15 @@ impl Invaders {
if min_x == 0 {
self.direction = 1;
downwards = true;
- } else {
- let max_x = self.army.iter().map(|invader| invader.x).max().unwrap_or(0);
- if max_x == NUM_COLS - 1 {
- self.direction = -1;
- downwards = true;
- }
+ }
+ } else {
+ let max_x = self.army.iter().map(|invader| invader.x).max().unwrap_or(0);
+ if max_x == NUM_COLS - 1 {
+ self.direction = -1;
+ downwards = true;
}
}
+
if downwards {
let new_duration = max(self.move_timer.duration.as_millis() - 250, 250);
self.move_timer = Timer::from_millis(new_duration as u64);
By the way, Rust generally uses spaces, not tabs. If you run cargo fmt
, your entire project will be reformatted nicely.
Thank you for that, that did it. Also didn't know about the cargo fmt
command. Thanks!
Ultimate Rust 2 goes over cargo fmt
, cargo clippy
, and a lot of other cool stuff.
I get the following error when the invaders move "down"