battle_boats 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/battle_boats/board.rb +5 -13
- data/lib/battle_boats/console_ui.rb +26 -16
- 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: 92ec7ba406b6f4c837600bb9bf2affc4c0cb7659
|
4
|
+
data.tar.gz: ffaf1cdf4bf9fb2118da2594280443cb2af246fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1793feae5f52bbdfe66362f8e13345c06d8a841c2325e81b8c46926e048aa017a4d3823ff5f036775bd2d3291a4adc9a63e6be89043c05974f675ed442dc7cb2
|
7
|
+
data.tar.gz: 64b661bad1fa0e76619afdf586627a2d74190819e3f8390ad3d5e0bb567628053527f0985263ef284279315a7a7845cdc8408970e94e83f906f345db538d3cbf
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/battle_boats/board.rb
CHANGED
@@ -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)
|
38
38
|
@play_area[coordinate.row.to_i][coordinate.column.to_i]
|
39
39
|
end
|
40
40
|
end
|
@@ -59,21 +59,13 @@ module BattleBoats
|
|
59
59
|
|
60
60
|
def validate_position(coordinate:)
|
61
61
|
@error_messages.clear
|
62
|
-
if !
|
63
|
-
@error_messages << "
|
64
|
-
end
|
65
|
-
if !within_range?(coordinate.column)
|
66
|
-
@error_messages << "The selected column is invalid"
|
67
|
-
end
|
68
|
-
if @error_messages.empty?
|
69
|
-
if !position_available?(coordinate: coordinate)
|
70
|
-
@error_messages << "That position has already been hit"
|
71
|
-
end
|
62
|
+
if !position_available?(coordinate: coordinate)
|
63
|
+
@error_messages << "That position has already been hit"
|
72
64
|
end
|
73
65
|
end
|
74
66
|
|
75
|
-
def within_range?(
|
76
|
-
if
|
67
|
+
def within_range?(coordinate)
|
68
|
+
if coordinate.row.to_s =~ /^[0-9]$/ && coordinate.column.to_s =~ /^[0-9]$/
|
77
69
|
true
|
78
70
|
else
|
79
71
|
false
|
@@ -16,9 +16,13 @@ module BattleBoats
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get_coordinate
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
output.puts "Target coordinate: "
|
20
|
+
user_input = input.gets.chomp
|
21
|
+
until valid_input?(user_input)
|
22
|
+
output.puts "Coordinate invalid."
|
23
|
+
user_input = input.gets.chomp
|
24
|
+
end
|
25
|
+
input_to_coordinate(user_input)
|
22
26
|
end
|
23
27
|
|
24
28
|
def display_status_report(status_report)
|
@@ -33,15 +37,27 @@ module BattleBoats
|
|
33
37
|
|
34
38
|
attr_reader :output, :input
|
35
39
|
|
40
|
+
def valid_input?(coordinate)
|
41
|
+
coordinate =~ /^[A-J][0-9]$/i
|
42
|
+
end
|
43
|
+
|
44
|
+
def input_to_coordinate(input)
|
45
|
+
input_row = input[0]
|
46
|
+
input_column = input[1]
|
47
|
+
row = row_labels.index(input_row.upcase)
|
48
|
+
column = input_column.to_i
|
49
|
+
BattleBoats::Coordinate.new(row: row, column: column)
|
50
|
+
end
|
51
|
+
|
36
52
|
def format_board(board)
|
37
53
|
board_string = horizontal_line
|
38
54
|
board_string << newline
|
39
|
-
board_string <<
|
55
|
+
board_string << column_label
|
40
56
|
board_string << horizontal_line
|
41
57
|
board_string << newline
|
42
58
|
board.play_area.each_with_index do |row, row_number|
|
43
59
|
board_string << pipe
|
44
|
-
board_string << " #{row_number} "
|
60
|
+
board_string << " #{row_labels[row_number]} "
|
45
61
|
board_string << pipe
|
46
62
|
row.each do |cell|
|
47
63
|
board_string << " #{cell} "
|
@@ -54,10 +70,14 @@ module BattleBoats
|
|
54
70
|
board_string
|
55
71
|
end
|
56
72
|
|
57
|
-
def
|
73
|
+
def column_label
|
58
74
|
"| | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |\n"
|
59
75
|
end
|
60
76
|
|
77
|
+
def row_labels
|
78
|
+
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
|
79
|
+
end
|
80
|
+
|
61
81
|
def newline
|
62
82
|
"\n"
|
63
83
|
end
|
@@ -69,15 +89,5 @@ module BattleBoats
|
|
69
89
|
def pipe
|
70
90
|
"|"
|
71
91
|
end
|
72
|
-
|
73
|
-
def get_row
|
74
|
-
output.puts "Target row:"
|
75
|
-
input.gets.chomp
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_column
|
79
|
-
output.puts "Target column:"
|
80
|
-
input.gets.chomp
|
81
|
-
end
|
82
92
|
end
|
83
93
|
end
|
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.7
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|