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>
impl<'a, 'b> FruitsManager<'a, 'b>
Sourcepub fn new(nb: u16, carte: Arc<RwLock<Map<'b>>>) -> Self
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);
Sourcefn spawn_random(carte: &Map<'_>) -> Fruit<'a>
fn spawn_random(carte: &Map<'_>) -> Fruit<'a>
Spawns a fruit at a random position on the map.
Sourcepub fn replace_fruits(&mut self, fruits_to_remove: &[Fruit<'a>])
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)
Sourcepub fn eat_some_fruits(&self, position: &Position) -> Option<Vec<Fruit<'a>>>
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.
Sourcefn generate_position_rounded_by_cs(carte: &Map<'_>) -> Position
fn generate_position_rounded_by_cs(carte: &Map<'_>) -> Position
Generates a random valid position for spawning fruits.
pub(crate) fn resize_to_terminal(&mut self)
Trait Implementations§
Source§impl<'a> Widget for &FruitsManager<'a, 'a>
impl<'a> Widget for &FruitsManager<'a, 'a>
Source§impl<'a> Widget for FruitsManager<'a, 'a>
Implements Widget
for compatibility with older versions.
impl<'a> Widget for FruitsManager<'a, 'a>
Implements Widget
for compatibility with older versions.
Source§impl<'a> WidgetRef for FruitsManager<'a, 'a>
Implements WidgetRef
for rendering fruits on the screen.
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)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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