Class: GamesAndRpgParadise::ShakesAndFidgets::Waffenladen

Inherits:
Object
  • Object
show all
Includes:
Colours::E, Colours
Defined in:
lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb

Constant Summary collapse

WEAPONS =
YAML.load_file(_)

Constants included from Colours

Colours::WHITE

Instance Method Summary collapse

Methods included from Colours

#brown, #cfile, #convert_colour, convert_colour, #fancy, #normal, #pink, #red, #yel

Constructor Details

#initialize(optional_character_dataset = nil, run_already = true) ⇒ Waffenladen

#

initialize

#


33
34
35
36
37
38
39
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 33

def initialize(
    optional_character_dataset = nil,
    run_already = true
  )
  set_character_dataset(optional_character_dataset)
  run if run_already
end

Instance Method Details

#ask_user_which_one_to_buyObject

#

ask_user_which_one_to_buy

#


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 76

def ask_user_which_one_to_buy
  e
  e 'Which one do you wish to buy?'
  n = fetch_user_input :no_prompt
  n = (n.first.to_i - 1) if n.is_a? Array
  e 'You decided to buy:'
  p (n+1)
  item_to_buy = inv?[n] # This will be a hash.
  name_of_the_item = item_to_buy.keys.first
  cost = item_to_buy[name_of_the_item]['Kosten']
  e 'It will cost '+cost.to_s+'.'
  has_enough_money = cost < @character_dataset.coins?
  if has_enough_money
    @character_dataset.deduct_money(cost)
    e 'You bought '+sfancy(name_of_the_item)+'.'
    @character_dataset.inventory << name_of_the_item
  else
    e 'You do not have enough money to buy '+sfancy(name_of_the_item)+'.' 
  end
end

#display_inventoryObject

#

display_inventory

Note that @inventory refers to the inventory of the shop.

#


109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 109

def display_inventory
  e
  e 'This shop has the following weapons for sale:'
  e
  @inventory.each_with_index {|hash, index|
    name_of_the_weapon = hash.keys.first
    cost = hash[name_of_the_weapon]['Kosten']
    index += 1
    name_of_the_weapon = name_of_the_weapon.ljust(15)
    e '  ('+sfancy(index.to_s)+') '+
      name_of_the_weapon+
      ' (cost: '+cost.to_s+' silver)'
  }
end

#enter_shopObject

#

enter_shop

#


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 58

def enter_shop
  e 'You enter the weapon shop and glance at the various '+
    'offered weapons.'
  e 'TODO: 6 slots are available'
  @inventory = [] # An Array.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  @inventory << Hash[WEAPONS.to_a.sample(1)] # This will obtain a random element.
  display_inventory
  ask_user_which_one_to_buy
end

#inventory?Boolean Also known as: inv?

#

inventory?

#

Returns:

  • (Boolean)


100
101
102
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 100

def inventory?
  @inventory
end

#runObject

#

run

#


51
52
53
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 51

def run
  enter_shop
end

#set_character_dataset(i) ⇒ Object

#

set_character_dataset

#


44
45
46
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/waffenladen/waffenladen.rb', line 44

def set_character_dataset(i)
  @character_dataset = i
end