battle_boats 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92ec7ba406b6f4c837600bb9bf2affc4c0cb7659
4
- data.tar.gz: ffaf1cdf4bf9fb2118da2594280443cb2af246fc
3
+ metadata.gz: b9b10aee1f2048f395a0630511233753ec454a6e
4
+ data.tar.gz: 3b7ef2c6e80f95c78a4d3967287d4874473e6f15
5
5
  SHA512:
6
- metadata.gz: 1793feae5f52bbdfe66362f8e13345c06d8a841c2325e81b8c46926e048aa017a4d3823ff5f036775bd2d3291a4adc9a63e6be89043c05974f675ed442dc7cb2
7
- data.tar.gz: 64b661bad1fa0e76619afdf586627a2d74190819e3f8390ad3d5e0bb567628053527f0985263ef284279315a7a7845cdc8408970e94e83f906f345db538d3cbf
6
+ metadata.gz: 4815fb5a29d9d59188c18326035e249abfacf7174b29d0ab4fd1c06424a4cf10df75c96b7c7c5497c4ab11881565c57f9d8140e32b6fdd5a561c266abd439eb3
7
+ data.tar.gz: 5c3d7dd1d4b9a987187b9a410d051621fe845b57f45ce6a798ebc675c6617e88b4e7da8420835d41a07a63aa6de44c922c1f906dd3e8643833828a297a4d680b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.8
2
+ ### New Features
3
+ - Displays "sunk" message one a ship has been hit along its entire length
4
+
1
5
  # 0.0.7
2
6
  ### New Features
3
7
  - Corrdinate input format is now `<<letter>><<number>>`, eg. `G3`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- battle_boats (0.0.7)
4
+ battle_boats (0.0.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -34,7 +34,7 @@ module BattleBoats
34
34
  end
35
35
 
36
36
  def cell_at(coordinate:)
37
- if within_range?(coordinate)
37
+ if within_range?(coordinate: coordinate)
38
38
  @play_area[coordinate.row.to_i][coordinate.column.to_i]
39
39
  end
40
40
  end
@@ -64,7 +64,7 @@ module BattleBoats
64
64
  end
65
65
  end
66
66
 
67
- def within_range?(coordinate)
67
+ def within_range?(coordinate:)
68
68
  if coordinate.row.to_s =~ /^[0-9]$/ && coordinate.column.to_s =~ /^[0-9]$/
69
69
  true
70
70
  else
@@ -77,7 +77,7 @@ module BattleBoats
77
77
  end
78
78
 
79
79
  def occupy_cells(cells:, ship:)
80
- if cells_are_occupiable(cells)
80
+ if cells_are_occupiable(cells: cells)
81
81
  cells.each do |cell|
82
82
  cell.occupant = ship
83
83
  end
@@ -86,7 +86,7 @@ module BattleBoats
86
86
  end
87
87
  end
88
88
 
89
- def cells_are_occupiable(cells)
89
+ def cells_are_occupiable(cells:)
90
90
  cells.none?(&:nil?) && cells.none?(&:occupied?)
91
91
  end
92
92
  end
@@ -17,6 +17,7 @@ module BattleBoats
17
17
 
18
18
  def strike
19
19
  if !hit?
20
+ occupant.hit
20
21
  @hit = true
21
22
  end
22
23
  end
@@ -30,10 +31,11 @@ module BattleBoats
30
31
  end
31
32
 
32
33
  def status_report
33
- if hit?
34
- "You hit my #{occupant.name}!"
35
- else
36
- "All Clear!"
34
+ occupant_name = occupant.name
35
+ if occupant.sunk?
36
+ "You sunk my #{occupant_name}!"
37
+ elsif hit?
38
+ "You hit my #{occupant_name}!"
37
39
  end
38
40
  end
39
41
 
@@ -14,5 +14,9 @@ module BattleBoats
14
14
  def empty?
15
15
  true
16
16
  end
17
+
18
+ def hit; end
19
+
20
+ def sunk?; end
17
21
  end
18
22
  end
@@ -9,10 +9,23 @@ module BattleBoats
9
9
  @name = name
10
10
  @length = length
11
11
  @symbol = symbol.red
12
+ @hits = 0
12
13
  end
13
14
 
14
15
  def empty?
15
16
  false
16
17
  end
18
+
19
+ def hit_count
20
+ @hits
21
+ end
22
+
23
+ def hit
24
+ @hits += 1
25
+ end
26
+
27
+ def sunk?
28
+ hit_count == length
29
+ end
17
30
  end
18
31
  end
@@ -1,3 +1,3 @@
1
1
  module BattleBoats
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battle_boats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Countz