[−][src]Struct slot_machine::game::Game
Game state
Implementations
impl Game
[src]
pub fn new(
credits: u32,
bet: u32,
bet_min: u32,
bet_max: u32
) -> Result<Self, InvalidBet>
[src]
credits: u32,
bet: u32,
bet_min: u32,
bet_max: u32
) -> Result<Self, InvalidBet>
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]
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]
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl PartialEq<Game> for Game
[src]
impl Serialize for Game
[src]
pub fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralPartialEq for Game
[src]
Auto Trait Implementations
impl RefUnwindSafe for Game
[src]
impl Send for Game
[src]
impl Sync for Game
[src]
impl Unpin for Game
[src]
impl UnwindSafe for Game
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,