From 4c2fbf5843a9a5bb90e30084b524c731b334131c Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Sat, 26 Oct 2019 06:17:55 -0700 Subject: [PATCH] Fix turn order --- app/controllers/games_controller.rb | 5 ++++- app/controllers/tables_controller.rb | 1 + app/models/game.rb | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2da309f4..13f8352a 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 1267a532..764cac26 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 e0bb2334..196e6814 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