battle_boats 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -5
- data/Gemfile.lock +2 -2
- data/lib/battle_boats/board.rb +43 -3
- data/lib/battle_boats/console_ui.rb +4 -0
- data/lib/battle_boats/engine.rb +11 -7
- data/lib/battle_boats/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d417f15deb5ea35be4829d14c0af66e5fd347e8
|
4
|
+
data.tar.gz: 75522bcf8e4e69dad64495f76962cc1b0178dccd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
3
|
-
- Can fire and miss a target
|
8
|
+
### New Features
|
9
|
+
- Can fire at an empty board and "miss" a target
|
4
10
|
|
5
11
|
# 0.0.2
|
6
|
-
|
12
|
+
### Bug Fixes
|
7
13
|
- YANKED due to vulnerability with rubocop development dependency
|
8
14
|
|
9
15
|
# 0.0.1
|
10
|
-
|
16
|
+
### New Features
|
11
17
|
- Welcome message
|
12
18
|
|
13
19
|
# 0.0.0
|
14
|
-
|
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.
|
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.
|
55
|
+
rubocop (~> 0.55)
|
56
56
|
simplecov (~> 0.16)
|
57
57
|
|
58
58
|
BUNDLED WITH
|
data/lib/battle_boats/board.rb
CHANGED
@@ -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
|
-
|
19
|
-
@
|
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
|
data/lib/battle_boats/engine.rb
CHANGED
@@ -11,13 +11,17 @@ module BattleBoats
|
|
11
11
|
|
12
12
|
def start
|
13
13
|
interface.greet
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
data/lib/battle_boats/version.rb
CHANGED
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.
|
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
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|