Struct rusty_freecell::game::Game

source ·
pub struct Game {
    field: [Vec<Card>; 16],
    highlighted_card: usize,
    selected_card_opt: Option<usize>,
    undo_history: CircularBuffer<UNDO_LEVELS, Move>,
    move_count: u32,
    high_contrast: bool,
}
Expand description

Represents the state of a FreeCell game.

Fields§

§field: [Vec<Card>; 16]

The playing field, consisting of stacks of cards.

§highlighted_card: usize

The index of the card the player currently has highlighted

§selected_card_opt: Option<usize>

The index of the card the player has marked to be moved, if any.

§undo_history: CircularBuffer<UNDO_LEVELS, Move>

The circular buffer storing the game’s undo history.

§move_count: u32

The number of moves made so far in the game.

§high_contrast: bool

Indicates whether the game is in high contrast mode, where each suit is printed in a different color.

Implementations§

source§

impl Game

source

pub fn print(&self, out: &mut Stdout) -> Result<(), Error>

Prints the game state to the terminal.

§Arguments
  • out - A mutable reference to the standard output stream.
§Returns

A Result indicating success or an error if writing to the output stream fails.

source

fn print_board(&self, out: &mut Stdout) -> Result<(), Error>

Prints the game board layout to the terminal.

source

fn print_chrome(out: &mut Stdout, move_count: u32) -> Result<(), Error>

Prints the game chrome (title, side bars, etc.) to the terminal.

source

fn print_card_at_coord( out: &mut Stdout, x: u16, y: u16, card: Card, highlighted: bool, selected: bool, high_contrast: bool ) -> Result<(), Error>

Prints a card at the specified coordinates on the terminal.

source

fn print_win(out: &mut Stdout) -> Result<(), Error>

Prints the win message to the terminal.

source

fn print_string_at_coord( out: &mut Stdout, string: &str, x: u16, y: u16 ) -> Result<(), Error>

Prints a string at the specified coordinates on the terminal.

source§

impl Game

source

pub fn new(rng: &mut ThreadRng) -> Game

Creates a new instance of the FreeCell game.

§Arguments
  • rng - A mutable reference to a random number generator.
§Returns

A new Game instance.

source

pub fn is_won(&self) -> bool

Checks if the game has been won.

§Returns

true if the game has been won, otherwise false.

source

pub fn toggle_high_contrast(&mut self)

Toggles high contrast mode, making diamonds magenta and spades yellow.

source

pub fn move_cursor_left(&mut self)

Moves the cursor to the left on the game field, skipping invalid spots.

source

pub fn move_cursor_right(&mut self)

Moves the cursor to the right on the game field, skipping invalid spots.

source

pub fn quick_stack_to_foundations(&mut self)

Quick stacks all visible cards to the foundation piles, recursively.

source

pub fn handle_card_press(&mut self)

Handles the event where a player clicks space/enter on a card.

source

pub fn player_try_execute_move(&mut self, from: usize, to: usize)

Executes a player move if it is valid.

source

pub fn perform_undo(&mut self)

Undoes the last move made by the player. Can be used multiple times to travel back in the game’s history.

source

fn are_opposite_colors(card1: Card, card2: Card) -> bool

Checks if two cards are of opposite colors.

source

fn move_is_valid(&self, from: usize, to: usize) -> bool

Checks if a move from one position to another is valid.

source

fn execute_move(&mut self, from: usize, to: usize)

Executes a move from one position to another, not checking if it follows the rules. To try executing a move in a way that fails if the move does not follow the rules, use player_try_execute_move.

Auto Trait Implementations§

§

impl Freeze for Game

§

impl RefUnwindSafe for Game

§

impl Send for Game

§

impl Sync for Game

§

impl Unpin for Game

§

impl UnwindSafe for Game

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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