Module: Goby

Includes:
Music, WorldCommand
Defined in:
lib/goby/util.rb,
lib/goby/music.rb,
lib/goby/driver.rb,
lib/goby/map/map.rb,
lib/goby/map/tile.rb,
lib/goby/scaffold.rb,
lib/goby/event/npc.rb,
lib/goby/item/food.rb,
lib/goby/item/item.rb,
lib/goby/item/legs.rb,
lib/goby/battle/use.rb,
lib/goby/event/shop.rb,
lib/goby/item/torso.rb,
lib/goby/event/chest.rb,
lib/goby/event/event.rb,
lib/goby/item/helmet.rb,
lib/goby/item/shield.rb,
lib/goby/item/weapon.rb,
lib/goby/battle/attack.rb,
lib/goby/battle/battle.rb,
lib/goby/battle/escape.rb,
lib/goby/entity/entity.rb,
lib/goby/entity/player.rb,
lib/goby/world_command.rb,
lib/goby/entity/fighter.rb,
lib/goby/entity/monster.rb,
lib/goby/item/equippable.rb,
lib/goby/battle/battle_command.rb

Overview

Collection of classes, modules, and functions that make up the Goby framework.

Defined Under Namespace

Modules: Equippable, Fighter, Music, Scaffold, WorldCommand Classes: Attack, Battle, BattleCommand, C, Chest, Entity, Escape, Event, Food, Helmet, Item, Legs, Location, Map, Monster, NPC, Player, Shield, Shop, Tile, Torso, Use, Weapon

Constant Summary

Constants included from WorldCommand

WorldCommand::DEFAULT_COMMANDS, WorldCommand::NO_ITEM_DROP_ERROR, WorldCommand::SPECIAL_COMMANDS_HEADER

Instance Method Summary collapse

Methods included from WorldCommand

#describe_tile, #display_default_commands, #display_special_commands, #help, #interpret_command

Methods included from Music

#play_music, #set_playback, #set_program, #stop_music

Instance Method Details

#load_game(filename) ⇒ Player

Reads and check the save file and parses into the player object

Parameters:

  • filename (String)

    the file containing the save data.

Returns:

  • (Player)

    the player corresponding to the save data.



106
107
108
109
110
111
112
113
# File 'lib/goby/util.rb', line 106

def load_game(filename)
  begin
    player = YAML.load_file(filename)
    return player
  rescue
    return nil
  end
end

#player_input(lowercase: true, prompt: '', doublespace: true) ⇒ Object

Simple player input script.

Parameters:

  • lowercase (Boolean) (defaults to: true)

    mark true if response should be returned lowercase.

  • prompt (String) (defaults to: '')

    the prompt for the user to input information.

  • doublespace (Boolean) (defaults to: true)

    mark false if extra space should not be printed after input.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/goby/util.rb', line 55

def player_input(lowercase: true, prompt: '', doublespace: true)

  # When using Readline, rspec actually prompts the user for input, freezing the tests.
  print prompt
  input = (ENV['TEST'] == 'rspec') ? gets.chomp : Readline.readline(" \b", false)
  puts "\n" if doublespace

  if ((input.size > 1) and (input != Readline::HISTORY.to_a[-1]))
    Readline::HISTORY.push(input)
  end

  return lowercase ? input.downcase : input
end

#run_driver(player) ⇒ Object

Runs the main game loop.

Parameters:

  • player (Player)

    the player of the game.



11
12
13
14
# File 'lib/goby/driver.rb', line 11

def run_driver(player)
  while (run_turn(player)); end
  stop_music
end

#save_game(player, filename) ⇒ Object

Serializes the player object into a YAML file and saves it

Parameters:

  • player (Player)

    the player object to be saved.

  • filename (String)

    the name under which to save the file.



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/goby/util.rb', line 88

def save_game(player, filename)

  # Set 'moved' to true so we see minimap on game load.
  player.moved = true
  player_data = YAML::dump(player)
  player.moved = false

  File.open(filename, "w") do |file|
    file.puts player_data
  end
  print "Successfully saved the game!\n\n"
  return
end

#type(message) ⇒ Object

Prints text as if it were being typed.

Parameters:

  • message (String)

    the message to type out.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/goby/util.rb', line 72

def type(message)

  # Amount of time to sleep between printing character.
  time = ENV['TEST'] ? 0 : 0.015

  # Sleep between printing of each char.
  message.split("").each do |i|
    sleep(time) if time.nonzero?
    print i
  end
end