Class: GamesAndRpgParadise::Mechwars::Mech
- Defined in:
- lib/games_and_rpg_paradise/games/mechwars/mech.rb
Overview
GamesAndRpgParadise::Mechwars::Mech
Constant Summary collapse
- COLOURIZE =
#
COLOURIZE
#
true
- NAMES =
#
NAMES
#
%w( Attack Black Blasted Blue Cougar Crusaders Cyborgs Dallas Day Death Force Freedom Green Hyenas Indian Jacksons Last Lions Loving Meatloaf Net Night Panthers Robot Rose Scouts Seattle Shadow Silent Spider Stealth Tank Team Tigers Unicorn Walkers WestCoast EvilNightmare YellowBoys FranticGirls Sexy )
Instance Attribute Summary collapse
-
#mech_name ⇒ Object
(also: #name)
readonly
Returns the value of attribute mech_name.
-
#object_my_pilot ⇒ Object
readonly
Returns the value of attribute object_my_pilot.
Attributes inherited from Vehicle
#array_weapons, #average_speed, #has_pilot, #height, #length, #maximum_speed, #plating, #type, #weight
Instance Method Summary collapse
-
#condition ⇒ Object
# === condition.
-
#engage_this_target(i) ⇒ Object
(also: #engage_target)
# === engage_this_target.
-
#got_hit(damage_recieved) ⇒ Object
# === got_hit.
-
#initialize ⇒ Mech
constructor
# === initialize ========================================================================= #.
-
#modify_integrity_status(input) ⇒ Object
# === modify_integrity_status.
-
#output(arg, colour = 'yelbonblack') ⇒ Object
(also: #ou, #e)
# === output.
-
#random ⇒ Object
# === random.
-
#report ⇒ Object
# === report.
-
#shoot_at(target) ⇒ Object
# === shoot_at.
Methods inherited from Vehicle
#debug, #fetch_which_yaml_data, #fetch_yaml_data, #reset
Constructor Details
#initialize ⇒ Mech
#
initialize
#
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 73 def initialize e 'Loading Mech ...' @mech_name = '' @name = @mech_name @mech_weight = 20_000 @mech_height = '' # in cm @mech_n_weapons = 3 @base_mech_plating = (1..8).entries.rand @object_my_pilot = Pilot.new() @object_my_pilot.random_name # für nen namen @target = nil # no enemy at start. @integrity_factor = 3 # the amount of damage needed to inflict @base_mech_plating += @integrity_factor # integrity factor also improves plating # before the mech status is downgraded by 1. Higher mechs # have a higher integrity factor, more "material" @mech_status = 100 # keeps a % @integrity_start_status = @integrity_factor * @mech_status @damage = 0 # stores how much damage we were dealt already @deal_this_base_damage = 3 # base damage we deal with our weapon # to check how @integrity has to be altered @integrity_status = @integrity_start_status # Not in use right now. @hash_mech_plating = { 'head' => @base_mech_plating-3, 'arm' => @base_mech_plating-2, 'torso' => @base_mech_plating, 'legs' => @base_mech_plating-1, } end |
Instance Attribute Details
#mech_name ⇒ Object (readonly) Also known as: name
Returns the value of attribute mech_name.
66 67 68 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 66 def mech_name @mech_name end |
#object_my_pilot ⇒ Object (readonly)
Returns the value of attribute object_my_pilot.
65 66 67 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 65 def object_my_pilot @object_my_pilot end |
Instance Method Details
#condition ⇒ Object
#
condition
condition tells you how you are feeling
#
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 126 def condition case @integrity_status when (@integrity_start_status/2)..(@integrity_start_status) e sfancy('You are in a good condition.') when (@integrity_start_status/3)..(@integrity_start_status/2) e swarn('You are slightly damaged.') when 11..(@integrity_start_status/3) e swarn('You are heavily damaged.') when 1..10 e swarn('You are extremely damaged.') when 0 e swarn('You are destroyed!') end end |
#engage_this_target(i) ⇒ Object Also known as: engage_target
#
engage_this_target
Engage a target via this method.
#
231 232 233 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 231 def engage_this_target(i) @target = i end |
#got_hit(damage_recieved) ⇒ Object
#
got_hit
We got hit! Oh no! ;)
The damage it gets is the raw damage. Before we apply it, we reduce the plating.
#
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 210 def got_hit(damage_recieved) e "Ack! You (#{@mech_name}) got hit for #{damage}" damage_recieved -= @mech_plating damage_recieved = 0 if damage_recieved < 0 e "Luckily your armour of #{@mech_plating} reduces "+ "this damage to #{damage_recieved}." modify_integrity_status('-'+damage_recieved) ou "Your status: #{@integrity_status}: " condition if @integrity_status <= 0 ou "You (#{@mech_name}) are - sadly - destroyed!" ou "The pilot #{@object_my_pilot.name} died as well." exit end end |
#modify_integrity_status(input) ⇒ Object
#
modify_integrity_status
Modify integrity status. Usually you use this by deducting.
#
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 108 def modify_integrity_status(input) input = input.to_s case input[-1,1] when '-' @integrity_status -= input.to_i else @integrity_status += input.to_i # addieren end # @integrity_status can never fall below 0. # 0 already means the mech is destroyed. @integrity_status = 0 if @integrity_status <= 0 end |
#output(arg, colour = 'yelbonblack') ⇒ Object Also known as: ou, e
#
output
will just output stuff. ou is an alias to this.
#
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 158 def output(arg, colour='yelbonblack') if COLOURIZE if rand(2) == 0 e arg, colour else e arg, colour end else puts arg end end |
#random ⇒ Object
#
random
This method sets the values randomly. This is in alternative to reading it from a yaml file.
#
147 148 149 150 151 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 147 def random @mech_name = NAMES1.rand << ' ' << NAMES2.rand @mech_weight = (5..154).entries.rand @mech_height = (300..6600).entries.rand end |
#report ⇒ Object
#
report
Gives back values for our mech.
#
176 177 178 179 180 181 182 183 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 176 def report e "Mech name: #{@mech_name}", COLOUR_NORMAL e "Mech weight: #{@mech_weight} tons", COLOUR_NORMAL e "Mech height: #{@mech_height} cm", COLOUR_NORMAL e "Mech n weapons: #{@mech_n_weapons}", COLOUR_NORMAL e "Mech Plating: #{@mech_plating}", COLOUR_NORMAL e "Mech Status: #{@mech_status}", COLOUR_NORMAL end |
#shoot_at(target) ⇒ Object
#
shoot_at
Shoot at a target.
#
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/games_and_rpg_paradise/games/mechwars/mech.rb', line 190 def shoot_at(target) deal_this_damage = 0 e "You (#{@mech_name}) fire your weapon at \"#{target}\"." @mech_n_weapons.times { |my_weapon| deal_this_damage += rand(8) # my_weapon deal_this_damage += @deal_this_base_damage # plus base damage } e "You have hit your target #{target} for #{deal_this_damage} damage!" e "You dealt your enemy #{deal_this_damage} damage." return @damage end |