Class: Game2048Controller
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Game2048Controller
- Defined in:
- app/controllers/game_2048_controller.rb
Instance Method Summary collapse
Instance Method Details
#make_move ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/game_2048_controller.rb', line 11 def make_move direction = params[:direction] moved = false board = session[:game_2048_board].map(&:dup) case direction when "up" moved = move_up when "down" moved = move_down when "left" moved = move_left when "right" moved = move_right end if moved add_new_tile update_score(session[:game_2048_score]) check_game_over end respond_to do |format| format.json { render json: { board: session[:game_2048_board], score: session[:game_2048_score], game_over: session[:game_2048_over], won: session[:game_2048_won] } } end end |
#new_game ⇒ Object
45 46 47 48 |
# File 'app/controllers/game_2048_controller.rb', line 45 def new_game initialize_game redirect_to game_2048_play_path end |
#play ⇒ Object
2 3 4 5 |
# File 'app/controllers/game_2048_controller.rb', line 2 def play @aesthetic = Aesthetic.find_by(game_id: Game.find_by(name: "2048").id) initialize_game if session[:game_2048_board].nil? end |
#show ⇒ Object
7 8 9 |
# File 'app/controllers/game_2048_controller.rb', line 7 def show redirect_to game_2048_play_path end |