fn step(&mut self) -> GameState {
        self.counter += 1;
        if self.counter % self.speed as u64 != 0 {
            return GameState::Live;
        }
        if self.game_over {
            return GameState::GameOver;
        }
        // update snake head
        let mut new_head = self.snake_head;
        if self.direction == Direction::Up {
            new_head.y -= BLOCK_SIZE;
        } else if self.direction == Direction::Right {
            new_head.x += BLOCK_SIZE;
        } else if self.direction == Direction::Down {
            new_head.y += BLOCK_SIZE;
        } else if self.direction == Direction::Left {
            new_head.x -= BLOCK_SIZE;
        }
        new_head.x = new_head.x % self.width;
        new_head.y = new_head.y % self.height;

        self.snake_body.push_back(self.snake_head);
        self.snake_head = new_head;
        if let Some(food) = self.food {
            if self.snake_head == food {
                serial_println!("found food!!!");
                self.score += 1;
                self.food = None;
                self.snake_length += 1;
            } else {
                self.snake_tail = self.snake_body.pop_front();
            }
        } else {
            self.place_random_food();
            self.snake_tail = self.snake_body.pop_front();
        }
        if self.snake_head.x >= self.width - 2 * BLOCK_SIZE
            || self.snake_head.y >= self.height - 2 * BLOCK_SIZE
            || self.snake_head.x <= BLOCK_SIZE
            || self.snake_head.y <= BLOCK_SIZE
        {
            self.game_over = true;
        }
        for body in self.snake_body.iter() {
            if self.snake_head == *body {
                self.game_over = true;
            }
        }

        if self.game_over {
            GameState::GameOver
        } else {
            GameState::Live
        }
    }
// step moves the snake one step forward
step moves the snake one step forward
step moves the snake one step forward
fn step(&mut self) -> GameState {
        self.counter += 1;
        if self.counter % self.speed as u64 != 0 {
            return GameState::Live;
        }
        if self.game_over {
            return GameState::GameOver;
        }
        // update snake head
        let mut new_head = self.snake_head;
        if self.direction == Direction::Up {
            new_head.y -= BLOCK_SIZE;
        } else if self.direction == Direction::Right {
            new_head.x += BLOCK_SIZE;
        } else if self.direction == Direction::Down {
            new_head.y += BLOCK_SIZE;
        } else if self.direction == Direction::Left {
            new_head.x -= BLOCK_SIZE;
        }
        new_head.x = new_head.x % self.width;
        new_head.y = new_head.y % self.height;
        self.snake_body.push_back(self.snake_head);
        self.snake_head = new_head;
        if let Some(food) = self.food {
            if self.snake_head == food {
                serial_println!("found food!!!");
                self.score += 1;
                self.food = None;
                self.snake_length += 1;
            } else {
                self.snake_tail = self.snake_body.pop_front();
            }
        } else {
            self.place_random_food();
            self.snake_tail = self.snake_body.pop_front();
        }
        if self.snake_head.x >= self.width - 2 * BLOCK_SIZE
            || self.snake_head.y >= self.height - 2 * BLOCK_SIZE
            || self.snake_head.x <= BLOCK_SIZE
            || self.snake_head.y <= BLOCK_SIZE
        {
            self.game_over = true;
        }
        for body in self.snake_body.iter() {
            if self.snake_head == *body {
                self.game_over = true;
            }
        }
        if self.game_over {
            GameState::GameOver
        } else {
            GameState::Live
        }
    }
fn step ( & mut self ) -> GameState { self . counter += 1 ; if self . counter % self . speed as u64 != 0 { return GameState :: Live ; } if self . game_over { return GameState :: GameOver ; } // update snake head let mut new_head = self . snake_head ; if self . direction == Direction :: Up { new_head . y -= BLOCK_SIZE ; } else if self . direction == Direction :: Right { new_head . x += BLOCK_SIZE ; } else if self . direction == Direction :: Down { new_head . y += BLOCK_SIZE ; } else if self . direction == Direction :: Left { new_head . x -= BLOCK_SIZE ; } new_head . x = new_head . x % self . width ; new_head . y = new_head . y % self . height ; self . snake_body . push_back ( self . snake_head ) ; self . snake_head = new_head ; if let Some ( food ) = self . food { if self . snake_head == food { serial_println ! ( " " ) ; self . score += 1 ; self . food = None ; self . snake_length += 1 ; } else { self . snake_tail = self . snake_body . pop_front ( ) ; } } else { self . place_random_food ( ) ; self . snake_tail = self . snake_body . pop_front ( ) ; } if self . snake_head . x >= self . width - 2 * BLOCK_SIZE || self . snake_head . y >= self . height - 2 * BLOCK_SIZE || self . snake_head . x <= BLOCK_SIZE || self . snake_head . y <= BLOCK_SIZE { self . game_over = true ; } for body in self . snake_body . iter ( ) { if self . snake_head == * body { self . game_over = true ; } } if self . game_over { GameState :: GameOver } else { GameState :: Live } }
step moves the snake one step forward
step moves the snake one step forward
&mut self
&mut self