Class: ClasslessMud::Game

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world, settings) ⇒ Game

Returns a new instance of Game.



6
7
8
9
10
# File 'lib/classless_mud/game.rb', line 6

def initialize world, settings
  @players = []
  @world = world
  @settings = settings
end

Instance Attribute Details

#playersObject (readonly)

Returns the value of attribute players.



3
4
5
# File 'lib/classless_mud/game.rb', line 3

def players
  @players
end

#settingsObject (readonly)

Returns the value of attribute settings.



4
5
6
# File 'lib/classless_mud/game.rb', line 4

def settings
  @settings
end

Instance Method Details

#add_player(player) ⇒ Object



12
13
14
15
16
17
# File 'lib/classless_mud/game.rb', line 12

def add_player player
  @players << player
  @world.add_player player
  starting_room.enter player
  broadcast "#{player.name} has joined the game."
end

#broadcast(message) ⇒ Object



28
29
30
# File 'lib/classless_mud/game.rb', line 28

def broadcast message
  @world.handle_message message
end

#display_players(player) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/classless_mud/game.rb', line 32

def display_players player
  player.puts "Currently active players\n------------------------\n\#{@players.map(&:name).join(\"\\n\")}\n"
end

#remove_player(player) ⇒ Object



23
24
25
26
# File 'lib/classless_mud/game.rb', line 23

def remove_player player
  @players.delete player
  broadcast "#{player.name} has left the game."
end

#starting_roomObject



19
20
21
# File 'lib/classless_mud/game.rb', line 19

def starting_room
  @world.starting_room
end