class ScottKit::Game::Instruction

Public Instance Methods

execute(args) click to toggle source

Returns true iff interpreter should continue to next action

# File lib/scottkit/play.rb, line 410
def execute(args)
  @game.dputs :show_instructions,
    "      executing #{self.render(args.clone)}"
  if (@op == 0)
    return false # shouldn't happen
  elsif (@op <= 51)
    puts @game.messages[@op].gsub('`', '"')
    return false
  elsif (@op >= 102)
    puts @game.messages[@op-50].gsub('`', '"')
    return false
  else case @op
  when 52 then
    if @game.ncarried == @game.maxload
      puts "I've too much to carry!"
    else
      @game.items[args.shift].loc = ROOM_CARRIED
      puts "O.K."
    end
  when 53 then @game.items[args.shift].loc = @game.loc
  when 54 then @game.loc = args.shift
  when 55 then @game.items[args.shift].loc = ROOM_NOWHERE
  when 56 then @game.flags[15] = true
  when 57 then @game.flags[15] = false
  when 58 then @game.flags[args.shift] = true
  when 59 then @game.items[args.shift].loc = ROOM_NOWHERE
  when 60 then @game.flags[args.shift] = false
  when 61 then
    puts "I am dead."; @game.flags[15] = false;
    @game.loc = @game.rooms.size-1; @game.need_to_look
  when 62 then i = args.shift; @game.items[i].loc = args.shift
  when 63 then @game.finish(0)
  when 64 then @game.need_to_look
  when 65 then @game.score
  when 66 then @game.inventory
  when 67 then @game.flags[0] = true
  when 68 then @game.flags[0] = false
  when 69 then
    @game.items[ITEM_LAMP].loc = ROOM_CARRIED
    @game.lampleft = @game.lamptime
    @game.flags[FLAG_LAMPDEAD] = false
  when 70 then # do nothing
  when 71 then @game.prompt_and_save
  when 72 then
    item1 = @game.items[args.shift]
    item2 = @game.items[args.shift]
    item1.loc, item2.loc = item2.loc, item1.loc
  when 73 then return true
  when 74 then @game.items[args.shift].loc = ROOM_CARRIED
  when 75 then i1 = args.shift; i2 = args.shift
    @game.items[i1].loc = @game.items[i2].loc
  when 76 then @game.need_to_look
  when 77 then @game.counter -= 1
  when 78 then print @game.counter, " "
  when 79 then @game.counter = args.shift
  when 80 then @game.loc, @game.saved_room = @game.saved_room, @game.loc
  when 81 then which = args.shift
    @game.counter, @game.counters[which] =
      @game.counters[which], @game.counter
  when 82 then @game.counter += args.shift
  when 83 then @game.counter -= args.shift
  when 84 then print @game.noun
  when 85 then puts @game.noun
  when 86 then puts
  when 87 then which = args.shift
    @game.loc, @game.saved_rooms[which] =
      @game.saved_rooms[which], @game.loc
  #87 swap_specific_room unused in Adventureland/Pirate
  when 88 then sleep 2 if !@game.options[:no_wait]
  #88 wait unused in Adventureland/Pirate
  #89 draw unused in Adventureland/Pirate
  else raise "unimplemented instruction code #@op"
  end
  end
  return false
end
quote(*args) click to toggle source
# File lib/scottkit/decompile.rb, line 141
def quote(*args); @game.quote(*args); end
render(args) click to toggle source
# File lib/scottkit/decompile.rb, line 143
def render(args)
  if (@op == 0)
    return "NOP" # shouldn't happen
  elsif (@op <= 51)
    return "print #{quote @game.messages[@op]}"
  elsif (@op >= 102)
    return "print #{quote @game.messages[@op-50]}"
  end

  op = OPS[@op-52]
  return "UNKNOWN_OP" if !op
  op[0] + case op[1]
  when :item
    " #{quote @game.itemname(args.shift)}"
  when :room
    " #{quote @game.roomname(args.shift)}"
  when :number
    " #{@game.quote String(args.shift)}"
  when :item_item
    " #{quote @game.itemname(args.shift)}" +
    " #{quote @game.itemname(args.shift)}"
  when :item_room
    " #{quote @game.itemname(args.shift)}" +
    " #{quote @game.roomname(args.shift)}"
  when :NONE
    "" # Nothing to add
  else
    " UNKNOWN_PARAM"
  end
end