Class: SplendorGame::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/splendor_game/options.rb

Constant Summary collapse

NOBLES_AVAILABLE =
{ 2 => 3, 3 => 4, 4 => 5}
STARTING_GOLD_TOKENS =
5
STARTING_NON_GOLD_TOKENS =
{ 2 => 4, 3 => 5, 4 => 7}
DISPLAY_CARDS_PER_ROW =
4
WINNING_SCORE =
15
MIN_TO_TAKE_TWO =
4
PLAYER_TOKEN_LIMIT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_options = nil) ⇒ Options

Returns a new instance of Options.



12
13
14
15
16
17
18
# File 'lib/splendor_game/options.rb', line 12

def initialize(user_options = nil)
  if user_options.is_a?(Hash)
    @user_options = user_options 
  else
    @user_options = Hash.new()
  end
end

Instance Attribute Details

#bankObject (readonly)

Returns the value of attribute bank.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def bank
  @bank
end

#deckObject (readonly)

Returns the value of attribute deck.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def deck
  @deck
end

#displayObject (readonly)

Returns the value of attribute display.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def display
  @display
end

#noblesObject (readonly)

Returns the value of attribute nobles.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def nobles
  @nobles
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def options
  @options
end

#playersObject (readonly)

Returns the value of attribute players.



11
12
13
# File 'lib/splendor_game/options.rb', line 11

def players
  @players
end

Instance Method Details

#clean_user_optionsObject



20
21
22
23
24
25
26
# File 'lib/splendor_game/options.rb', line 20

def clean_user_options
  [:starting_non_gold_tokens, :nobles_available].each do |key|
    if @user_options[key].respond_to?(:keys)
      @user_options.delete(key) if !([2,3,4] - @user_options[key].keys).empty?
    end
  end
end

#default_optionsObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/splendor_game/options.rb', line 28

def default_options
  output = Hash.new()
  output[:display_cards_per_row] = DISPLAY_CARDS_PER_ROW
  output[:winning_score] = WINNING_SCORE
  output[:min_to_take_two] = MIN_TO_TAKE_TWO
  output[:starting_gold_tokens] = STARTING_GOLD_TOKENS
  output[:starting_non_gold_tokens] = STARTING_NON_GOLD_TOKENS
  output[:nobles_available] = NOBLES_AVAILABLE
  output[:player_token_limit] = PLAYER_TOKEN_LIMIT
  output
end

#give_optionsObject

Take the user values if they are valid, else use defaults



41
42
43
44
# File 'lib/splendor_game/options.rb', line 41

def give_options
  clean_user_options
  @user_options.merge(default_options)
end