From 18728ccf1262f3cd1425a8277264d18af73a8a26 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 5 May 2024 13:26:48 +0100 Subject: L1 playable --- forward-please.rb | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'forward-please.rb') 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) -- cgit v1.2.1