SLMT / rust-snake

A snake game written in Rust.
MIT License
84 stars 27 forks source link

Game crushes on key input other than arrow keys #6

Closed timschwarzbrunn closed 2 years ago

timschwarzbrunn commented 2 years ago

The game crushes if you press e.g. the key "k". Change in game.rs the key detection from

let dir = match key {
    Key::Up => Some(Direction::Up),
    Key::Down => Some(Direction::Down),
    Key::Left => Some(Direction::Left),
    Key::Right => Some(Direction::Right),
    _ => None
};

to

let dir = match key {
    Key::Up => Some(Direction::Up),
    Key::Down => Some(Direction::Down),
    Key::Left => Some(Direction::Left),
    Key::Right => Some(Direction::Right),
    _ => return
};

Nice game!

SLMT commented 2 years ago

Sorry for my late response. Thanks for your quick fix! I have fixed the problem accordingly (https://github.com/SLMT/rust-snake/commit/91db082d0e2f767f160392c09bd64f4d44e84412).