Class: GamesParadise::Mechwars::Arena
- Inherits:
-
Object
- Object
- GamesParadise::Mechwars::Arena
- Defined in:
- lib/games_paradise/mechwars/arena.rb
Instance Attribute Summary collapse
-
#experience ⇒ Object
readonly
Returns the value of attribute experience.
-
#how_many_mechs ⇒ Object
(also: #n_mechs)
readonly
Returns the value of attribute how_many_mechs.
Instance Method Summary collapse
-
#combat_round(object1, object2) ⇒ Object
# === combat_round ===================================================================== #.
-
#fight(object1 = , object2 = ) ⇒ Object
# === fight.
-
#fill_arena ⇒ Object
# === fill_arena.
-
#fill_arena_and_set_targets ⇒ Object
# === fill_arena_and_set_targets ===================================================================== #.
-
#initialize(how_many_mechs = 4) ⇒ Arena
constructor
# === initialize ===================================================================== #.
-
#report ⇒ Object
# === report ===================================================================== #.
-
#report_how_many_mechs_will_be_created ⇒ Object
# === report_how_many_mechs_will_be_created ===================================================================== #.
-
#reset ⇒ Object
# === reset (reset tag) ===================================================================== #.
-
#set_targets ⇒ Object
# === set_targets.
Constructor Details
#initialize(how_many_mechs = 4) ⇒ Arena
#
initialize
#
21 22 23 24 25 26 27 |
# File 'lib/games_paradise/mechwars/arena.rb', line 21 def initialize( how_many_mechs = 4 ) @how_many_mechs = how_many_mechs report_how_many_mechs_will_be_created reset end |
Instance Attribute Details
#experience ⇒ Object (readonly)
Returns the value of attribute experience.
15 16 17 |
# File 'lib/games_paradise/mechwars/arena.rb', line 15 def experience @experience end |
#how_many_mechs ⇒ Object (readonly) Also known as: n_mechs
Returns the value of attribute how_many_mechs.
16 17 18 |
# File 'lib/games_paradise/mechwars/arena.rb', line 16 def how_many_mechs @how_many_mechs end |
Instance Method Details
#combat_round(object1, object2) ⇒ Object
#
combat_round
#
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/games_paradise/mechwars/arena.rb', line 96 def combat_round(object1,object2) while true damage=@array_storing_mech_objects[0].shoot_at(@array_storing_mech_objects[1].name) @array_storing_mech_objects[1].got_hit(damage) damage=@array_storing_mech_objects[1].shoot_at(@array_storing_mech_objects[0].name) @array_storing_mech_objects[0].got_hit(damage) @combat_round_counter += 1 sleep(1) # 1 sekunde pause end end |
#fight(object1 = , object2 = ) ⇒ Object
#
fight
Here our objects fight with each other.
#
114 115 116 |
# File 'lib/games_paradise/mechwars/arena.rb', line 114 def fight(object1= @array_storing_mech_objects[0],object2=@array_storing_mech_objects[1]) combat_round(object1, object2) end |
#fill_arena ⇒ Object
#
fill_arena
just fills our arena with mechs
#
75 76 77 78 79 80 81 |
# File 'lib/games_paradise/mechwars/arena.rb', line 75 def fill_arena @how_many_mechs.times { |tmp| foo = Mech.new foo.random @array_storing_mech_objects << foo } end |
#fill_arena_and_set_targets ⇒ Object
#
fill_arena_and_set_targets
#
65 66 67 68 |
# File 'lib/games_paradise/mechwars/arena.rb', line 65 def fill_arena_and_set_targets fill_arena set_targets end |
#report ⇒ Object
#
report
#
58 59 60 |
# File 'lib/games_paradise/mechwars/arena.rb', line 58 def report pp @array_storing_mech_objects end |
#report_how_many_mechs_will_be_created ⇒ Object
#
report_how_many_mechs_will_be_created
#
32 33 34 35 36 |
# File 'lib/games_paradise/mechwars/arena.rb', line 32 def report_how_many_mechs_will_be_created e "="*80 e "Creating #{@how_many_mechs} Mechs." e "="*80 end |
#reset ⇒ Object
#
reset (reset tag)
#
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/games_paradise/mechwars/arena.rb', line 41 def reset # =================================================================== # # === @array_storing_mech_objects # =================================================================== # @array_storing_mech_objects = [] @combat_round_counter = 0 # counts at which combat round we are #@experience ranges from 0 for newbie and 10000 for # extreme veteran. High experience can improve the pilots # skills. Or enhance his overall abilities. @experience = 0+rand(200) end |
#set_targets ⇒ Object
#
set_targets
sets targets
#
88 89 90 91 |
# File 'lib/games_paradise/mechwars/arena.rb', line 88 def set_targets @array_storing_mech_objects[0].engage_target(@array_storing_mech_objects[1]) @array_storing_mech_objects[1].engage_target(@array_storing_mech_objects[0]) end |