質問するログイン新規登録

回答編集履歴

3

Remove debugging code

2017/11/16 20:13

投稿

gouf
gouf

スコア2321

answer CHANGED
@@ -10,7 +10,6 @@
10
10
  def initialize(pokemon_a, pokemon_b)
11
11
  @turn_count = 0
12
12
  @players = [pokemon_a, pokemon_b]
13
- @players.map(&:name)
14
13
  end
15
14
 
16
15
  def game_start!
@@ -30,7 +29,6 @@
30
29
  @turn_count += 1
31
30
 
32
31
  @players.reverse! if @players.size.modulo(@turn_count).even?
33
- @players.map(&:name)
34
32
  end
35
33
 
36
34
  # たたかう

2

refactor

2017/11/16 20:13

投稿

gouf
gouf

スコア2321

answer CHANGED
@@ -36,7 +36,7 @@
36
36
  # たたかう
37
37
  def battle!
38
38
  attacker, defender = @players # 攻撃側と防御側を取り出す
39
- defender.damage!(attacker.attack_power)
39
+ defender.taken_damage!(attacker.attack_power)
40
40
  end
41
41
 
42
42
  def print_initial_situation
@@ -77,7 +77,7 @@
77
77
  @vitality <= 0
78
78
  end
79
79
 
80
- def damage!(attack_power)
80
+ def taken_damage!(attack_power)
81
81
  @vitality -= attack_power
82
82
  end
83
83
  end

1

Fix a bug

2017/11/16 20:09

投稿

gouf
gouf

スコア2321

answer CHANGED
@@ -10,6 +10,7 @@
10
10
  def initialize(pokemon_a, pokemon_b)
11
11
  @turn_count = 0
12
12
  @players = [pokemon_a, pokemon_b]
13
+ @players.map(&:name)
13
14
  end
14
15
 
15
16
  def game_start!
@@ -26,16 +27,16 @@
26
27
 
27
28
  # 剰余で順繰りに順番を回す
28
29
  def turn_phaze!
30
+ @turn_count += 1
31
+
29
- @players.reverse! if @turn_count.modulo(@players.size).odd?
32
+ @players.reverse! if @players.size.modulo(@turn_count).even?
30
- @players
33
+ @players.map(&:name)
31
34
  end
32
35
 
33
36
  # たたかう
34
37
  def battle!
35
38
  attacker, defender = @players # 攻撃側と防御側を取り出す
36
39
  defender.damage!(attacker.attack_power)
37
-
38
- @turn_count += 1
39
40
  end
40
41
 
41
42
  def print_initial_situation
@@ -92,13 +93,10 @@
92
93
  # なまえ:ピッピ, たいりょく:50, こうげき:20
93
94
  # ポッポのこうげき
94
95
  # ピッピは30のダメージをうけた!
95
- #
96
+ #
96
97
  # ピッピのこうげき
97
98
  # ポッポは20のダメージをうけた!
98
- #
99
+ #
99
- # ピッピのこうげき
100
- # ポッポは20のダメージをうけた!
101
- #
102
100
  # ポッポのこうげき
103
101
  # ピッピは30のダメージをうけた!
104
102
  # ピッピはやられてしまった!