Class: Gemwarrior::Battle
- Inherits:
-
Object
- Object
- Gemwarrior::Battle
- Defined in:
- lib/gemwarrior/battle.rb
Constant Summary collapse
- ERROR_ATTACK_OPTION_INVALID =
CONSTANTS ERRORS
'That will not do anything against the monster.'- BEAST_MODE_ATTACK =
100- TEXT_ESCAPE =
MESSAGES
'POOF'
Instance Attribute Summary collapse
-
#monster ⇒ Object
Returns the value of attribute monster.
-
#player ⇒ Object
Returns the value of attribute player.
-
#player_is_defending ⇒ Object
Returns the value of attribute player_is_defending.
-
#world ⇒ Object
Returns the value of attribute world.
Instance Method Summary collapse
-
#initialize(options) ⇒ Battle
constructor
A new instance of Battle.
- #start(is_arena = nil, is_event = nil) ⇒ Object
Constructor Details
#initialize(options) ⇒ Battle
Returns a new instance of Battle.
18 19 20 21 22 23 |
# File 'lib/gemwarrior/battle.rb', line 18 def initialize() self.world = .fetch(:world) self.player = .fetch(:player) self.monster = .fetch(:monster) self.player_is_defending = false end |
Instance Attribute Details
#monster ⇒ Object
Returns the value of attribute monster.
16 17 18 |
# File 'lib/gemwarrior/battle.rb', line 16 def monster @monster end |
#player ⇒ Object
Returns the value of attribute player.
16 17 18 |
# File 'lib/gemwarrior/battle.rb', line 16 def player @player end |
#player_is_defending ⇒ Object
Returns the value of attribute player_is_defending.
16 17 18 |
# File 'lib/gemwarrior/battle.rb', line 16 def player_is_defending @player_is_defending end |
#world ⇒ Object
Returns the value of attribute world.
16 17 18 |
# File 'lib/gemwarrior/battle.rb', line 16 def world @world end |
Instance Method Details
#start(is_arena = nil, is_event = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gemwarrior/battle.rb', line 25 def start(is_arena = nil, is_event = nil) print_battle_line if is_arena print 'Your opponent is now...' Animation::run({:phrase => "#{monster.name.upcase}!", :speed => :slow}) elsif is_event puts "You are attacked by #{monster.name}!" else puts "You decide to attack #{monster.name}!" end puts "#{monster.name} cries out: \"#{monster.battlecry}\"".colorize(:yellow) # first strike! unless is_arena if monster_strikes_first?(is_event) puts "#{monster.name} strikes first!".colorize(:yellow) monster_attacks_player end end # main battle loop loop do if monster_dead? monster_death return elsif player_dead? player_death return 'death' end # check for near death if player_near_death? puts "You are almost dead!\n".colorize(:yellow) end if monster_near_death? puts "#{monster.name} is almost dead!\n".colorize(:yellow) end puts # print health info print "#{player.name.upcase.ljust(12)} :: #{player.hp_cur.to_s.rjust(3)} HP" if world.debug_mode print " (LVL: #{player.level})" end print "\n" print "#{monster.name.upcase.ljust(12)} :: " if world.debug_mode || player.special_abilities.include?(:rocking_vision) print "#{monster.hp_cur.to_s.rjust(3)}" else print "???" end print " HP" if world.debug_mode print " (LVL: #{monster.level})" end print "\n" puts self.player_is_defending = false # battle options prompt puts 'What do you do?' print '['.colorize(:yellow) print 'F'.colorize(:green) print 'ight/'.colorize(:yellow) print 'A'.colorize(:green) print 'ttack]['.colorize(:yellow) print 'D'.colorize(:green) print 'efend]['.colorize(:yellow) print 'L'.colorize(:green) print 'ook]['.colorize(:yellow) print 'P'.colorize(:green) print 'ass]['.colorize(:yellow) print 'R'.colorize(:green) print 'un]'.colorize(:yellow) print "\n" player_action = STDIN.gets.chomp.downcase # player action case player_action when 'fight', 'f', 'attack', 'a' puts "You attack #{monster.name}#{player.cur_weapon_name}!" dmg = calculate_damage_to(monster) if dmg > 0 take_damage(monster, dmg) if monster_dead? monster_death return end else puts "You miss entirely!".colorize(:yellow) end when 'defend', 'd' puts 'You dig in and defend this round.' self.player_is_defending = true when 'pass', 'p' puts 'You decide to pass your turn for some reason. Brave!' when 'look', 'l' print "#{monster.name}".colorize(:white) print " (#{monster.hp_cur}/#{monster.hp_max} HP): #{monster.description}\n" puts "It has some distinguishing features, too: face is #{monster.face}, hands are #{monster.hands}, and general mood is #{monster.mood}." if world.debug_mode puts "If defeated, will receive:" puts " >> XP : #{monster.xp}" puts " >> ROX : #{monster.rox}" puts " >> ITEMS: #{monster.inventory.list_contents}" next end when 'run', 'r' if player_escape? monster.hp_cur = monster.hp_max puts "You successfully elude #{monster.name}!".colorize(:green) print_escape_text return else puts "You were not able to run away! :-(".colorize(:yellow) end else puts ERROR_ATTACK_OPTION_INVALID next end # monster action monster_attacks_player end end |