Imorove turn logic regress new end of game bugs

This commit is contained in:
Jesse C. Fisher 2019-10-26 05:21:20 -07:00
parent 8970379e57
commit b665999104
3 changed files with 15 additions and 11 deletions

View File

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

View File

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

View File

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