Fix turn order

This commit is contained in:
Jesse C. Fisher 2019-10-26 06:17:55 -07:00
parent 919e5379f7
commit d671517b47
3 changed files with 6 additions and 1 deletions

View File

@ -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?

View File

@ -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

View File

@ -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