battle_boats 0.1.0 → 0.2.0

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: 61b60dbcbc5c2bacf5a9690767c0e8cb0fb63b93
4
- data.tar.gz: 2fd42e2e42aee3d500a4d80025183e5f545c82b8
3
+ metadata.gz: 0f62377f075c9e70f367ab75639126cf5b4c786c
4
+ data.tar.gz: 2c179de8a9b6c69d0622c0a97806c1fb4277da01
5
5
  SHA512:
6
- metadata.gz: 97c3219a5f1dfa994cc2aabb0a4c716f5b044296a7a5f3efb862c5ecc5f889c68becb3a746ffece89770227137b9728c91e27c944636ad59549894cd371070a0
7
- data.tar.gz: 5b165df1380372d778d6c5708a063de0269912f6c28bc85efe6444d1db770ecf990b0fc8892e30106ba6985c75c27ed88ec77e47c3d12948563c90bda119c2f1
6
+ metadata.gz: 7f8a5bab8721b38fe6f534f9512874464cb9b155a03d4a7ca5e2d0cdb04e64f3e6adab7c7e481ee4cf4585f45c1b902c304cbc3542947116963688e458c7fc8c
7
+ data.tar.gz: 5f7bb5eca963fa72efbf9bebfc8ae663140f3003b260b411a757b98cadefc9142d98a60692c988210d96132c7ea2af29205baf815b82861a0260eb73f0e9e638
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.2.0
2
+ ### New Features
3
+ - After placing your ships, you'll see two boards, yours and the computer player's
4
+ - The computer play fires back at random, immediately after you strike it
5
+ - Your ships are now green, instead of yellow
6
+ - You can lose the game to the computer
7
+
1
8
  # 0.1.0
2
9
  ### New Features
3
10
  - At the start of the game, the user will be prompted to place their ships on their board
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- battle_boats (0.1.0)
4
+ battle_boats (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -66,6 +66,10 @@ module BattleBoats
66
66
  end
67
67
  end
68
68
 
69
+ def get_random_coordinate
70
+ BattleBoats::Coordinate.random(row: 0..9, column: 0..9)
71
+ end
72
+
69
73
  private
70
74
 
71
75
  def create_play_area
@@ -85,9 +89,5 @@ module BattleBoats
85
89
  def within_range?(coordinate:)
86
90
  coordinate.row.between?(0, 9) && coordinate.column.between?(0, 9)
87
91
  end
88
-
89
- def get_random_coordinate
90
- BattleBoats::Coordinate.random(row: 0..9, column: 0..9)
91
- end
92
92
  end
93
93
  end
@@ -17,7 +17,7 @@ module BattleBoats
17
17
  board_string << if cell.occupied? && cell.hit?
18
18
  " #{cell.occupant.symbol.red} "
19
19
  elsif cell.occupied? && !hide_ships
20
- " #{cell.occupant.symbol.yellow} "
20
+ " #{cell.occupant.symbol.green} "
21
21
  elsif cell.hit?
22
22
  " #{'X'.yellow} "
23
23
  else
@@ -12,6 +12,10 @@ module BattleBoats
12
12
  def yellow
13
13
  "\e[33m#{self}\e[0m"
14
14
  end
15
+
16
+ def green
17
+ "\e[32m#{self}\e[0m"
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -56,6 +56,10 @@ module BattleBoats
56
56
  output.puts "You've won the game!"
57
57
  end
58
58
 
59
+ def lose
60
+ output.puts "You've lost the game!"
61
+ end
62
+
59
63
  private
60
64
 
61
65
  attr_reader :output, :input, :board_formatter
@@ -16,8 +16,10 @@ module BattleBoats
16
16
  until ally_board.ship_deployed?(ship: ship)
17
17
  interface.display_ally_board(ally_board)
18
18
  interface.display_ship_data(ship: ship)
19
+
19
20
  coordinate = interface.get_coordinate
20
21
  orientation = interface.get_orientation
22
+
21
23
  ally_board.attempt_to_deploy_ship(ship: ship,
22
24
  coordinate: coordinate,
23
25
  orientation: orientation)
@@ -27,21 +29,45 @@ module BattleBoats
27
29
 
28
30
  def start
29
31
  interface.greet
30
- until enemy_board.game_over?
32
+ until game_over?
33
+
34
+ interface.display_status_report(ally_board.status_report)
35
+ interface.display_ally_board(ally_board)
36
+
37
+ interface.display_status_report(enemy_board.status_report)
31
38
  interface.display_board(enemy_board)
39
+
32
40
  coordinate = interface.get_coordinate
33
41
  until enemy_board.strike_position(coordinate: coordinate)
34
42
  interface.display_status_report(enemy_board.status_report)
35
43
  coordinate = interface.get_coordinate
36
44
  end
37
- interface.display_status_report(enemy_board.status_report)
45
+
46
+ enemy_coordinate = enemy_board.get_random_coordinate
47
+ until ally_board.strike_position(coordinate: enemy_coordinate)
48
+ enemy_coordinate = enemy_board.get_random_coordinate
49
+ end
50
+
38
51
  end
39
- interface.win
40
- interface.display_board(enemy_board)
52
+ end_game
41
53
  end
42
54
 
43
55
  private
44
56
 
57
+ def game_over?
58
+ enemy_board.game_over? || ally_board.game_over?
59
+ end
60
+
61
+ def end_game
62
+ interface.display_ally_board(ally_board)
63
+ interface.display_board(enemy_board)
64
+ if enemy_board.game_over?
65
+ interface.win
66
+ else
67
+ interface.lose
68
+ end
69
+ end
70
+
45
71
  attr_reader :interface, :enemy_board, :ally_board
46
72
  end
47
73
  end
@@ -1,3 +1,3 @@
1
1
  module BattleBoats
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".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.1.0
4
+ version: 0.2.0
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-06-06 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler