-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializable.rb
More file actions
25 lines (23 loc) · 779 Bytes
/
Copy pathserializable.rb
File metadata and controls
25 lines (23 loc) · 779 Bytes
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
def show_saved_names
data_directory = Dir.glob("chessgame_data/*.txt")
data_directory.each { |path| puts File.basename(path).chomp(".txt") }
end
def choose_name
puts "What is the name you saved?"
name = gets.chomp
if File.exist? "chessgame_data/#{name}.txt"
puts "We found your progress, You can continue where you left off".light_green
file = open("chessgame_data/#{name}.txt", 'r')
loaded_game = Marshal.load(file.read)
option = loaded_game.option
if option == "1"
loaded_game.human_vs_human
elsif option == "2"
loaded_game.human_vs_ai
else
loaded_game.ai_vs_ai
end
else
puts "This name doesn't exist in our database".light_red
end
end