Update README.md

This commit is contained in:
Uttarayan Mondal
2021-01-18 05:12:07 +05:30
parent 6f9a5bd91f
commit cad605c458
8 changed files with 32 additions and 19 deletions
+5 -5
View File
@@ -69,8 +69,8 @@ impl Cell {
pub fn random(lines: i32, cols: i32) -> Cell {
let mut rng = rand::thread_rng();
Cell::new(
rng.gen_range(0..lines),
rng.gen_range(0..cols),
rng.gen_range(1..lines),
rng.gen_range(1..cols),
CellType::Food,
)
}
@@ -127,8 +127,8 @@ impl Board {
let (snake_line, snake_col): (i32, i32) = snake.posyx();
if (snake_line >= self.maxlines)
|| (snake_col >= self.maxcols)
|| (snake_line <= 0)
|| (snake_col <= 0)
|| (snake_line < 0)
|| (snake_col < 0)
{
self.gamestate = GameState::Failed(FailState::Wall);
return true;
@@ -175,7 +175,7 @@ pub struct Snake {
head: Cell,
body: LinkedList<Cell>,
direction: Direction,
pub grow: bool,
grow: bool,
}
impl Snake {
pub fn new(head: Cell) -> Snake {
+4 -7
View File
@@ -52,18 +52,15 @@ pub fn log(snake: &Snake, board: &Board) {
mvwaddstr(stdscr(), 0, 0, &format!("snake:head: {} {} ", shl, shc));
mvwaddstr(stdscr(), 1, 0, &format!("board:food: {} {} ", bfl, bfc));
wmove(stdscr(), 2, 0);
for snake_cell in snake.iter() {
let (scl, scc): (i32, i32) = snake_cell.posyx();
waddstr(stdscr(), &format!("cell: {} {} ", scl, scc));
}
// for snake_cell in snake.iter() {
// let (scl, scc): (i32, i32) = snake_cell.posyx();
// waddstr(stdscr(), &format!("cell: {} {} ", scl, scc));
// }
// mvwaddstr(
// stdscr(),
// 2,
// 0,
// &format!("snake_size {}", snake.iter().size_hint().0),
// );
if snake.grow {
mvwaddstr(stdscr(), 3, 0, &format!("snake:grew"));
}
wrefresh(stdscr());
}
+7 -3
View File
@@ -37,10 +37,14 @@ pub fn start() {
nodelay(game_win, false);
match menu::pause_menu_control() {
//112 is keycode for 'p'
0 => (), //resume
1 => (), //restart
0 => (), //resume
1 => {
snake =
Snake::new(Cell::new(mlines / 2, mcols / 2, backend::CellType::Snake)); //Initialise snake in the middle of the screen
board = Board::new(mlines - vmargin * 2, mcols - hmargin * 2);
} //restart
2 => break, //exit
_ => (), //other charachters just in case
_ => (), //other charachters just in case
}
wrefresh(game_win);
nodelay(game_win, true);