battle 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/lib/battle/game.rb +9 -2
- data/lib/battle/version.rb +1 -1
- data/spec/lib/battle/game_spec.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b63b218431b7d6012bcbd74d3918cc9e9feee2
|
4
|
+
data.tar.gz: ade55b6823ed8cd71a7bbc3f8ba27b3124305b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c137becb1b6c07f1cad79bd578cece549fe1eac89a3bb5adca2123f22f8210c166932fc07adc0d07444ec157bdcdc22e4f22ecd3d6efc4ae4203a015c7e39674
|
7
|
+
data.tar.gz: 54f60c22b88c6ee3ef9bb35804389af8430a73cfae374be8327111de20e416f70253052d25c13680aaae5566bb28b6fd86e9526c0e623f91c2f6e6576c3d11a5
|
data/.travis.yml
CHANGED
data/lib/battle/game.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Battle
|
2
2
|
class Game
|
3
3
|
attr_reader :name, :email, :id, :coords, :status, :ships, :prize,
|
4
|
-
:response
|
4
|
+
:response, :nuke_status, :sunk
|
5
5
|
|
6
6
|
STATUSES = %w[start victory defeat]
|
7
7
|
|
@@ -57,6 +57,8 @@ module Battle
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def sink_ship(name)
|
60
|
+
@sunk = name
|
61
|
+
return if name.nil?
|
60
62
|
ships.delete ships.find { |ship| ship.is? name }
|
61
63
|
end
|
62
64
|
|
@@ -69,7 +71,8 @@ module Battle
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def handle_nuke
|
72
|
-
sink_ship response['sunk']
|
74
|
+
sink_ship response['sunk']
|
75
|
+
handle_nuke_status
|
73
76
|
handle_defeat
|
74
77
|
handle_victory
|
75
78
|
assign_coordinates
|
@@ -82,6 +85,10 @@ module Battle
|
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
88
|
+
def handle_nuke_status
|
89
|
+
@nuke_status = response['status']
|
90
|
+
end
|
91
|
+
|
85
92
|
def handle_defeat
|
86
93
|
defeat if response["game_status"] == "lost"
|
87
94
|
end
|
data/lib/battle/version.rb
CHANGED
@@ -115,6 +115,11 @@ describe Battle::Game do
|
|
115
115
|
it "don't change game status" do
|
116
116
|
expect { game.nuke(5, 9) }.to_not change { game.status }
|
117
117
|
end
|
118
|
+
|
119
|
+
it 'sets nuke_status to miss' do
|
120
|
+
game.nuke(5, 9)
|
121
|
+
expect(game.nuke_status).to eq 'miss'
|
122
|
+
end
|
118
123
|
end
|
119
124
|
|
120
125
|
context "when hit battleship" do
|
@@ -132,6 +137,16 @@ describe Battle::Game do
|
|
132
137
|
"y" => 7 })
|
133
138
|
end
|
134
139
|
|
140
|
+
it 'sets nuke_status to hit' do
|
141
|
+
game.nuke(5, 9)
|
142
|
+
expect(game.nuke_status).to eq 'hit'
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'sets the sunk attribute to ship name' do
|
146
|
+
game.nuke(5, 9)
|
147
|
+
expect(game.sunk).to eq 'Battleship'
|
148
|
+
end
|
149
|
+
|
135
150
|
it 'decrease ships count' do
|
136
151
|
expect { game.nuke(5, 9) }.to change { game.ships.count }.by(-1)
|
137
152
|
end
|