Class: Gambler::Game::BasicGame
- Inherits:
-
Object
- Object
- Gambler::Game::BasicGame
- Defined in:
- lib/gambler/game/basic_game.rb
Overview
The basic game class in which all others can inherit. Feel free to create your own game class which does not inherit from BasicGame, but uses Player, Deck, etc. directly.
BasicGame gives some free functionality to it’s children:
-
players
: Instance reader for the game’s Player(s). -
ante
: Instance accessor for the game’s current ante. -
deck
: Brand new, fully shuffled Deck to play with. -
pot
: Instance accessor for the game’s current pot.
The options
hash only requires one element, players
, which must be an array of Gambler::Player object(s).
Example:
class Poker < Gambler::Game::BasicGame
def initialize( = {})
# .. do custom shit (if needed) ..
super() # Required to recieve free functionality.
# .. more custom shit (if needed) ..
end
def poker_stuff
!cheat
end
end
# Create some players.
@dale = Gambler::Player.new('Dale')
@kenny = Gambler::Player.new('Kenny')
# This will be passed to Poker.new.
= {
:players => [@dale, @kenny], # The only required option.
:ante => 50,
:pot => 1_000
}
@game = Poker.new()
@game.poker_stuff
Direct Known Subclasses
Constant Summary collapse
- INITIAL_ANTE =
10
- INITIAL_POT =
0
Instance Attribute Summary collapse
-
#ante ⇒ Object
Returns the value of attribute ante.
-
#deck ⇒ Object
Returns the value of attribute deck.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#pot ⇒ Object
Returns the value of attribute pot.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BasicGame
constructor
A new instance of BasicGame.
Constructor Details
#initialize(options = {}) ⇒ BasicGame
Returns a new instance of BasicGame.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gambler/game/basic_game.rb', line 51 def initialize( = {}) raise Exceptions::NoPlayers unless [:players].size > 0 [:players].each do |player| raise Exceptions::InvalidPlayers unless player.is_a? Player end @players = [:players] @deck = Deck.new 3.times { @deck.shuffle! } @ante = [:ante] || INITIAL_ANTE @pot = [:pot] || INITIAL_POT end |
Instance Attribute Details
#ante ⇒ Object
Returns the value of attribute ante.
49 50 51 |
# File 'lib/gambler/game/basic_game.rb', line 49 def ante @ante end |
#deck ⇒ Object
Returns the value of attribute deck.
49 50 51 |
# File 'lib/gambler/game/basic_game.rb', line 49 def deck @deck end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
48 49 50 |
# File 'lib/gambler/game/basic_game.rb', line 48 def players @players end |
#pot ⇒ Object
Returns the value of attribute pot.
49 50 51 |
# File 'lib/gambler/game/basic_game.rb', line 49 def pot @pot end |