Class: Dat::Games
- Inherits:
-
Object
- Object
- Dat::Games
- Defined in:
- lib/dat/games.rb
Instance Attribute Summary collapse
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
Instance Method Summary collapse
- #[](gid) ⇒ Object
- #add(gid, opt = {}) ⇒ Object
- #check!(gid) ⇒ Object
-
#initialize(logger) ⇒ Games
constructor
A new instance of Games.
Constructor Details
Instance Attribute Details
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
11 12 13 |
# File 'lib/dat/games.rb', line 11 def dict @dict end |
Instance Method Details
#[](gid) ⇒ Object
25 26 27 28 29 |
# File 'lib/dat/games.rb', line 25 def [](gid) @games.fetch(gid) rescue KeyError raise NoGameError, "Game does not exist" end |
#add(gid, opt = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dat/games.rb', line 31 def add(gid, opt={}) opt.merge(:dict => @dict) game = Game.new(@logger.create(gid), opt) opt[:players].each do |p| if p.respond_to?(:bot?) && p.bot? p.init(game) end end @games[gid] = game @games[gid].next_move! end |
#check!(gid) ⇒ Object
19 20 21 22 23 |
# File 'lib/dat/games.rb', line 19 def check!(gid) if @games[gid] && @games[gid].won raise NoGameError, "Game has been won." end end |