Class: Checkers::Game::State

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/checkers/game/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(turn) ⇒ State

Returns a new instance of State.



11
12
13
14
15
16
# File 'lib/checkers/game/state.rb', line 11

def initialize(turn)
  @board = Board.new
  @turn = turn
  @winner = nil
  @tie = false
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



8
9
10
# File 'lib/checkers/game/state.rb', line 8

def board
  @board
end

#tieObject

Returns the value of attribute tie.



8
9
10
# File 'lib/checkers/game/state.rb', line 8

def tie
  @tie
end

#turnObject

Returns the value of attribute turn.



8
9
10
# File 'lib/checkers/game/state.rb', line 8

def turn
  @turn
end

#winnerObject

Returns the value of attribute winner.



8
9
10
# File 'lib/checkers/game/state.rb', line 8

def winner
  @winner
end

Instance Method Details

#set_state(attrs = {}) ⇒ Object



18
19
20
21
22
# File 'lib/checkers/game/state.rb', line 18

def set_state(attrs = {})
  changed
  attrs.each { |attr, value| send("#{attr}=", value) }
  notify_observers
end