-
Notifications
You must be signed in to change notification settings - Fork 827
Expand file tree
/
Copy pathrunner.rb
More file actions
70 lines (65 loc) · 2.32 KB
/
runner.rb
File metadata and controls
70 lines (65 loc) · 2.32 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
require 'optparse'
require 'fileutils'
module RubyWarrior
class Runner
def initialize(arguments, stdin, stdout)
@arguments = arguments
@stdin = stdin
@stdout = stdout
@game = RubyWarrior::Game.new
end
def run
Config.in_stream = @stdin
Config.out_stream = @stdout
Config.delay = 0.6
parse_options
@game.start
end
def reset
if ! File.directory?('rubywarrior/')
# If the directory doesn't exist, we can't reset the progress.
print "No progress to reset.\n"
else
directories = Dir["rubywarrior/*"]
if directories.length>0
puts inputProfile = UI.choose('directory', directories)
if inputProfile != nil
if File.directory?('%{IN}'% {IN:inputProfile})
# Prompt the user to avoid accidental an reset.
print "Are you sure you want to reset your progress? [yn]\n"
input = gets.chomp
if input == 'y'
FileUtils.rm_rf('%{IN}'% {IN:inputProfile} )
print "Progress reset.\n"
elsif input == 'n'
print "Progress not reset.\n"
else
print "Not a valid option (y or n). Please try again.\n"
reset
end
else
print "No such profile.\n"
end
else
print "No profile name provided.\n"
end
else
print "No profile to reset."
end
end
exit
end
private
def parse_options
options = OptionParser.new
options.banner = "Usage: rubywarrior [options]"
options.on('-d', '--directory DIR', "Run under given directory") { |dir| Config.path_prefix = dir }
options.on('-l', '--level LEVEL', "Practice level on epic") { |level| Config.practice_level = level.to_i }
options.on('-r', '--reset', "Reset all Progress ") { reset }
options.on('-s', '--skip', "Skip user input") { Config.skip_input = true }
options.on('-t', '--time SECONDS', "Delay each turn by seconds") { |seconds| Config.delay = seconds.to_f }
options.on('-h', '--help', "Show this message") { puts(options); exit }
options.parse!(@arguments)
end
end
end