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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 765cef2a3566e7f824cd2319ec960c90f0d26622
4
- data.tar.gz: 1de5b33a33bce1bac1162ad670ca0af38499d277
3
+ metadata.gz: 92ec7ba406b6f4c837600bb9bf2affc4c0cb7659
4
+ data.tar.gz: ffaf1cdf4bf9fb2118da2594280443cb2af246fc
5
5
  SHA512:
6
- metadata.gz: 8a5e7d65fc210a47de5df56a539fa4d53f0fed11d3f7f67b2aa0f2fca733e7b0f061166dbe1f7e42b002529e8f10ddcb1ccdcb075ac4f17ba1aa1d40593a6ca7
7
- data.tar.gz: 68ebe43ee2985c47cd9275d71e138ebc085b7074ca76e43bf62edaa4cf8ee96e9885d3e53b14c90b06241abc075bc5f3f9630b732fa8e5b711b655355d7ffe19
6
+ metadata.gz: 1793feae5f52bbdfe66362f8e13345c06d8a841c2325e81b8c46926e048aa017a4d3823ff5f036775bd2d3291a4adc9a63e6be89043c05974f675ed442dc7cb2
7
+ data.tar.gz: 64b661bad1fa0e76619afdf586627a2d74190819e3f8390ad3d5e0bb567628053527f0985263ef284279315a7a7845cdc8408970e94e83f906f345db538d3cbf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.0.7
2
+ ### New Features
3
+ - Corrdinate input format is now `<<letter>><<number>>`, eg. `G3`
4
+ - Coordinate input is case insensitive
5
+
1
6
  # 0.0.6
2
7
  ### New Features
3
8
  - The game is now in color!
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- battle_boats (0.0.6)
4
+ battle_boats (0.0.7)
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.row) && within_range?(coordinate.column)
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 !within_range?(coordinate.row)
63
- @error_messages << "The selected row is invalid"
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?(input)
76
- if input.to_s =~ /^[0-9]$/
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
- row = get_row
20
- column = get_column
21
- BattleBoats::Coordinate.new(row: row, column: column)
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 << top_row
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 top_row
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
@@ -1,3 +1,3 @@
1
1
  module BattleBoats
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".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.6
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-21 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler