diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2da309f..13f8352 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -46,9 +46,12 @@ class GamesController < ApplicationController # Instantiate the play @play = @game.controlling_player.plays.new @play.game_id = @game.id + + # TODO Bug next player fails if inventory is empty + @next_player_id = @game.next_player_id @play.player_cards << @cards_to_play if @play.save - @game.set_controlling_player 'next' + @game.controlling_player_id = @next_player_id @game.save else # TODO: Does anything need to happen here? diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb index 1267a53..764cac2 100644 --- a/app/controllers/tables_controller.rb +++ b/app/controllers/tables_controller.rb @@ -32,6 +32,7 @@ class TablesController < ApplicationController def show # TODO move this to the game.rb model # Clear play to beat if play returns to owner + # TODO refactor to ensure play for 2nd and 3rd place if @game.play_to_beat.try(:player).try(:id) == @game.controlling_player_id @game.play_to_beat_id = nil @game.save diff --git a/app/models/game.rb b/app/models/game.rb index e0bb233..196e681 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -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) + # TODO Fix bug @controlling_player_index ||= 0 player_ids_by_seat_order[(@controlling_player_index + 1) % self.player_ids_by_seat_order.length] end