tic_tac_toe_bfox 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/{bin → exe}/setup +0 -0
- data/{bin → exe}/tictactoe +0 -0
- data/lib/tictactoe/game.rb +49 -13
- data/lib/tictactoe/input_helper.rb +27 -1
- data/lib/tictactoe/version.rb +1 -1
- data/tictactoe.gemspec +1 -0
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77bae52f24f75f486df81b5ffa3531a4c22e2794
|
4
|
+
data.tar.gz: 4e25c2db4e1dcbd85ba59a70023428e1affda332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4787f634c001fca03954538925b481c295f02272ab4eba395bb4965fb4c2518390311ca2f72642027f6b420e75275c2112a431a94aeca80759ce7b8c096c97b8
|
7
|
+
data.tar.gz: af573af23a3896e6ae51e76b9c2c01174ea7b56cfe37ed4519b8d7b190cc9722aaa37c1f30c1877ee9db775093b39f296f8ee78520d87f35d965c71d5d851844
|
data/README.md
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
**Instructions:**
|
4
4
|
|
5
|
-
1. In order to play the game, please type **
|
5
|
+
1. In order to play the game, please type **tictactoe** into your console.
|
6
6
|
2. Follow the prompts to set your name and the value of your mark.
|
7
7
|
3. Choose whether you would like to play a computer (**"C"**) or a human (**"H"**).
|
8
8
|
4. If you choose to play a computer, further choose whether you would like to play
|
9
9
|
* an easy (**"E"**) computer: this computer selects randomly
|
10
10
|
* a difficult (**"D"**) computer: this computer is impossible to beat!
|
11
11
|
5. Choose how many squares per row you would like. Note that 9 is the maximum, unless you are playing a difficult computer, who prefers to play with a maximum of 3 squares per row.
|
12
|
+
6. In order to exit the game at any time, please type **exit** into your console.
|
data/{bin → exe}/setup
RENAMED
File without changes
|
data/{bin → exe}/tictactoe
RENAMED
File without changes
|
data/lib/tictactoe/game.rb
CHANGED
@@ -16,7 +16,7 @@ module TTT
|
|
16
16
|
# below finds the user needed input needed for initial players and board configuration and stores in config object
|
17
17
|
@config = GameConfig.new(@input_helper)
|
18
18
|
@players = generate_players
|
19
|
-
@board =
|
19
|
+
@board = generate_empty_board
|
20
20
|
end
|
21
21
|
|
22
22
|
#overriding so that io and input_helper always in harmony
|
@@ -31,28 +31,48 @@ module TTT
|
|
31
31
|
[player_1, player_2]
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def generate_empty_board
|
35
35
|
number_of_rows_cols = config.number_of_rows_cols
|
36
36
|
Board.new(rows_and_cols: number_of_rows_cols, squares: SquaresFactory.build_empty_squares(number_of_rows_cols) )
|
37
37
|
end
|
38
38
|
|
39
|
+
def reset_board
|
40
|
+
self.board = generate_empty_board
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset_game
|
44
|
+
reset_board
|
45
|
+
self.number_of_turns_taken = 0
|
46
|
+
end
|
47
|
+
|
39
48
|
def play
|
40
|
-
while
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
while true
|
50
|
+
while !over?
|
51
|
+
print_board
|
52
|
+
square_choice = get_square_choice
|
53
|
+
#note that change_square moves current_player forward only if game is not won
|
54
|
+
if square_choice == :exit
|
55
|
+
break
|
56
|
+
else
|
57
|
+
change_square(square_choice, current_player.value)
|
58
|
+
end
|
59
|
+
end
|
46
60
|
|
47
|
-
|
48
|
-
print_board
|
49
|
-
io.present_with_new_line("#{current_player.name} wins!")
|
50
|
-
else
|
61
|
+
#need to print_final_iteration of board
|
51
62
|
print_board
|
52
|
-
|
63
|
+
|
64
|
+
if won?
|
65
|
+
winning_prompt
|
66
|
+
elsif draw?
|
67
|
+
draw_prompt
|
68
|
+
end
|
69
|
+
|
70
|
+
reset_game
|
71
|
+
new_game_starting_graphic
|
53
72
|
end
|
54
73
|
end
|
55
74
|
|
75
|
+
|
56
76
|
def get_square_choice
|
57
77
|
if current_player.type == :human
|
58
78
|
input_helper.get_square_to_change(current_player.name, available_choices)
|
@@ -77,6 +97,10 @@ module TTT
|
|
77
97
|
board.full? || board.won?
|
78
98
|
end
|
79
99
|
|
100
|
+
def draw?
|
101
|
+
board.full? && !board.won?
|
102
|
+
end
|
103
|
+
|
80
104
|
def won?
|
81
105
|
board.won?
|
82
106
|
end
|
@@ -125,5 +149,17 @@ module TTT
|
|
125
149
|
def current_turn_player_index
|
126
150
|
(number_of_turns_taken % number_of_players)
|
127
151
|
end
|
152
|
+
|
153
|
+
def winning_prompt
|
154
|
+
io.present_with_new_line("#{current_player.name} wins!")
|
155
|
+
end
|
156
|
+
|
157
|
+
def draw_prompt
|
158
|
+
io.present_with_new_line("Draw!")
|
159
|
+
end
|
160
|
+
|
161
|
+
def new_game_starting_graphic
|
162
|
+
input_helper.new_game_starting_graphic
|
163
|
+
end
|
128
164
|
end
|
129
165
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module TTT
|
2
2
|
class InputHelper
|
3
|
-
attr_accessor :io
|
3
|
+
attr_accessor :io, :keep_going
|
4
4
|
|
5
5
|
def initialize(io)
|
6
6
|
@io = io
|
@@ -81,6 +81,11 @@ module TTT
|
|
81
81
|
user_choice = nil
|
82
82
|
while true
|
83
83
|
user_choice = io.receive
|
84
|
+
if user_choice.to_s.upcase == "EXIT"
|
85
|
+
#http://blog.honeybadger.io/how-to-exit-a-ruby-program/
|
86
|
+
exit(0)
|
87
|
+
end
|
88
|
+
#breaks out of input loop if input is valid (the block validation makes sure some rule is true)
|
84
89
|
break if block_validation.call(user_choice)
|
85
90
|
puts reprompt
|
86
91
|
end
|
@@ -95,5 +100,26 @@ module TTT
|
|
95
100
|
end
|
96
101
|
io.present("\n")
|
97
102
|
end
|
103
|
+
|
104
|
+
def new_game_starting_graphic
|
105
|
+
io.present("New game starting in 3")
|
106
|
+
i = 2
|
107
|
+
2.times do
|
108
|
+
marching_dots
|
109
|
+
io.present("#{i.to_s}")
|
110
|
+
i = i - 1
|
111
|
+
end
|
112
|
+
marching_dots
|
113
|
+
io.present("\n")
|
114
|
+
end
|
115
|
+
|
116
|
+
def marching_dots
|
117
|
+
sleep(0.4)
|
118
|
+
io.present(".")
|
119
|
+
sleep(0.3)
|
120
|
+
io.present(".")
|
121
|
+
sleep(0.3)
|
122
|
+
io.present(".")
|
123
|
+
end
|
98
124
|
end
|
99
125
|
end
|
data/lib/tictactoe/version.rb
CHANGED
data/tictactoe.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tic_tac_toe_bfox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Fox
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,10 +52,26 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.4
|
55
69
|
description: In order to play the game, please type "tictactoe" at the command line.
|
56
70
|
email:
|
57
71
|
- brettfox11@gmail.com
|
58
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- setup
|
74
|
+
- tictactoe
|
59
75
|
extensions: []
|
60
76
|
extra_rdoc_files: []
|
61
77
|
files:
|
@@ -65,8 +81,8 @@ files:
|
|
65
81
|
- Gemfile
|
66
82
|
- README.md
|
67
83
|
- Rakefile
|
68
|
-
-
|
69
|
-
-
|
84
|
+
- exe/setup
|
85
|
+
- exe/tictactoe
|
70
86
|
- lib/tictactoe.rb
|
71
87
|
- lib/tictactoe/board.rb
|
72
88
|
- lib/tictactoe/board_presenter_terminal.rb
|