Class: LOTS::Character
- Inherits:
-
Object
- Object
- LOTS::Character
- Defined in:
- lib/character.rb
Instance Attribute Summary collapse
-
#current_enemy ⇒ Object
Returns the value of attribute current_enemy.
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#health ⇒ Object
Returns the value of attribute health.
-
#in_combat ⇒ Object
Returns the value of attribute in_combat.
-
#int ⇒ Object
Returns the value of attribute int.
-
#level ⇒ Object
Returns the value of attribute level.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#mana ⇒ Object
Returns the value of attribute mana.
-
#name ⇒ Object
Returns the value of attribute name.
-
#str ⇒ Object
Returns the value of attribute str.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#attack(args) ⇒ Object
Player attacks enemy.
-
#initialize(args) ⇒ Character
constructor
A new instance of Character.
- #move(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Character
Returns a new instance of Character.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/character.rb', line 30 def initialize (args) name = args[:name] world = args[:world] @name = name @level = 1 @health = 100 @mana = 100 @str = 5 @int = 5 @x = 1 @y = world.get_height @in_combat = false @current_enemy = nil @lines = 0 @dead = 0 return "Welcome %{name}! Let's play Legend of the Sourcerer!" end |
Instance Attribute Details
#current_enemy ⇒ Object
Returns the value of attribute current_enemy.
26 27 28 |
# File 'lib/character.rb', line 26 def current_enemy @current_enemy end |
#dead ⇒ Object
Returns the value of attribute dead.
28 29 30 |
# File 'lib/character.rb', line 28 def dead @dead end |
#health ⇒ Object
Returns the value of attribute health.
18 19 20 |
# File 'lib/character.rb', line 18 def health @health end |
#in_combat ⇒ Object
Returns the value of attribute in_combat.
25 26 27 |
# File 'lib/character.rb', line 25 def in_combat @in_combat end |
#int ⇒ Object
Returns the value of attribute int.
24 25 26 |
# File 'lib/character.rb', line 24 def int @int end |
#level ⇒ Object
Returns the value of attribute level.
22 23 24 |
# File 'lib/character.rb', line 22 def level @level end |
#lines ⇒ Object
Returns the value of attribute lines.
27 28 29 |
# File 'lib/character.rb', line 27 def lines @lines end |
#mana ⇒ Object
Returns the value of attribute mana.
19 20 21 |
# File 'lib/character.rb', line 19 def mana @mana end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/character.rb', line 17 def name @name end |
#str ⇒ Object
Returns the value of attribute str.
23 24 25 |
# File 'lib/character.rb', line 23 def str @str end |
#x ⇒ Object
Returns the value of attribute x.
20 21 22 |
# File 'lib/character.rb', line 20 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
21 22 23 |
# File 'lib/character.rb', line 21 def y @y end |
Instance Method Details
#attack(args) ⇒ Object
Player attacks enemy
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 |
# File 'lib/character.rb', line 49 def attack(args) player = self enemy = args[:enemy] ui = args[:ui] # Does the player even hit the enemy? # We could use a hit chance stat here, but since we don't have one, # we'll just base it off the player/enemy stength discrepency. ui.enemy_info({:player => player}) ui.player_info({:player => player}) str_diff = (player.str - enemy.str) * 2 hit_chance = rand(1...100) + str_diff + HIT_CHANCE_MODIFIER if (hit_chance > 50) # Determine value of the attack attack_value = rand(1...player.str) + ATTACK_VALUE_MODIFIER if attack_value > enemy.health print "You swing and " + "hit".light_yellow + " the " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damage, killing it!\n" print "You gain " + enemy.lines.to_s.light_white + " lines of code.\n" return ENEMY_KILLED else print "You swing and " + "hit".light_yellow + " the " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damage!\n" return attack_value end else print "You swing and " + "miss".light_red + " the " + enemy.name + "!\n" return 0 end return true end |
#move(args) ⇒ Object
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 |
# File 'lib/character.rb', line 80 def move(args) direction = args[:direction] world = args[:world] ui = args[:ui] story = args[:story] case direction when :up if @y > 1 @y -= 1 else ui.out_of_bounds return false end when :down if @y < world.get_height @y += 1 else ui.out_of_bounds return false end when :left if @x > 1 @x -= 1 else ui.out_of_bounds return false end when :right if @x < world.get_width @x += 1 else ui.out_of_bounds return false end end unless world.check_area({:player => self, :ui => ui, :story => story}) return false else return true end end |