Class: TTT::HtmlGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt/interfaces/web_interface/html_generator.rb

Instance Method Summary collapse

Constructor Details

#initializeHtmlGenerator

Returns a new instance of HtmlGenerator.



3
4
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 3

def initialize
end

Instance Method Details

#game_list(games) ⇒ Object



14
15
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 14

def game_list(games)
end

#hidden_field(game, game_id) ⇒ Object



17
18
19
20
21
22
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 17

def hidden_field(game, game_id)
  html_string = ""
  html_string += %q[<div id="current_player" game_id="#{game_id}">]
  html_string += true if game.ai_move? && !game.board.finished?
  html_string += "</div>"
end

#html_closeObject



72
73
74
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 72

def html_close
  "</body></html>"
end

#html_openObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 54

def html_open
  html_string = ""
  html_string += %q[<!DOCTYPE html>]
  html_string += %q[<html><head><title>Java Server TTT</title>]
  html_string += %q[<link href="/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />]
  html_string += %q[<link href="/css/application.css" media="all" rel="stylesheet" type="text/css" />]
  html_string += %q[<link href="/css/tictactoe.css" media="all" rel="stylesheet" type="text/css" />]
  html_string += %q[<link href="/css/web_game.css" media="all" rel="stylesheet" type="text/css" />]
  html_string += %q[<script src="/js/jquery.js" type="text/javascript"></script>]
  html_string += %q[<script src="/js/ttt.js" type="text/javascript"></script>]
  html_string += %q[<script src="/js/application.js" type="text/javascript"></script></head>]
  html_string += %q[<body><div class="main_buttons"><div class="new_game_btn_wrapper">]
  html_string += %q[<a href="/new_game" class="button">New Game</a></div>]
  html_string += %q[<div class="all_games_btn_wrapper">]
  html_string += %q[<a href="/game_list" class="button">All Games</a></div>]
  html_string += %q[</div>]
end

#main_body(flash_message, web_game_presenter) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 24

def main_body(flash_message, web_game_presenter)
  html_string = ""
  html_string += %q[<div style="width: 1020px; margin: 100px auto 20px auto;">]
  html_string += %q[<h4 class="notice">#{flash_message}</h4>] if flash_message
  html_string += web_game_presenter.show_board
  html_string += "</div>"
end

#move_historyObject



32
33
34
35
36
37
38
39
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 32

def move_history
  html_string = ""
  html_string += %q[<div id="buttons" style="width: 800px; margin: auto;">]
  html_string += %q[<div id="button_left" style="float: left; margin-left: 200px;">]
  html_string += %q[<img src="/images/button_left.png" class="pointer" /></div>]
  html_string += %q[<div id="button_right" style="float: right; margin-right: 200px;">]
  html_string += %q[<img src="/images/button_right.png" class="pointer" /></div></div>]
end

#move_index(web_game_history) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 41

def move_index(web_game_history)
  html_string = ""
  html_string += %q[<div class="move_history" style="float: right; width: 170px; height: 800px; text-align: right;">]
  html_string += %q[<h4 style="text-align: center;">Move History</h4>]
  html_string += %q[<ul style="width: 215px;">]
  game_history.each_with_index do |move, index|
    move_list_class = index == 0 ? "move_list_first" : "move_list"
    html_string += %q[<li class="#{move_list_class}"><span style="margin-right: 10px;">#{index + 1})</span>]
    html_string += %q[<span style="margin-right: 10px;">#{move.side}</span> #{move.move}]
  end
  html_string += "</ul></div>"
end

#new_gameObject



6
7
8
9
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 6

def new_game
  html_string = html_open
  html_string += html_close
end

#show_game(game, game_id, game_history) ⇒ Object



11
12
# File 'lib/ttt/interfaces/web_interface/html_generator.rb', line 11

def show_game(game, game_id, game_history)
end