Module: GamesAndRpgParadise::ShakesAndFidgets::Shared

Includes:
ColourE
Included in:
Armour, Stadtwache, UserInput
Defined in:
lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb

Overview

include ShakesAndFidgets::Shared

Instance Method Summary collapse

Instance Method Details

#calculate_cost_for_n_increase_of_attribute(n_times_increased_already = 0) ⇒ Object

#

calculate_cost_for_n_increase_of_attribute

This method expects that you will pass the amount of times that this specific attribute was already improved.

#


136
137
138
139
140
141
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 136

def calculate_cost_for_n_increase_of_attribute(
    n_times_increased_already = 0
  )
  cost = 25 + ((n_times_increased_already + 1) * 5)
  return cost
end

#fetch_user_input(prompt_to_use = PROMPT) ⇒ Object Also known as: obtain_user_input

#

fetch_user_input

Since Mar 2014 @user_input will be an Array.

#


119
120
121
122
123
124
125
126
127
128
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 119

def fetch_user_input(prompt_to_use = PROMPT)
  prompt_to_use = '' if prompt_to_use == :no_prompt
  @user_input = Readline.readline(prompt_to_use, true)
  if @user_input.include? ';'
    @user_input = @user_input.split(';')
  else # else turn it into an Array.
    @user_input = [ @user_input ]
  end
  return @user_input
end

#load_yaml(i) ⇒ Object

#

load_yaml

Wrapper around YAML.load_file.

#


87
88
89
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 87

def load_yaml(i)
  YAML.load_file(i)
end

#report_nameObject

#

report_name

Colouredized output.

#


96
97
98
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 96

def report_name
  ee sfancy('ShakesAndFidgets: ')
end

#save_character(character_object) ⇒ Object Also known as: save_charakter

#

save_character (save tag)

Use this method to save the important values of a Character.

Right now only XP (but may include attributes and items in the future).

#


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 150

def save_character(character_object)
  name = character_object.name.to_s
  store_here = STORE_WHERE.gsub(
    /(\.yml$)/, name+'\\1'
  )
  hash = { 'xp' => character_object.xp } # Add XP here.
  stats = character_object.stats?
  hash.merge!(stats)
  e 'Saving the amount of XP ('+simp(hash['xp'].to_s+' XP')+
    ') and the stats from character `'+sfancy(character_object.name.capitalize)+
    '` into the file'
  e '  '+sfile(store_here)
  armours = character_object.armours?
  hash.merge! armours # Add the armours.
  begin
    File.open(store_here, 'w+') {|entry| YAML.dump(sanitized_hash, entry) }
  rescue Exception => error
    opnn; e 'An error happened in the file shared/shared.rb!'
    pp error
    pp sanitized_hash
    pp error
  end
end

#user_inputObject Also known as: get_user_input

#

user_input

#


103
104
105
106
107
108
109
110
111
112
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/shared/shared.rb', line 103

def user_input
  # ======================================================================= #
  # === Check whether we have readline
  # ======================================================================= #
  if ::ShakesAndFidgets::HAS_READLINE
    Readline.readline.chomp
  else
    $stdin.gets.chomp
  end
end