Fixed food spawning and snake collision

Fixed the food spawning in the walls
Fixed the snake not colliding with itself
Added speed control to the snake
Exit if the ncurses window is too small
This commit is contained in:
Uttarayan Mondal
2021-01-19 02:49:10 +05:30
parent 477ffdb036
commit d32f293c99
3 changed files with 39 additions and 8 deletions
+11 -1
View File
@@ -4,7 +4,9 @@ mod highscore;
mod menu;
// use game::{Cell, Snake};
// use ncurses::*;
use ncurses::{curs_set, endwin, initscr, keypad, noecho, raw, refresh, stdscr, CURSOR_VISIBILITY};
use ncurses::{
curs_set, endwin, getmaxyx, initscr, keypad, noecho, raw, refresh, stdscr, CURSOR_VISIBILITY,
};
fn main() {
// let (lines, cols): (i32, i32) = (0, 0);
@@ -13,6 +15,14 @@ fn main() {
keypad(stdscr(), true);
curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);
noecho();
let (mut mlines, mut mcols): (i32, i32) = (0, 0);
getmaxyx(stdscr(), &mut mlines, &mut mcols);
if (mlines < 20) || (mcols < 35) {
refresh();
endwin();
eprintln!("Sorry window size too small");
std::process::exit(1);
}
loop {
match menu::main_menu_control() {
0 => game::start(),