added optimizations, moved location of new segment
This commit is contained in:
parent
6198043d76
commit
13116ecd32
3 changed files with 10 additions and 2 deletions
|
@ -8,3 +8,10 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = "0.26.1"
|
crossterm = "0.26.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
#opt-level = "z"
|
||||||
|
lto = true
|
||||||
|
strip = true
|
||||||
|
panic = "abort"
|
||||||
|
codegen-units = 1
|
||||||
|
|
|
@ -6,5 +6,5 @@ This is my first project in rust so the code is probably great.
|
||||||
|
|
||||||
Play the game:
|
Play the game:
|
||||||
```
|
```
|
||||||
cargo run
|
cargo run --release
|
||||||
```
|
```
|
||||||
|
|
|
@ -103,6 +103,7 @@ fn main() -> Result<()> {
|
||||||
let mut direction: Direction = Direction::Left;
|
let mut direction: Direction = Direction::Left;
|
||||||
let mut score = 0;
|
let mut score = 0;
|
||||||
let mut lost = false;
|
let mut lost = false;
|
||||||
|
let origin = Point { x: 0, y: 0 };
|
||||||
|
|
||||||
screen.queue(MoveTo(head_x, head_y))?;
|
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 {
|
if head_x == apples[i].x && head_y == apples[i].y {
|
||||||
score += 1;
|
score += 1;
|
||||||
apples[i] = Point { x: thread_rng().gen_range(0..cols), y: thread_rng().gen_range(0..rows)};
|
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(MoveTo(apples[i].x, apples[i].y))?;
|
||||||
screen.queue(Print("*".to_string()))?;
|
screen.queue(Print("*".to_string()))?;
|
||||||
|
|
Loading…
Reference in a new issue