battle_boats 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a74f9d785a67a640d0cab5e9c4a81db0ae9ef77
4
- data.tar.gz: d70c00997e2a04baa7f9634ebea6a7b057363019
3
+ metadata.gz: 3d417f15deb5ea35be4829d14c0af66e5fd347e8
4
+ data.tar.gz: 75522bcf8e4e69dad64495f76962cc1b0178dccd
5
5
  SHA512:
6
- metadata.gz: 5d8f2a57c1dc3e062ce9651870ca2de7b9553ba9e20fe0d2007c28abf0315c1515ac0ec13ad2a1b85f1a0c1b181f3b453609433c4359c054b28d9fa943131dd5
7
- data.tar.gz: 31bc1db1950c708442630d2415cbbda32e4bcd49667d7eb4380c8ef89e2486f21f360477f82eb8c26945002d8cb3ab5fa1824172c30579cbb337a564fbb8c98a
6
+ metadata.gz: a217b9891b88d5ea077dce6ef3787852bbcb6d68add6410709ddde5f8ac6d9ba44eadfbec3425616e9e0a1ee5809e1a41f4c306fe34c1414b3208c4a978ec10b
7
+ data.tar.gz: 53109099edc9b6228995faba7a6a7e85a6fcc7d47a704164babb9616fb319c77c4ec078c880f114792e90101f16a3b151a7c0c98d61216c7ed7e760ba6422713
data/CHANGELOG.md CHANGED
@@ -1,15 +1,21 @@
1
+ # 0.0.4
2
+ ### New Features
3
+ - Error messages for bad input
4
+ - Prompt will ask again for input if input is invalid
5
+ - Game loops for more than one strike
6
+
1
7
  # 0.0.3
2
- ## New Features
3
- - Can fire and miss a target on the board
8
+ ### New Features
9
+ - Can fire at an empty board and "miss" a target
4
10
 
5
11
  # 0.0.2
6
- ## Bug Fixes
12
+ ### Bug Fixes
7
13
  - YANKED due to vulnerability with rubocop development dependency
8
14
 
9
15
  # 0.0.1
10
- ## New Features
16
+ ### New Features
11
17
  - Welcome message
12
18
 
13
19
  # 0.0.0
14
- ## New Features
20
+ ### New Features
15
21
  - claim name
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- battle_boats (0.0.2)
4
+ battle_boats (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -52,7 +52,7 @@ DEPENDENCIES
52
52
  bundler (~> 1.16)
53
53
  rake (~> 10.0)
54
54
  rspec (~> 3.0)
55
- rubocop (~> 0.42)
55
+ rubocop (~> 0.55)
56
56
  simplecov (~> 0.16)
57
57
 
58
58
  BUNDLED WITH
@@ -1,9 +1,10 @@
1
1
  module BattleBoats
2
2
  class Board
3
- attr_reader :play_area, :status_report
3
+ attr_reader :play_area, :status_report, :error_messages
4
4
 
5
5
  def initialize
6
6
  @status_report = ""
7
+ @error_messages = []
7
8
  @play_area = []
8
9
  10.times do
9
10
  row = []
@@ -15,8 +16,47 @@ module BattleBoats
15
16
  end
16
17
 
17
18
  def strike_position(row:, column:)
18
- @play_area[row.to_i][column.to_i] = "X"
19
- @status_report = "Miss!"
19
+ validate_position(row: row, column: column)
20
+ if @error_messages.empty?
21
+ @play_area[row.to_i][column.to_i] = "X"
22
+ @status_report = "Miss!"
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ def game_over?
30
+ false
31
+ end
32
+
33
+ private
34
+
35
+ def validate_position(row:, column:)
36
+ @error_messages.clear
37
+ if !between_zero_and_nine?(row)
38
+ @error_messages << "The selected row is invalid"
39
+ end
40
+ if !between_zero_and_nine?(column)
41
+ @error_messages << "The selected column is invalid"
42
+ end
43
+ if @error_messages.empty?
44
+ if !position_available?(row: row, column: column)
45
+ @error_messages << "That position has already been hit"
46
+ end
47
+ end
48
+ end
49
+
50
+ def between_zero_and_nine?(input)
51
+ if input.to_s =~ /^[0-9]$/
52
+ true
53
+ else
54
+ false
55
+ end
56
+ end
57
+
58
+ def position_available?(row:, column:)
59
+ @play_area[row.to_i][column.to_i] != "X"
20
60
  end
21
61
  end
22
62
  end
@@ -27,6 +27,10 @@ module BattleBoats
27
27
  output.puts status_report
28
28
  end
29
29
 
30
+ def display_errors(errors)
31
+ output.puts errors
32
+ end
33
+
30
34
  private
31
35
 
32
36
  attr_reader :output, :input
@@ -11,13 +11,17 @@ module BattleBoats
11
11
 
12
12
  def start
13
13
  interface.greet
14
- interface.display_board(board)
15
- row = interface.get_row
16
- column = interface.get_column
17
- board.strike_position(row: row, column: column)
18
- status_report = board.status_report
19
- interface.display_status_report(status_report)
20
- interface.display_board(board)
14
+ until board.game_over?
15
+ interface.display_board(board)
16
+ row = interface.get_row
17
+ column = interface.get_column
18
+ until board.strike_position(row: row, column: column)
19
+ interface.display_errors(board.error_messages)
20
+ row = interface.get_row
21
+ column = interface.get_column
22
+ end
23
+ interface.display_status_report(board.status_report)
24
+ end
21
25
  end
22
26
 
23
27
  private
@@ -1,3 +1,3 @@
1
1
  module BattleBoats
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battle_boats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Countz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler