Update on 20171031 5:46pm
diff --git a/hero_game/hero.rb b/hero_game/hero.rb
index 77a9a80..b3b6705 100644
--- a/hero_game/hero.rb
+++ b/hero_game/hero.rb
@@ -1,7 +1,5 @@
-class Hero
- MAX_HP = 200
- MAX_AP = 80
+class Hero
attr_accessor :hp, :name
@@ -9,19 +7,8 @@
def initialize(name, hp, ap)
@name = name
-
- if MAX_HP < hp
- @hp = MAX_HP
- else
- @hp = hp
- end
-
- if MAX_AP < ap
- @ap = MAX_AP
- else
- @ap = ap
- end # 設定一個名為 hp(生命值)的 attribute
-
+ @hp = hp
+ @ap = ap
@alive = true # 英雄剛被創造,所以預設為 true,表示英雄被創造時一定是活著的
# 印出被創造的英雄的 attributes
@@ -47,16 +34,12 @@
puts "#{enemy.name} 剩下 #{enemy.hp} 點 HP"
puts ""
- enemy.die?
- end
-
- def die?
- if hp < 1
- die
+ if enemy.hp < 1 # 生命值小於 1,代表死亡(戰敗)
+ enemy.die # 敵人死亡
end
end
- private def die # 代表死亡(戰敗)
+ def die # 代表死亡(戰敗)
@alive = false
puts "#{@name} 被打倒了"
end
@@ -68,4 +51,4 @@
def self.all
return @@heroes # 回傳包含所有 hero 的 array
end
-end
+end
\ No newline at end of file