[][src]Struct slot_machine::game::Game

pub struct Game { /* fields omitted */ }

Game state

Implementations

impl Game[src]

pub fn new(
    credits: u32,
    bet: u32,
    bet_min: u32,
    bet_max: u32
) -> Result<Self, InvalidBet>
[src]

Creates new Game instance. The winnings are 0.

Examples

Game::new(1000, 1, 1, 100);

Errors

Returns InvalidBet if bet_min > bet_max or bet < bet_min or bet > bet_max.

pub fn set_bet(&mut self, bet: u32) -> Result<(), InvalidBet>[src]

Bet setter.

Errors

Returns InvalidBet if bet < Game::bet_min or bet > Game::bet_max.

pub fn bet(&self) -> u32[src]

Returns the bet size in credits

pub fn min(&self) -> u32[src]

Returns the minimum allowable bet

pub fn max(&self) -> u32[src]

Returns the maximum allowable bet

pub fn credits(&self) -> u32[src]

Returns the number of credits in the balance

pub fn win(&self) -> u32[src]

Returns the amount of the last win

pub fn spin(&mut self) -> Result<Vec<Symbol>, LowBalance>[src]

Simulates the rotation of the reels slot machine.

Returns symbols on the reels. Also changes state of the Game depending on the size of the bet and winnings.

Errors

Returns LowBalance if the number of credits in the balance credits is less than the bet size bet.

Examples

let mut game = Game::new(1000, 1, 1, 100).unwrap();
game.spin().unwrap();

// The new value of credits equals `old_value_of_credits - bet_size + winning`
assert_eq!(game.credits(), 1000 - 1 + game.win());

pub fn to_json(&self) -> String[src]

Converts an instance to a Json object.

Trait Implementations

impl Clone for Game[src]

impl Debug for Game[src]

impl<'de> Deserialize<'de> for Game[src]

impl PartialEq<Game> for Game[src]

impl Serialize for Game[src]

impl StructuralPartialEq for Game[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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