Class: WebGamePresenter::ThreeByThreeByThree

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 110

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

#square_class(index) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb', line 127

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'
               when 9               then 'top_left'
               when 10              then 'top_middle'
               when 11              then 'top_right'
               when 12              then 'middle_left'
               when 13              then 'middle'
               when 14              then 'middle_right'
               when 15              then 'bottom_left'
               when 16              then 'bottom_middle'
               when 17              then 'bottom_right'
               when 18              then 'top_left'
               when 19              then 'top_middle'
               when 20              then 'top_right'
               when 21              then 'middle_left'
               when 22              then 'middle'
               when 23              then 'middle_right'
               when 24              then 'bottom_left'
               when 25              then 'bottom_middle'
               when 26              then 'bottom_right'
              end
end