-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.rb
More file actions
71 lines (65 loc) · 1.46 KB
/
app.rb
File metadata and controls
71 lines (65 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require_relative 'board.rb'
require_relative 'square.rb'
require 'pp'
class App
def initialize(*players)
@board = Board.new
@score_board = ScoreBoard.new
@turn = 1
@winner = 0
@players = players
end
def welcome
puts 'Welcome to Tick Tack Toe!!!'
puts 'Get ready to play ;)'
end
def turn(player, type)
begin
row, col = player.pick_square
square = Square.new(type, Position.new(row, col))
rescue
puts "Check your spelling dummy"
row, col = player.pick_square
square = Square.new(type, Position.new(row, colgit
end
while @board.is_square_taken?(square)
row, col = player.pick_square
square = Square.new(type, Position.new(row, col))
end
@board.add_new_square(square)
if player == @players[0]
@score_board.player_1_move(square.position)
else
@score_board.player_2_move(square.position)
end
end
def next_turn
if @turn == 1
turn(@players[0], Type.new('X'))
@turn = 0
else
turn(@players[1], Type.new('O'))
@turn = 1
end
puts @board.to_s
end
def end_game(winner)
puts "The winner is #{@players[winner].name}."
puts @board.to_s
#PP.pp(@board)
end
def run_game
welcome
while @winner == 0
if @board.is_finished?
puts 'booom'
exit
end
next_turn
if @score_board.winner?
end_game(@score_board.winner?)
@winner = 1
end
end
end
end