Class: MISSIONGAME::Player
- Inherits:
-
Object
- Object
- MISSIONGAME::Player
- Defined in:
- lib/player.rb
Instance Attribute Summary collapse
-
#bonus ⇒ Object
Returns the value of attribute bonus.
-
#current_enemy ⇒ Object
Returns the value of attribute current_enemy.
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#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.
-
#lives ⇒ Object
Returns the value of attribute lives.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#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) ⇒ Player
constructor
A new instance of Player.
- #move(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Player
Returns a new instance of Player.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/player.rb', line 25 def initialize(args) name = args[:name] neworleans = args[:neworleans] @name = name @level = 1 @lives = 100 @bonus = 100 @str = 5 @int = 5 @x = 1 @y = neworleans.get_height @in_combat = false @current_enemy = nil @points = 0 @dead = 0 "Welcome %{name}! Let's play!" end |
Instance Attribute Details
#bonus ⇒ Object
Returns the value of attribute bonus.
14 15 16 |
# File 'lib/player.rb', line 14 def bonus @bonus end |
#current_enemy ⇒ Object
Returns the value of attribute current_enemy.
21 22 23 |
# File 'lib/player.rb', line 21 def current_enemy @current_enemy end |
#dead ⇒ Object
Returns the value of attribute dead.
23 24 25 |
# File 'lib/player.rb', line 23 def dead @dead end |
#in_combat ⇒ Object
Returns the value of attribute in_combat.
20 21 22 |
# File 'lib/player.rb', line 20 def in_combat @in_combat end |
#int ⇒ Object
Returns the value of attribute int.
19 20 21 |
# File 'lib/player.rb', line 19 def int @int end |
#level ⇒ Object
Returns the value of attribute level.
17 18 19 |
# File 'lib/player.rb', line 17 def level @level end |
#lives ⇒ Object
Returns the value of attribute lives.
13 14 15 |
# File 'lib/player.rb', line 13 def lives @lives end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/player.rb', line 12 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
22 23 24 |
# File 'lib/player.rb', line 22 def points @points end |
#str ⇒ Object
Returns the value of attribute str.
18 19 20 |
# File 'lib/player.rb', line 18 def str @str end |
#x ⇒ Object
Returns the value of attribute x.
15 16 17 |
# File 'lib/player.rb', line 15 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
16 17 18 |
# File 'lib/player.rb', line 16 def y @y end |
Instance Method Details
#attack(args) ⇒ Object
Player attacks enemy
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 |
# File 'lib/player.rb', line 44 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.lives print "You fought for your life and " + "hit".light_yellow + " " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damages, killing him!\n" print "You gain " + enemy.points.to_s.light_white + " points.\n" ENEMY_KILLED else print "You fought for your life and " + "hit".light_yellow + " " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damages, killing him!\n" attack_value end else print "You fought for your life and " + "missed".light_red + " " + enemy.name + "!\n" 0 end 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/player.rb', line 80 def move(args) direction = args[:direction] neworleans = args[:neworleans] 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 < neworleans.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 < neworleans.get_width @x += 1 else ui.out_of_bounds return false end end if neworleans.check_area({player: self, ui: ui, story: story}) true else false end end |