Class: WebGamePresenter::ThreeByThree

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

Instance Attribute Summary

Attributes inherited from Base

#board, #id

Instance Method Summary collapse

Methods inherited from Base

#generate_form, #initialize, #next_player_move, #side_class

Constructor Details

This class inherits a constructor from WebGamePresenter::Base

Instance Method Details

#show_boardObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 45

def show_board
  html_string = "<table class='three_by_three'><tr>"
  board[].each_with_index do |square, index|
    html_string += "</tr><tr>" if index % 3 == 0 && index != 0
    if square == " "
      html_string += %Q(#{generate_form(index) unless board.finished?}<td value="#{index}" class="square #{next_player_move} #{square_class(index)}"></td>)
    else
      html_string += %Q(<td id="#{index}" name="move" class="square #{side_class(square)} #{square_class(index)}">#{square}</td>)
    end
  end
  html_string += "</tr></table>"
end

#square_class(index) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 58

def square_class(index)
  html_class = case index
               when 0 then 'top_left'
               when 1 then 'top_middle'
               when 2 then 'top_right'
               when 3 then 'middle_left'
               when 4 then 'middle'
               when 5 then 'middle_right'
               when 6 then 'bottom_left'
               when 7 then 'bottom_middle'
               when 8 then 'bottom_right'
               end
end