-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
53 lines (48 loc) · 1.24 KB
/
game.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
require "highline/import"
require "./lib/naughts_and_crosses.rb"
require "./lib/connect_game.rb"
say "Menu"
loop do
choose do |menu|
menu.prompt = "Please select a menu number"
menu.choice "Naughts and Crosses" do
say "Naughts and Crosses\nRules: \nPlayer 1 is x \nPlayer 2 is o\nChoose positions with number 1 - 9"
say empty_board
board = empty_board
play_sequence = 1
game_play = true
while game_play
begin
position = ask "Choose a number 1 - 9", Integer
board = play_on_board(board, position, play_sequence)
say board
play_sequence += 1
if board.include?(" wins") or board.include?(" moves")
game_play = false
end
rescue RuntimeError => e
say e.message
end
end
end
menu.choice "Connect the dots" do
say "Connect the dots\n Rules: \n Player Red is R\n Player Blue is B\n"
@game = ConnectGame.new
say @game.board
game_play = true
while game_play
begin
row = ask "Choose a row from 1 -5 to play", Integer
@game.play(row)
say @game.board
if @game.done?.include?(" Wins")
game_play = false
end
rescue RuntimeError => e
say e.message
end
end
end
menu.choice(:Exit) { exit }
end
end