fn move_snake(&mut self) {
        match self.snake.mov(self.bounds, &self.food) {
            // Handles the case where the food was eaten.
            Some(eaten) => {
                if self.snake.length() >= self.win_size() {
                    self.state = State::Ended(EndKind::Win);
                } else if eaten {
                    // Handles the case where the food was eaten: it needs to be
                    // regenerated.
                    self.food.regenerate(&self.snake, self.bounds);
                }

                if self.snake.head_intersects() {
                    // If the head intersects the body, game over.
                    self.state = State::Ended(EndKind::Loss)
                }
            },

            // Out of bounds. End of the game.
            None => self.state = State::Ended(EndKind::Loss),
        }
    }
/// Moves the snake in the current direction.
Moves the snake in the current direction.
Moves the snake in the current direction .
fn move_snake(&mut self) {
        match self.snake.mov(self.bounds, &self.food) {
            // Handles the case where the food was eaten.
            Some(eaten) => {
                if self.snake.length() >= self.win_size() {
                    self.state = State::Ended(EndKind::Win);
                } else if eaten {
                    // Handles the case where the food was eaten: it needs to be
                    // regenerated.
                    self.food.regenerate(&self.snake, self.bounds);
                }
                if self.snake.head_intersects() {
                    // If the head intersects the body, game over.
                    self.state = State::Ended(EndKind::Loss)
                }
            },
            // Out of bounds. End of the game.
            None => self.state = State::Ended(EndKind::Loss),
        }
    }
fn move_snake ( & mut self ) { match self . snake . mov ( self . bounds , & self . food ) { // Handles the case where the food was eaten. Some ( eaten ) => { if self . snake . length ( ) >= self . win_size ( ) { self . state = State :: Ended ( EndKind :: Win ) ; } else if eaten { // Handles the case where the food was eaten: it needs to be // regenerated. self . food . regenerate ( & self . snake , self . bounds ) ; } if self . snake . head_intersects ( ) { // If the head intersects the body, game over. self . state = State :: Ended ( EndKind :: Loss ) } } , // Out of bounds. End of the game. None => self . state = State :: Ended ( EndKind :: Loss ) , } }
Moves the snake in the current direction.
Moves the snake in the current direction .
&mut self
&mut self