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
+11 -3
View File
@@ -1,6 +1,14 @@
# Snake in rust
Trying to make a snake game in rust using ncurses.
It is nowhere near complete.
This is for me to learn rust better.
The game is playable
run with
```bash
cargo run
```
- To fix bugs
- To Implement the highscore system
Learning from [ncurses](https://docs.rs/ncurses)
+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);
View File
View File
+3
View File
@@ -0,0 +1,3 @@
pub fn show() {
// highscore_file = backend::load(
}
+2 -1
View File
@@ -1,5 +1,6 @@
extern crate ncurses;
mod game;
mod highscore;
mod menu;
// use game::{Cell, Snake};
// use ncurses::*;
@@ -15,7 +16,7 @@ fn main() {
loop {
match menu::main_menu_control() {
0 => game::start(),
1 => (),
1 => highscore::show(),
_ => break,
}
}