Class: TttGamesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TttGamesController
- Defined in:
- lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb
Instance Method Summary collapse
- #create_game ⇒ Object
- #game_list ⇒ Object
- #get_game ⇒ Object
- #move_history ⇒ Object
- #new ⇒ Object
- #next_move ⇒ Object
- #show ⇒ Object
- #update_game ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#create_game ⇒ Object
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]) [:game_id] = @context.add_game(game) flash[:notice] = "Welcome to Tic Tac Toe!" redirect_to :action => "show" end |
#game_list ⇒ Object
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_game ⇒ Object
39 40 41 42 |
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 39 def get_game [:game_id] = params[:id] redirect_to :action => "show" end |
#move_history ⇒ Object
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, [: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, [:move_index]) @web_game_presenter = WebGamePresenter.for(board: @game.board, id: [:game_id]) @finished = true [:last_id] = @id flash[:notice], view_file = TttGame.evaluate_game([:game_id], @context) render view_file end |
#new ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 11 def new [:game_id] = nil [:move_index] = nil @players = @context.players @boards = @context.boards end |
#next_move ⇒ Object
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 |
#show ⇒ Object
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([:game_id]) @web_game_presenter = WebGamePresenter.for(board: @game.board, id: [:game_id]) @web_game_history = @context.get_history([:game_id]) @id = [:game_id] @finished = @game.board.finished? flash[:notice], view_file = TttGame.evaluate_game([:game_id], @context) render view_file end |
#update_game ⇒ Object
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) [:game_id] = params[:id] redirect_to :action => "show" end |
#welcome ⇒ Object
7 8 9 |
# File 'lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb', line 7 def welcome redirect_to :action => "new" end |