Struct snake::Snake [−][src]
Instance of game Snake containing board state, rng, and display
Implementations
impl Snake
[src]
pub fn new(seed: u64, size: u8) -> Snake
[src]
Creates a game instance with no display
Arguments
seed
- Seed for random generation of foodsize
- The width/height of game board grid
Example
use snake::Snake; let mut game = Snake::new(0, 10);
pub fn length(&self) -> usize
[src]
Returns length of snake
pub fn current_direction(&self) -> Direction
[src]
Returns current direction of snake
pub fn walls(&self) -> Vec<f32>
[src]
Returns distance of head from walls in the following order left, up-left, up, up-right, right, down-right, down, down-left
pub fn snake(&self) -> Vec<f32>
[src]
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
pub fn food(&self) -> Vec<f32>
[src]
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
pub fn turn(&mut self, dir: Direction) -> bool
[src]
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 RefUnwindSafe for Snake
impl Send for Snake
impl Sync for Snake
impl Unpin for Snake
impl UnwindSafe for Snake
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,