Struct FruitsManager

Source
pub struct FruitsManager<'a, 'b: 'a> {
    fruits: Vec<Fruit<'a>>,
    carte: Arc<RwLock<Map<'b>>>,
}
Expand description

Manages fruit objects within the game logic. Map outlive fruits, so ’b lifetime >= ’a (fruits) lifetime

Fields§

§fruits: Vec<Fruit<'a>>§carte: Arc<RwLock<Map<'b>>>

Implementations§

Source§

impl<'a, 'b> FruitsManager<'a, 'b>

Source

pub fn new(nb: u16, carte: Arc<RwLock<Map<'b>>>) -> Self

Creates a new FruitsManager with a given number of fruits.

§Panics

if guard cannot be got for Map (whenever a previous panic poisoned guard)

§Example
use std::sync::{Arc, RwLock};
use ratatui::layout::Rect;
use rsnaker::game_logic::fruits_manager::FruitsManager;
use rsnaker::graphics::sprites::map::Map;
let x =42;
let map = Arc::new(RwLock::new(Map::new(2, Rect::new(0,0, 160,10))));
let manager = FruitsManager::new(3, map);
Source

fn spawn_random(carte: &Map<'_>) -> Fruit<'a>

Spawns a fruit at a random position on the map.

Source

pub fn replace_fruits(&mut self, fruits_to_remove: &[Fruit<'a>])

Replaces eaten fruits with new random ones and ensures balance.

§Panics

if guard cannot be got for Map (whenever a previous panic poisoned guard)

Source

pub fn eat_some_fruits(&self, position: &Position) -> Option<Vec<Fruit<'a>>>

Returns a list of fruits at the given position, copying them to avoid lock contention.

Source

fn generate_position_rounded_by_cs(carte: &Map<'_>) -> Position

Generates a random valid position for spawning fruits.

Source

pub(crate) fn resize_to_terminal(&mut self)

Trait Implementations§

Source§

impl<'a> Widget for &FruitsManager<'a, 'a>

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl<'a> Widget for FruitsManager<'a, 'a>

Implements Widget for compatibility with older versions.

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl<'a> WidgetRef for FruitsManager<'a, 'a>

Implements WidgetRef for rendering fruits on the screen.

Source§

fn render_ref(&self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for FruitsManager<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for FruitsManager<'a, 'b>

§

impl<'a, 'b> Send for FruitsManager<'a, 'b>

§

impl<'a, 'b> Sync for FruitsManager<'a, 'b>

§

impl<'a, 'b> Unpin for FruitsManager<'a, 'b>

§

impl<'a, 'b> UnwindSafe for FruitsManager<'a, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V