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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/battle_boats/board.rb +4 -4
- data/lib/battle_boats/board_formatter.rb +1 -1
- data/lib/battle_boats/colorize.rb +4 -0
- data/lib/battle_boats/console_ui.rb +4 -0
- data/lib/battle_boats/engine.rb +30 -4
- 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: 0f62377f075c9e70f367ab75639126cf5b4c786c
|
4
|
+
data.tar.gz: 2c179de8a9b6c69d0622c0a97806c1fb4277da01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/battle_boats/board.rb
CHANGED
@@ -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.
|
20
|
+
" #{cell.occupant.symbol.green} "
|
21
21
|
elsif cell.hit?
|
22
22
|
" #{'X'.yellow} "
|
23
23
|
else
|
data/lib/battle_boats/engine.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|