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
impl Game
sourcefn print_board(&self, out: &mut Stdout) -> Result<(), Error>
fn print_board(&self, out: &mut Stdout) -> Result<(), Error>
Prints the game board layout to the terminal.
sourcefn print_chrome(out: &mut Stdout, move_count: u32) -> Result<(), Error>
fn print_chrome(out: &mut Stdout, move_count: u32) -> Result<(), Error>
Prints the game chrome (title, side bars, etc.) to the terminal.
source§impl Game
impl Game
sourcepub fn toggle_high_contrast(&mut self)
pub fn toggle_high_contrast(&mut self)
Toggles high contrast mode, making diamonds magenta and spades yellow.
sourcepub fn move_cursor_left(&mut self)
pub fn move_cursor_left(&mut self)
Moves the cursor to the left on the game field, skipping invalid spots.
sourcepub fn move_cursor_right(&mut self)
pub fn move_cursor_right(&mut self)
Moves the cursor to the right on the game field, skipping invalid spots.
sourcepub fn quick_stack_to_foundations(&mut self)
pub fn quick_stack_to_foundations(&mut self)
Quick stacks all visible cards to the foundation piles, recursively.
sourcepub fn handle_card_press(&mut self)
pub fn handle_card_press(&mut self)
Handles the event where a player clicks space/enter on a card.
sourcepub fn player_try_execute_move(&mut self, from: usize, to: usize)
pub fn player_try_execute_move(&mut self, from: usize, to: usize)
Executes a player move if it is valid.
sourcepub fn perform_undo(&mut self)
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.
sourcefn are_opposite_colors(card1: Card, card2: Card) -> bool
fn are_opposite_colors(card1: Card, card2: Card) -> bool
Checks if two cards are of opposite colors.
sourcefn move_is_valid(&self, from: usize, to: usize) -> bool
fn move_is_valid(&self, from: usize, to: usize) -> bool
Checks if a move from one position to another is valid.
sourcefn execute_move(&mut self, from: usize, to: usize)
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
.