taka_tic_tac_toe 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/taka_tic_tac_toe/game.rb +0 -38
- data/lib/taka_tic_tac_toe/human.rb +0 -4
- data/lib/taka_tic_tac_toe.rb +0 -1
- metadata +1 -2
- data/lib/taka_tic_tac_toe/console.rb +0 -13
@@ -2,57 +2,23 @@ module TakaTicTacToe
|
|
2
2
|
class Game
|
3
3
|
|
4
4
|
attr_accessor :human, :board, :computer
|
5
|
-
attr_writer :output, :input
|
6
5
|
|
7
6
|
|
8
7
|
def initialize
|
9
8
|
@human = Human.new('X')
|
10
9
|
@board = Board.new
|
11
10
|
@computer = Computer.new('O', @human.mark)
|
12
|
-
@output = STDOUT
|
13
|
-
@input = STDIN
|
14
|
-
end
|
15
|
-
|
16
|
-
def ask_difficulty
|
17
|
-
@output.puts "Enter computer difficulty: (e)asy, (m)edium, (i)mpossible"
|
18
|
-
difficulty = @input.gets.chomp.upcase
|
19
|
-
@computer.difficulty = "ImpossibleAi" if difficulty == "I"
|
20
|
-
@computer.difficulty = "EasyAi" if difficulty == "E"
|
21
|
-
end
|
22
|
-
|
23
|
-
def play
|
24
|
-
@output.puts "Welcome to Tic Tac Toe!"
|
25
|
-
print_board
|
26
|
-
end
|
27
|
-
|
28
|
-
def ask_move
|
29
|
-
@output.puts "Enter your move: "
|
30
11
|
end
|
31
12
|
|
32
13
|
def make_moves(move)
|
33
14
|
choose_move(get_human_mark, move)
|
34
15
|
choose_move(get_computer_mark, computer_move) if !is_over?
|
35
|
-
print_board
|
36
16
|
end
|
37
17
|
|
38
18
|
def reset_board
|
39
19
|
@board.reset
|
40
20
|
end
|
41
21
|
|
42
|
-
def ask_mark
|
43
|
-
@output.puts "Enter a letter for your mark"
|
44
|
-
@human.ask_for_mark
|
45
|
-
end
|
46
|
-
|
47
|
-
def continue?
|
48
|
-
@output.puts "Play again? y/n"
|
49
|
-
@input.gets.chomp.upcase == 'Y'
|
50
|
-
end
|
51
|
-
|
52
|
-
def print_board
|
53
|
-
@output.puts @board.print_slots
|
54
|
-
end
|
55
|
-
|
56
22
|
def get_human_mark
|
57
23
|
@human.mark
|
58
24
|
end
|
@@ -72,9 +38,5 @@ module TakaTicTacToe
|
|
72
38
|
def choose_move(mark, index)
|
73
39
|
@board.set_move(mark, index)
|
74
40
|
end
|
75
|
-
|
76
|
-
def finished
|
77
|
-
@output.puts "End of game, good bye!"
|
78
|
-
end
|
79
41
|
end
|
80
42
|
end
|
data/lib/taka_tic_tac_toe.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taka_tic_tac_toe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -24,7 +24,6 @@ files:
|
|
24
24
|
- lib/taka_tic_tac_toe/ai_difficulty/medium_ai.rb
|
25
25
|
- lib/taka_tic_tac_toe/board.rb
|
26
26
|
- lib/taka_tic_tac_toe/computer.rb
|
27
|
-
- lib/taka_tic_tac_toe/console.rb
|
28
27
|
- lib/taka_tic_tac_toe/game.rb
|
29
28
|
- lib/taka_tic_tac_toe/human.rb
|
30
29
|
- lib/taka_tic_tac_toe/player.rb
|