pub struct Snake { /* private fields */ }
Expand description
Instance of game Snake containing board state, rng, and display
Implementations§
Source§impl Snake
impl Snake
Sourcepub fn current_direction(&self) -> Direction
pub fn current_direction(&self) -> Direction
Returns current direction of snake
Sourcepub fn walls(&self) -> Vec<f32>
pub fn walls(&self) -> Vec<f32>
Returns distance of head from walls in the following order left, up-left, up, up-right, right, down-right, down, down-left
Sourcepub fn snake(&self) -> Vec<f32>
pub fn snake(&self) -> Vec<f32>
Returns distance of head from snake in each direction in the following order left, up-left, up, up-right, right, down-right, down, down-left
Sourcepub fn food(&self) -> Vec<f32>
pub fn food(&self) -> Vec<f32>
Returns distance of head from food in each direction in the following order left, up-left, up, up-right, right, down-right, down, down-left
Sourcepub fn turn(&mut self, dir: Direction) -> bool
pub fn turn(&mut self, dir: Direction) -> bool
Elapses game one move. Returns true if game is still active and false if game is over (once snake has died).
§Arguments
dir
- Direction for the snake to move. If the provided direction is center or opposite the last provided direction (left/right, up/down), the snake will continue in the last provided direction
Auto Trait Implementations§
impl Freeze for Snake
impl RefUnwindSafe for Snake
impl Send for Snake
impl Sync for Snake
impl Unpin for Snake
impl UnwindSafe for Snake
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more