class Command_History
This class stores the commands that have been entered by the player, so we can have bash-style command history.
Public Class Methods
new()
click to toggle source
# File lib/skirmish/utilities.rb, line 12 def initialize @history = Array.new @position = 0 # The current 'position' in the list of commands end
Public Instance Methods
add_command(command)
click to toggle source
The user entered a command - store it to the list and update the pointer
# File lib/skirmish/utilities.rb, line 18 def add_command(command) @history.push command @position = @history.length - 1 end
get_next()
click to toggle source
Unless we're already looking at the most recent item in the list, increment the 'position' pointer and return the command at the new position
# File lib/skirmish/utilities.rb, line 37 def get_next unless @position == @history.length - 1 @position += 1 next_command = @history[@position] return next_command else return nil end end
get_previous()
click to toggle source
Unless we're already looking at the first item in the list, return the command at the current position and decrement the 'position' pointer
# File lib/skirmish/utilities.rb, line 25 def get_previous unless @position == 0 previous_command = @history[@position] @position -= 1 return previous_command else return nil end end