pub async fn new<'terminal>(
        screen: &mut Screen<'terminal>,
    ) -> Result<Self, Error> {
        // Tile for the snake's body.
        let grapheme = TermGrapheme::new_lossy("O");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::White.into(),
        };
        let body_tile = Tile { grapheme, colors };

        // Tile for the snake's head.
        let grapheme = TermGrapheme::new_lossy("@");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::White.into(),
        };
        let head_tile = Tile { grapheme, colors };

        // Tile for the food/fruit.
        let grapheme = TermGrapheme::new_lossy("ɔ́");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightRed.into(),
        };
        let food_tile = Tile { grapheme, colors };

        // Tile for the vertical component of the border.
        let grapheme = TermGrapheme::new_lossy("|");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let vertical_tile = Tile { grapheme, colors };

        // Tile for the horizontal component of the border.
        let grapheme = TermGrapheme::new_lossy("—");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let horizontal_tile = Tile { grapheme, colors };

        // Tile for the corner component of the border.
        let grapheme = TermGrapheme::new_lossy("+");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let corner_tile = Tile { grapheme, colors };

        // Message shown above the border.
        let message = tstring!["ESC to exit, arrows to move"];

        // Bounds of the plane (where the snake is allowed to go to).
        let bounds = Self::make_bounds(screen.size());

        // Initialization of snake and food.
        let snake = Snake::new(body_tile, head_tile, bounds);
        let food = Food::new(food_tile, &snake, bounds);

        Ok(Self {
            bounds,
            snake,
            food,
            corner_tile,
            vertical_tile,
            horizontal_tile,
            message,
            state: State::Running,
        })
    }
/// Initializes the game state, given terminal info.
Initializes the game state, given terminal info.
Initializes the game state given terminal info .
pub async fn new<'terminal>(
        screen: &mut Screen<'terminal>,
    ) -> Result<Self, Error> {
        // Tile for the snake's body.
        let grapheme = TermGrapheme::new_lossy("O");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::White.into(),
        };
        let body_tile = Tile { grapheme, colors };
        // Tile for the snake's head.
        let grapheme = TermGrapheme::new_lossy("@");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::White.into(),
        };
        let head_tile = Tile { grapheme, colors };
        // Tile for the food/fruit.
        let grapheme = TermGrapheme::new_lossy("ɔ́");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightRed.into(),
        };
        let food_tile = Tile { grapheme, colors };
        // Tile for the vertical component of the border.
        let grapheme = TermGrapheme::new_lossy("|");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let vertical_tile = Tile { grapheme, colors };
        // Tile for the horizontal component of the border.
        let grapheme = TermGrapheme::new_lossy("—");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let horizontal_tile = Tile { grapheme, colors };
        // Tile for the corner component of the border.
        let grapheme = TermGrapheme::new_lossy("+");
        let colors = Color2 {
            foreground: BasicColor::Black.into(),
            background: BasicColor::LightGreen.into(),
        };
        let corner_tile = Tile { grapheme, colors };
        // Message shown above the border.
        let message = tstring!["ESC to exit, arrows to move"];
        // Bounds of the plane (where the snake is allowed to go to).
        let bounds = Self::make_bounds(screen.size());
        // Initialization of snake and food.
        let snake = Snake::new(body_tile, head_tile, bounds);
        let food = Food::new(food_tile, &snake, bounds);
        Ok(Self {
            bounds,
            snake,
            food,
            corner_tile,
            vertical_tile,
            horizontal_tile,
            message,
            state: State::Running,
        })
    }
pub async fn new < ' terminal > ( screen : & mut Screen < ' terminal > , ) -> Result < Self , Error > { // Tile for the snake's body. let grapheme = TermGrapheme :: new_lossy ( " " ) ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: White . into ( ) , } ; let body_tile = Tile { grapheme , colors } ; // Tile for the snake's head. let grapheme = TermGrapheme :: new_lossy ( " " ) ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: White . into ( ) , } ; let head_tile = Tile { grapheme , colors } ; // Tile for the food/fruit. let grapheme = TermGrapheme :: new_lossy ( " ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: LightRed . into ( ) , } ; let food_tile = Tile { grapheme , colors } ; // Tile for the vertical component of the border. let grapheme = TermGrapheme :: new_lossy ( " " ) ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: LightGreen . into ( ) , } ; let vertical_tile = Tile { grapheme , colors } ; // Tile for the horizontal component of the border. let grapheme = TermGrapheme :: new_lossy ( " ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: LightGreen . into ( ) , } ; let horizontal_tile = Tile { grapheme , colors } ; // Tile for the corner component of the border. let grapheme = TermGrapheme :: new_lossy ( " " ) ; let colors = Color2 { foreground : BasicColor :: Black . into ( ) , background : BasicColor :: LightGreen . into ( ) , } ; let corner_tile = Tile { grapheme , colors } ; // Message shown above the border. let message = tstring ! [ " " ] ; // Bounds of the plane (where the snake is allowed to go to). let bounds = Self :: make_bounds ( screen . size ( ) ) ; // Initialization of snake and food. let snake = Snake :: new ( body_tile , head_tile , bounds ) ; let food = Food :: new ( food_tile , & snake , bounds ) ; Ok ( Self { bounds , snake , food , corner_tile , vertical_tile , horizontal_tile , message , state : State :: Running , } ) }
Initializes the game state, given terminal info.
Initializes the game state given terminal info .
screen
&mut Screen<'terminal>
screen
&mut Screen<'terminal>