Pokex v0.2.0 Player View Source
The Player model.
Player is defined by name
, wallet
and his hand
of cards.
Link to this section Summary
Functions
Returns a %Player{}
struct from the tuple {name, wallet}
given
Adds the given amount to the player’s wallet
Removes the cards in cards
from player’s hand and replaces them with cards in for_cards
Adds a hand to the player
Adds a hand to the player
Withdraws the amount given from the player’s wallet
Link to this section Functions
Returns a %Player{}
struct from the tuple {name, wallet}
given.
wallet
cannot be a negative number.
Returns a tuple {:ok, player}
or {:error, "Reason"}
.
Example
iex> Player.create({"Maria", 1000.0})
{:ok, %Player{name: "Maria", wallet: 1000.0, hand: nil}}
iex> Player.create({"Maria", -1000.0})
{:error, "Negative initial wallet amount not allowed"}
Adds the given amount to the player’s wallet.
The amount has to be a positive number.
Returns the player.
Examples
iex> Player.deposit(%Player{name: "Nick"}, 50)
%Player{name: "Nick", wallet: 50.0, hand: nil}
Removes the cards in cards
from player’s hand and replaces them with cards in for_cards
.
Returns the %Player{}
with the updated :hand
.
Examples
iex> Player.exchange(%Player{name: "Nick", hand: [{6, :clubs}, {3, :spades}, {9, :spades}, {4, :diamonds}, {6, :hearts}]}, [{4, :diamonds}, {6, :hearts}], [{:ace, :spades}, {2, :hearts}])
%Player{name: "Nick", hand: [{:ace, :spades}, {2, :hearts}, {6, :clubs}, {3, :spades}, {9, :spades}], wallet: 0.0}
Adds a hand to the player.
Overrides any previous hand in :hand
Adds a hand to the player.
Throws exception if there is a previous hand assigned
Withdraws the amount given from the player’s wallet.
The amount has to be a positive number.
The amount cannot be more than the player’s balance (wallet).
Returns the player.
Examples
iex> Player.withdraw(%Player{name: "Maria", wallet: 100.0}, 30)
%Player{name: "Maria", wallet: 70.0, hand: nil}
iex> Player.withdraw(%Player{name: "Nick", wallet: 100.0}, 100.0)
%Player{name: "Nick", wallet: 0.0, hand: nil}