diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b315ad3..2da309f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -36,15 +36,12 @@ class GamesController < ApplicationController # Player action: pass # TODO: wtf do we need game params for? And why nest hand_type in it? # if params[:game] - if params[:hand_type] == 'Pass' - @game.set_controlling_player 'next' - flash[:notice] = 'Successfully passed.' - @game.save - end - # end - + if params[:hand_type] == 'Pass' + @game.set_controlling_player 'next' + flash[:notice] = 'Successfully passed.' + @game.save # Player action: play_hand - if params[:player_card_ids] + elsif params[:player_card_ids] @cards_to_play = @game.controlling_player.try(:player_cards).order(:value).find(params[:player_card_ids]) # Instantiate the play @play = @game.controlling_player.plays.new diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb index cff7b2c..1267a53 100644 --- a/app/controllers/tables_controller.rb +++ b/app/controllers/tables_controller.rb @@ -30,6 +30,12 @@ class TablesController < ApplicationController # GET /tables/1 # GET /tables/1.json def show + # TODO move this to the game.rb model + # Clear play to beat if play returns to owner + if @game.play_to_beat.try(:player).try(:id) == @game.controlling_player_id + @game.play_to_beat_id = nil + @game.save + end end # GET /tables/new diff --git a/app/models/game.rb b/app/models/game.rb index 9899257..823ccfe 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -126,9 +126,9 @@ class Game < ActiveRecord::Base end # Clear play to beat if play returns to owner - if self.play_to_beat.try(:player).try(:id) == self.controlling_player_id - self.play_to_beat_id = nil - end + # if self.play_to_beat.try(:player).try(:id) == self.controlling_player_id + # self.play_to_beat_id = nil + # end end def joinable? user @@ -141,6 +141,7 @@ class Game < ActiveRecord::Base def next_player_id @controlling_player_index = self.player_ids_by_seat_order.index(controlling_player_id) + @controlling_player_index ||= 0 player_ids_by_seat_order[(@controlling_player_index + 1) % self.player_ids_by_seat_order.length] end