aboutsummaryrefslogtreecommitdiff
path: root/forward-please.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-05-05 13:26:48 +0100
committerNat Lasseter <user@4574.co.uk>2024-05-05 13:26:48 +0100
commit18728ccf1262f3cd1425a8277264d18af73a8a26 (patch)
tree2638206ebc797419420a6015323affa0fd4013fd /forward-please.rb
parente55e883718d4ef025171d25a3e31c84e3175d6fc (diff)
L1 playable
Diffstat (limited to 'forward-please.rb')
-rw-r--r--forward-please.rb42
1 files changed, 35 insertions, 7 deletions
diff --git a/forward-please.rb b/forward-please.rb
index fc36a6e..c919079 100644
--- a/forward-please.rb
+++ b/forward-please.rb
@@ -25,18 +25,41 @@ end
def clickactions
puts "Frames:"
- $clickframes.each do |i, frame|
- puts " #{i}: Interface #{frame.iface} -> #{frame.description}"
+ $clickframes.each do |id, frame|
+ puts " #{id}: #{frame.description} from Interface #{frame.iface}"
end
- l = 1
+ i = 1
puts "Actions:"
$instructions.each do |instr|
- puts " #{l}: Forward frame #{instr[0]} to interface #{instr[1].iface}"
+ puts " #{i}: Forward frame #{instr[0]} to interface #{instr[1].iface}"
end
end
def click
+ right = 0
+ wrong = 0
+
+ targetframes = []
+ $clickframes.each do |id, frame|
+ targetframes += $level.target(frame)
+ end
+
+ $instructions.each do |id, frame|
+ if targetframes.include?(frame)
+ right += 1
+ targetframes.delete(frame)
+ else
+ wrong += 1
+ end
+ end
+ wrong += targetframes.count
+
+ puts "#{right} out of #{right+wrong} correct"
+
+ $instructions = []
+ $clickframes = $level.generate
+ clickactions
end
def handle(cmd)
@@ -44,7 +67,12 @@ def handle(cmd)
when ?h
help
when ?f
- forward(*cmd.split[1..])
+ args = cmd.split[1..]
+ if args.count == 2
+ forward(*args)
+ else
+ puts "f {frame} {iface}"
+ end
when ?d
puts $level.description
when ?i
@@ -53,14 +81,14 @@ def handle(cmd)
clickactions
when ?c
click
- when :q
+ when ?q
exit 0
end
end
$clickframes = $level.generate
-pp $clickframes
+clickactions
loop do
print ">: "
handle(gets.strip)