Stashing played hand
This commit is contained in:
parent
b6a570edf8
commit
fc5ef4ce32
@ -1,5 +1,5 @@
|
|||||||
class GamesController < ApplicationController
|
class GamesController < ApplicationController
|
||||||
before_action :set_game, only: [:show, :edit, :update, :destroy]
|
before_action :set_game, only: [:show, :edit, :update, :destroy, :play_hand]
|
||||||
|
|
||||||
respond_to :html
|
respond_to :html
|
||||||
|
|
||||||
@ -20,6 +20,14 @@ class GamesController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def play_hand
|
||||||
|
# TODO validate player's turn, current_user == @game.current_player.user
|
||||||
|
@hand = params[:player_card_ids]
|
||||||
|
# TODO add current_hand logic
|
||||||
|
# @hand > @game.hand_to_beat
|
||||||
|
redirect_to @game
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@game = Game.new(title: game_params[:title])
|
@game = Game.new(title: game_params[:title])
|
||||||
if game_params[:player_ids]
|
if game_params[:player_ids]
|
||||||
|
|||||||
@ -33,6 +33,10 @@ class Game < ActiveRecord::Base
|
|||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_player
|
||||||
|
self.players.find_by(id: control_player_id)
|
||||||
|
end
|
||||||
|
|
||||||
def validate_startable
|
def validate_startable
|
||||||
@player_count = players.count
|
@player_count = players.count
|
||||||
errors[:players] = 'Must be at least 2 players.' if @player_count < 2
|
errors[:players] = 'Must be at least 2 players.' if @player_count < 2
|
||||||
|
|||||||
@ -47,13 +47,13 @@
|
|||||||
%h1 Hand to beat
|
%h1 Hand to beat
|
||||||
- else
|
- else
|
||||||
%h1 Open table
|
%h1 Open table
|
||||||
|
%h2= "Played #{@hand}"
|
||||||
|
|
||||||
.controls
|
.controls
|
||||||
- if @game.control_user == current_user
|
- if @game.control_user == current_user
|
||||||
// Show the Play Hand form
|
// Play hand form
|
||||||
-#= form_for @game, :url => {:action => "Bro"} do |f|
|
= form_for @game, :url => play_hand_game_path(@game) do |f|
|
||||||
= form_for @game do |f|
|
|
||||||
// Provide id of current game
|
// Provide id of current game
|
||||||
= f.hidden_field :id
|
-#= f.hidden_field :id
|
||||||
= f.submit "Play Hand"
|
= f.submit "Play Hand"
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,9 @@ Rails.application.routes.draw do
|
|||||||
resources :games do
|
resources :games do
|
||||||
get 'start'
|
get 'start'
|
||||||
get 'join'
|
get 'join'
|
||||||
|
member do
|
||||||
|
patch 'play_hand'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mount Upmin::Engine => '/admin'
|
mount Upmin::Engine => '/admin'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user