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:
+11
-1
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user