Class: TttGamesController

Inherits:
ApplicationController show all
Defined in:
lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_gameObject



18
19
20
21
22
23
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 18

def create_game
  game              = @context.setup.new_game(player1: params[:player1], player2: params[:player2], board: params[:board])
  cookies[:game_id] = @context.add_game(game)
  flash[:notice]    = "Welcome to Tic Tac Toe!"
  redirect_to :action => "show"
end

#game_listObject



35
36
37
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 35

def game_list
  @games              = @context.game_list
end

#get_gameObject



39
40
41
42
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 39

def get_game
  cookies[:game_id]    = params[:id]
  redirect_to :action => "show"
end

#move_historyObject



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

def move_history
  @game                     = @context.get_game(params[:id])
  @id, cookies[:game_id]    = params[:id], params[:id]
  @web_game_history         = @context.get_history(@id)
  adjust_move_index_pointers(params[:index_diff].to_i)
  @game.board.board         = TttGame.get_history_board(@game, cookies[:move_index])
  @web_game_presenter       = WebGamePresenter.for(board: @game.board, id: cookies[:game_id])
  @finished                 = true
  cookies[:last_id]         = @id
  flash[:notice], view_file = TttGame.evaluate_game(cookies[:game_id], @context)
  render view_file
end

#newObject



11
12
13
14
15
16
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 11

def new
  cookies[:game_id]    = nil
  cookies[:move_index] = nil
  @players = @context.players
  @boards  = @context.boards
end

#next_moveObject



64
65
66
67
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 64

def next_move
  @context.ai_move(params[:id])
  redirect_to :action => "show"
end

#showObject



25
26
27
28
29
30
31
32
33
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 25

def show
  @game               = @context.get_game(cookies[:game_id])
  @web_game_presenter = WebGamePresenter.for(board: @game.board, id: cookies[:game_id])
  @web_game_history   = @context.get_history(cookies[:game_id])
  @id                 = cookies[:game_id]
  @finished           = @game.board.finished?
  flash[:notice], view_file = TttGame.evaluate_game(cookies[:game_id], @context)
  render view_file
end

#update_gameObject



57
58
59
60
61
62
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 57

def update_game
  @game = @context.get_game(params[:id])
  @context.update_game(params[:id], params[:move], @game.current_player.side)
  cookies[:game_id]   = params[:id]
  redirect_to :action => "show"
end

#welcomeObject



7
8
9
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 7

def welcome
  redirect_to :action => "new"
end