Class: Gemwarrior::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/gemwarrior/game.rb

Constant Summary collapse

INVENTORY_DEFAULT =

CONSTANTS

Inventory.new
INVENTORY_DEBUG =
Inventory.new([Herb.new, Herb.new, Herb.new])
ROX_DEFAULT =
0
ROX_DEBUG =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Game

Returns a new instance of Game.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gemwarrior/game.rb', line 35

def initialize(options)
  # set game options
  GameOptions.add 'beast_mode', options.fetch(:beast_mode)
  GameOptions.add 'debug_mode', options.fetch(:debug_mode)
  GameOptions.add 'god_mode', options.fetch(:god_mode)
  GameOptions.add 'sound_enabled', options.fetch(:sound_enabled)
  GameOptions.add 'sound_system', options.fetch(:sound_system)
  GameOptions.add 'sound_volume', options.fetch(:sound_volume)
  GameOptions.add 'use_wordnik', options.fetch(:use_wordnik)
  GameOptions.add 'fight_completion', options.fetch(:fight_completion)

  # add classes for creatures, monsters, people, items, weapons, and armor to game
  # also add them to the global GameAssets
  init_creatures
  init_monsters
  init_people
  init_items
  init_weapons
  init_armor

  # create new world based on default template
  self.world               = init_world

  # update some player aspects to make more dynamic
  world.player.name        = world.player.generate_name
  world.player.face        = world.player.generate_face
  world.player.hands       = world.player.generate_hands
  world.player.mood        = world.player.generate_mood
  world.player.inventory   = GameOptions.data['debug_mode'] ? INVENTORY_DEBUG : INVENTORY_DEFAULT
  world.player.rox         = GameOptions.data['debug_mode'] ? ROX_DEBUG : ROX_DEFAULT

  # set some global variables
  world.duration           = { mins: 0, secs: 0, ms: 0 }
  world.emerald_beaten     = false
  world.shifty_to_jewel    = false
  world.shifty_has_jeweled = false

  # spawn bosses
  ## Pain Quarry
  world.location_by_name('pain_quarry-southeast').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-east').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-central').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-south').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-west').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-northwest').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  world.location_by_name('pain_quarry-north').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
  ## River Bridge
  world.location_by_name('river_bridge').bosses_abounding.push(Gemwarrior.const_get('Jaspern').new)
  ## Throne Room
  world.location_by_name('sky_tower-throne_room').bosses_abounding.push(Gemwarrior.const_get('Emerald').new)

  # mark home as visited
  world.location_by_name('home').visited = true

  # create options file if not existing
  update_options_file

  # require needed files for selected sound_system if sound_enabled
  if GameOptions.data['sound_enabled']
    Audio.init
  end

  # create the console
  self.evaluator  = Evaluator.new(world)
  self.repl       = Repl.new(self, world, evaluator)

  # enter Jool!
  repl.start('look', options.fetch(:extra_command), options.fetch(:new_skip), options.fetch(:resume_skip))
end

Instance Attribute Details

#evaluatorObject

Returns the value of attribute evaluator.



29
30
31
# File 'lib/gemwarrior/game.rb', line 29

def evaluator
  @evaluator
end

#monstersObject

Returns the value of attribute monsters.



29
30
31
# File 'lib/gemwarrior/game.rb', line 29

def monsters
  @monsters
end

#replObject

Returns the value of attribute repl.



29
30
31
# File 'lib/gemwarrior/game.rb', line 29

def repl
  @repl
end

#weaponsObject

Returns the value of attribute weapons.



29
30
31
# File 'lib/gemwarrior/game.rb', line 29

def weapons
  @weapons
end

#worldObject

Returns the value of attribute world.



29
30
31
# File 'lib/gemwarrior/game.rb', line 29

def world
  @world
end

Instance Method Details

#update_options_fileObject



105
106
107
108
109
110
111
112
113
# File 'lib/gemwarrior/game.rb', line 105

def update_options_file
  File.open(GameOptions.data['options_file_path'], 'w') do |f|
    f.puts "sound_enabled:#{GameOptions.data['sound_enabled']}"
    f.puts "sound_system:#{GameOptions.data['sound_system']}"
    f.puts "sound_volume:#{GameOptions.data['sound_volume']}"
    f.puts "use_wordnik:#{GameOptions.data['use_wordnik']}"
    f.puts "fight_completion:#{GameOptions.data['fight_completion']}"
  end
end