added optimizations, moved location of new segment

This commit is contained in:
Noah Swerhun 2023-06-29 21:42:33 -05:00
parent 6198043d76
commit 13116ecd32
3 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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
```

View file

@ -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()))?;