diff --git a/Cargo.toml b/Cargo.toml index 7395ade..cba75f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,10 @@ edition = "2021" [dependencies] crossterm = "0.26.1" rand = "0.8.5" + +[profile.release] +#opt-level = "z" +lto = true +strip = true +panic = "abort" +codegen-units = 1 diff --git a/README.md b/README.md index 28109f4..ecd332c 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,5 @@ This is my first project in rust so the code is probably great. Play the game: ``` -cargo run +cargo run --release ``` diff --git a/src/main.rs b/src/main.rs index 1128800..c1f27a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,6 +103,7 @@ fn main() -> Result<()> { let mut direction: Direction = Direction::Left; let mut score = 0; let mut lost = false; + let origin = Point { x: 0, y: 0 }; screen.queue(MoveTo(head_x, head_y))?; @@ -144,7 +145,7 @@ fn main() -> Result<()> { if head_x == apples[i].x && head_y == apples[i].y { score += 1; apples[i] = Point { x: thread_rng().gen_range(0..cols), y: thread_rng().gen_range(0..rows)}; - snake.push(Point { x: 0, y: 0 }); + snake.push(Point { x: (*(snake.last().unwrap_or(&origin))).x, y: (*(snake.last().unwrap_or(&origin))).y }); } screen.queue(MoveTo(apples[i].x, apples[i].y))?; screen.queue(Print("*".to_string()))?;