dependabot[bot] 62b8e94969 Bump rand_core from 0.6.1 to 0.6.4
Bumps [rand_core](https://github.com/rust-random/rand) from 0.6.1 to 0.6.4.
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/rand_core-0.6.1...0.6.4)

---
updated-dependencies:
- dependency-name: rand_core
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-15 05:21:47 +00:00
2021-03-15 17:30:10 +05:30
2021-01-24 03:12:13 +05:30
2021-03-15 22:30:49 +05:30
2021-03-15 17:30:10 +05:30
2023-05-15 05:21:47 +00:00
2021-03-15 22:30:49 +05:30
2021-03-15 17:35:47 +05:30

Snake in rust using ncurses crate

The game is playable

run with

cargo run

Keybinds

hjkl or arrow keys for movement

esc or p to pause

Screenshot

Click the image for asciinema

Need unicode support in terminal to print the snake

The unicode characters used are:

  • 0x0298 ʘ
  • 0x2550 ═
  • 0x2551 ║
  • 0x2554 ╔
  • 0x2557 ╗
  • 0x255a ╚
  • 0x255d ╝

Todo 🚧

  • Add a way to change the snake speed
    • Make a ui to switch the snake speed
    • Interal implementation of the snake speed
  • Implement Highscore System
    • Make the ui
    • Internal Implementation
  • Use unicode charachters to draw the snake

Bugs 🐛

  • Snake going through the walls
  • Food spawning in the walls
  • Boxdraw characters not rendering properly
  • Remove all the logging in the ui
  • Pausing delayed if esc is pressed but not if p is pressed.
  • The game flickers a lot after sometime (probably due to the constant redrawing of the whole board every tick)

Maybe in the future

  • Autoplay the game using a simple pathfinding algorithm (to show on r/unixporn of course 🤡)

Notes

A few notes about the game and how I should improve the game

A few notes about time complexity and redrawing with ncurses

The complexity of the program is O(n) every tick (time which changes relative to the speed)

However the place, I can improve is the redrawing of the game

At the time of writing the in commit f9be68e the game still redraws the total board and the total snake every tick.

I think this can be improved by only drawing the parts of the snake and the board when needed


Rust specific stuff I learned

char and std::char are not the same. char is the primitive type std::char is the char module.

As of Sat, 23 Jan 2021 21:49:13 +0000 the char::from_u32 (used in this program) is not valid in primitive char but is valid in std::char

ncursesw is not needed to print unicode characters. I have no clue where I got that idea from.

S
Description
Snake Game in rust using ncurses
Readme MIT 226 KiB
v0.2.3 Latest
2021-03-16 01:01:07 +08:00
Languages
Rust 100%