-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.rb
69 lines (59 loc) · 1.71 KB
/
driver.rb
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
load 'Pentago.rb'
def play_pentago
pBoard = Pentago.new
redraw_board = true
gameOver = false
# loop until all marbles are placed or there is a winner
while !gameOver
# draw the board if neccessary
if redraw_board
pBoard.print_board
else
redraw_board = true
end
# play the turn
puts pBoard.get_player_turn + " please place a marble: "
# the input needs to be error checked
puts "Enter row: "
# get row number from user
row = gets.to_i
break if 'c' == row
puts "Enter column: "
# get column number from user
col = gets.to_i
break if 'r' == col
# place the marble in the desired location
marble_placed = pBoard.place_marble(row, col)
if (marble_placed)
# print the board with the newly placed marble
pBoard.print_board
# select board to turn
puts pBoard.get_player_turn + " must choose a board to turn left or right"
puts "Enter board to turn: "
board = gets.chomp
puts "Enter direction (L/R): "
direction = gets.chomp
pBoard.turn_board(board, direction)
# check for winner
# getWinner returns Draw, None, or player 1 or 2
winner = pBoard.get_winner
if "None" == winner
# no winner, switch player turn and keep going
pBoard.switch_player_turn
elsif "Draw" == winner
# tie game
pboard.print_board
puts "Cat's game! But you can always play again."
gameOver = true
else
pBoard.print_board
puts "Winner is #{winner}. Congratulations #{winner}"
gameOver = true
end
else
puts "\n*****Please choose an unoccupied space*****"
redraw_board = false
end
end
end
play_pentago