battle_boats 0.0.1 → 0.0.3

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: 5d34a567d9ab259c06725fb376c6ac50ccfa50bb
4
- data.tar.gz: 267ad389ba1dcc16629ef311338082be84261cfa
3
+ metadata.gz: 5a74f9d785a67a640d0cab5e9c4a81db0ae9ef77
4
+ data.tar.gz: d70c00997e2a04baa7f9634ebea6a7b057363019
5
5
  SHA512:
6
- metadata.gz: 6b2522a014e9bdd08e14e18640210c5d07f8c061fb139662969ac6a8b42126ff682a3630ef1cf8eb26623bf56b4a1d9efe632ab3c68555234c39133c657e3fe7
7
- data.tar.gz: 9367398ad9236ff0b0913dee33199c71936c1739bf47241477c985c94df558b395c10195feb08504097861ea3bcf1a7a1a073f0d12bd444e44b20770860694f3
6
+ metadata.gz: 5d8f2a57c1dc3e062ce9651870ca2de7b9553ba9e20fe0d2007c28abf0315c1515ac0ec13ad2a1b85f1a0c1b181f3b453609433c4359c054b28d9fa943131dd5
7
+ data.tar.gz: 31bc1db1950c708442630d2415cbbda32e4bcd49667d7eb4380c8ef89e2486f21f360477f82eb8c26945002d8cb3ab5fa1824172c30579cbb337a564fbb8c98a
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - 'spec/*'
3
+ - 'spec/**/**'
4
4
  - 'Gemfile'
5
5
  - 'Rakefile'
6
6
  - '*.gemspec'
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # 0.0.3
2
+ ## New Features
3
+ - Can fire and miss a target on the board
4
+
5
+ # 0.0.2
6
+ ## Bug Fixes
7
+ - YANKED due to vulnerability with rubocop development dependency
8
+
9
+ # 0.0.1
10
+ ## New Features
11
+ - Welcome message
12
+
13
+ # 0.0.0
14
+ ## New Features
15
+ - claim name
data/Gemfile.lock CHANGED
@@ -1,14 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- battle_boats (0.0.1)
4
+ battle_boats (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  diff-lcs (1.3)
10
11
  docile (1.3.0)
11
12
  json (2.1.0)
13
+ parallel (1.12.1)
14
+ parser (2.5.1.0)
15
+ ast (~> 2.4.0)
16
+ powerpack (0.1.1)
17
+ rainbow (3.0.0)
12
18
  rake (10.5.0)
13
19
  rspec (3.7.0)
14
20
  rspec-core (~> 3.7.0)
@@ -23,11 +29,20 @@ GEM
23
29
  diff-lcs (>= 1.2.0, < 2.0)
24
30
  rspec-support (~> 3.7.0)
25
31
  rspec-support (3.7.1)
32
+ rubocop (0.55.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.5)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.9.0)
26
40
  simplecov (0.16.1)
27
41
  docile (~> 1.1)
28
42
  json (>= 1.8, < 3)
29
43
  simplecov-html (~> 0.10.0)
30
44
  simplecov-html (0.10.2)
45
+ unicode-display_width (1.3.2)
31
46
 
32
47
  PLATFORMS
33
48
  ruby
@@ -37,7 +52,8 @@ DEPENDENCIES
37
52
  bundler (~> 1.16)
38
53
  rake (~> 10.0)
39
54
  rspec (~> 3.0)
40
- simplecov
55
+ rubocop (~> 0.42)
56
+ simplecov (~> 0.16)
41
57
 
42
58
  BUNDLED WITH
43
59
  1.16.1
data/battle_boats.gemspec CHANGED
@@ -31,5 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "bundler", "~> 1.16"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "simplecov"
34
+ spec.add_development_dependency "rubocop", "~> 0.55"
35
+ spec.add_development_dependency "simplecov", "~> 0.16"
35
36
  end
data/bin/battle_boats CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'battle_boats'
4
-
5
- console_ui = BattleBoats::ConsoleUI.new
6
- console_ui.greet
3
+ require 'battle_boats/engine'
4
+ BattleBoats::Engine.new.start
@@ -0,0 +1,22 @@
1
+ module BattleBoats
2
+ class Board
3
+ attr_reader :play_area, :status_report
4
+
5
+ def initialize
6
+ @status_report = ""
7
+ @play_area = []
8
+ 10.times do
9
+ row = []
10
+ 10.times do
11
+ row << nil
12
+ end
13
+ @play_area << row
14
+ end
15
+ end
16
+
17
+ def strike_position(row:, column:)
18
+ @play_area[row.to_i][column.to_i] = "X"
19
+ @status_report = "Miss!"
20
+ end
21
+ end
22
+ end
@@ -1,15 +1,75 @@
1
1
  module BattleBoats
2
2
  class ConsoleUI
3
- def initialize(output: $stdout)
3
+ def initialize(output: $stdout, input: $stdin)
4
4
  @output = output
5
+ @input = input
5
6
  end
6
7
 
7
8
  def greet
8
9
  output.puts "Welcome to Battle Boats!"
9
10
  end
10
11
 
12
+ def display_board(board)
13
+ output.puts format_board(board)
14
+ end
15
+
16
+ def get_row
17
+ output.puts "Target row:"
18
+ input.gets.chomp
19
+ end
20
+
21
+ def get_column
22
+ output.puts "Target column:"
23
+ input.gets.chomp
24
+ end
25
+
26
+ def display_status_report(status_report)
27
+ output.puts status_report
28
+ end
29
+
11
30
  private
12
31
 
13
- attr_reader :output
32
+ attr_reader :output, :input
33
+
34
+ def format_board(board)
35
+ board_string = horizontal_line
36
+ board_string << newline
37
+ board_string << top_row
38
+ board_string << horizontal_line
39
+ board_string << newline
40
+ board.play_area.each_with_index do |row, row_number|
41
+ board_string << pipe
42
+ board_string << " #{row_number} "
43
+ board_string << pipe
44
+ row.each do |cell|
45
+ board_string << if cell
46
+ " #{cell} "
47
+ else
48
+ " . "
49
+ end
50
+ board_string << pipe
51
+ end
52
+ board_string << newline
53
+ board_string << horizontal_line
54
+ board_string << newline
55
+ end
56
+ board_string
57
+ end
58
+
59
+ def top_row
60
+ "| | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |\n"
61
+ end
62
+
63
+ def newline
64
+ "\n"
65
+ end
66
+
67
+ def horizontal_line
68
+ "-" * 67
69
+ end
70
+
71
+ def pipe
72
+ "|"
73
+ end
14
74
  end
15
75
  end
@@ -0,0 +1,27 @@
1
+ require_relative "board"
2
+ require_relative "console_ui"
3
+
4
+ module BattleBoats
5
+ class Engine
6
+ def initialize(interface: BattleBoats::ConsoleUI.new,
7
+ board: BattleBoats::Board.new)
8
+ @interface = interface
9
+ @board = board
10
+ end
11
+
12
+ def start
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)
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :interface, :board
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module BattleBoats
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
data/lib/battle_boats.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "battle_boats/version"
2
+ require "battle_boats/engine"
2
3
  require "battle_boats/console_ui"
4
+ require "battle_boats/board"
3
5
 
4
6
  module BattleBoats
5
7
  # Your code goes here...
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.1
4
+ version: 0.0.3
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-08 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.55'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.55'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '0.16'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '0.16'
69
83
  description: 'Battleship is a two-player guessing game. More details can be found
70
84
  here: https://en.wikipedia.org/wiki/Battleship_(game)'
71
85
  email:
@@ -80,6 +94,7 @@ files:
80
94
  - ".rspec"
81
95
  - ".rubocop.yml"
82
96
  - ".travis.yml"
97
+ - CHANGELOG.md
83
98
  - CODE_OF_CONDUCT.md
84
99
  - Gemfile
85
100
  - Gemfile.lock
@@ -91,7 +106,9 @@ files:
91
106
  - bin/console
92
107
  - bin/setup
93
108
  - lib/battle_boats.rb
109
+ - lib/battle_boats/board.rb
94
110
  - lib/battle_boats/console_ui.rb
111
+ - lib/battle_boats/engine.rb
95
112
  - lib/battle_boats/version.rb
96
113
  homepage: https://www.github.com/thomascountz/battle_boats
97
114
  licenses: