-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.rb
81 lines (71 loc) · 2 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
# This script loads all the dependencies for the chess program, prints a title screen and allows the user to
# select runtime options, particularly what types of players (human or ai) and whether to
# load a serialised save or start a fresh game.
require_relative "lib/utilities/display"
require_relative "lib/utilities/colour_patch"
require_relative "lib/utilities/save_manager"
require_relative "lib/utilities/piece_hashes"
require_relative "lib/utilities/empty_square"
require_relative "lib/utilities/castling"
require_relative "lib/utilities/player_types"
require_relative "lib/move"
require_relative "lib/move_tree"
require_relative "lib/board"
require_relative "lib/player"
require_relative "lib/computer_player"
require_relative "lib/round"
require_relative "lib/game_loop"
require_relative "lib/referee"
require_relative "lib/pieces/piece_icons"
require_relative "lib/pieces/piece"
require_relative "lib/pieces/king"
require_relative "lib/pieces/queen"
require_relative "lib/pieces/rook"
require_relative "lib/pieces/bishop"
require_relative "lib/pieces/knight"
require_relative "lib/pieces/pawn"
def new_session
menu
play_again
end
def play_again
print Display.play_again_msg
choice = gets.chomp.downcase
choice == "y" ? new_session : puts(Display.thanks_exit_msg)
end
def title
puts Display.title_art
puts Display.test_welcome_msg
puts Display.any_key_msg
gets
end
def menu
Display.clear_console
puts Display.menu_msg
choice = gets.chomp
case choice
when "1" then select_runtime("1")
when "2" then select_runtime("2")
when "3" then rules
else menu
end
end
def select_player_types
Display.clear_console
puts Display.player_select_msg
type = gets.chomp.downcase
return type if (1..4).include?(type.to_i)
select_player_types
end
def rules
Display.clear_console
puts Display.rules_msg
gets
menu
end
def select_runtime(option)
runtime = option == "2" ? SaveManager.load_save : Round.new(player_types: select_player_types)
GameLoop.new(runtime).play
end
title
new_session