Class: Beefdump::Game::Base

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

Constant Summary collapse

CLIENT_UPDATE_RATE =

10 times a second

1.0 / 10
GAME_STATE_PATH =
"#{ROOT_PATH}/game_state"
CURRENT_GAME_STATE_FILE =
"#{GAME_STATE_PATH}/current.bin"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/beefdump/game/base.rb', line 13

def initialize
  load_static_data
  load_map('test')
  init_game_state
    
  load_clients

  @shutdown = false

  game_loop
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



11
12
13
# File 'lib/beefdump/game/base.rb', line 11

def map
  @map
end

Instance Method Details

#claim_player(name, client) ⇒ Object



35
36
37
38
39
# File 'lib/beefdump/game/base.rb', line 35

def claim_player(name, client)
  player = @state.players.select {|p| p.name == name}.first
  raise "Player not found" unless player
  player
end

#load_map(new_map) ⇒ Object



25
26
27
# File 'lib/beefdump/game/base.rb', line 25

def load_map(new_map)
  @map = Map.load(new_map)
end

#should_run?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/beefdump/game/base.rb', line 41

def should_run?
  !@shutdown
end

#shutdown!Object



29
30
31
32
33
# File 'lib/beefdump/game/base.rb', line 29

def shutdown!
  Logger.info "Received shutdown command from client. Quitting game."
  save_game_state
  @shutdown = true
end