Class: WebGamePresenter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb

Direct Known Subclasses

FourByFour, ThreeByThree, ThreeByThreeByThree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 15

def initialize(options)
  self.board = options.fetch :board
  self.id    = options.fetch :id
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



20
21
22
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 20

def board
  board.board[]
end

#idObject

Returns the value of attribute id.



41
42
43
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 41

def id
  @id
end

Instance Method Details

#generate_form(index) ⇒ Object



37
38
39
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 37

def generate_form(index)
  %Q(<form id="#{index}" class="untaken_square" accept-charset="UTF-8" action="/ttt_games/#{id}/update_game" method="post"><input type="hidden" name="move" value="#{index}"></form>)
end

#next_player_moveObject



29
30
31
32
33
34
35
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 29

def next_player_move
  if TTT::Context.instance.ai_move?(id)
    "ai"
  else
    "human"
  end
end

#side_class(square) ⇒ Object



24
25
26
27
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 24

def side_class(square)
  return 'x_taken_square' if square == "x"
  'o_taken_square'
end