stash play hand logic
This commit is contained in:
parent
fc5ef4ce32
commit
a83c0679d7
@ -22,7 +22,18 @@ class GamesController < ApplicationController
|
|||||||
|
|
||||||
def play_hand
|
def play_hand
|
||||||
# TODO validate player's turn, current_user == @game.current_player.user
|
# TODO validate player's turn, current_user == @game.current_player.user
|
||||||
@hand = params[:player_card_ids]
|
@cards_to_play = @game.current_player.player_cards.find(params[:player_card_ids])
|
||||||
|
|
||||||
|
# Instantiate the play
|
||||||
|
@play = @game.current_player.plays.new
|
||||||
|
@play.game_id = @game.id
|
||||||
|
@play.save
|
||||||
|
|
||||||
|
@cards_to_play.each do |card|
|
||||||
|
card.play_id = @play.id
|
||||||
|
card.save
|
||||||
|
end
|
||||||
|
|
||||||
# TODO add current_hand logic
|
# TODO add current_hand logic
|
||||||
# @hand > @game.hand_to_beat
|
# @hand > @game.hand_to_beat
|
||||||
redirect_to @game
|
redirect_to @game
|
||||||
|
|||||||
@ -3,6 +3,7 @@ class Game < ActiveRecord::Base
|
|||||||
has_many :players, dependent: :destroy
|
has_many :players, dependent: :destroy
|
||||||
has_many :users, through: :players
|
has_many :users, through: :players
|
||||||
has_many :player_cards, through: :players
|
has_many :player_cards, through: :players
|
||||||
|
has_many :plays, through: :players
|
||||||
accepts_nested_attributes_for :players
|
accepts_nested_attributes_for :players
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ class Player < ActiveRecord::Base
|
|||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_many :player_cards
|
has_many :player_cards
|
||||||
|
has_many :plays
|
||||||
|
|
||||||
validates_presence_of :user_id
|
validates_presence_of :user_id
|
||||||
validates_presence_of :game_id
|
validates_presence_of :game_id
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
class PlayerCard < ActiveRecord::Base
|
class PlayerCard < ActiveRecord::Base
|
||||||
belongs_to :player
|
belongs_to :player
|
||||||
|
belongs_to :play
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
[rank, suit].join ' '
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -47,7 +47,10 @@
|
|||||||
%h1 Hand to beat
|
%h1 Hand to beat
|
||||||
- else
|
- else
|
||||||
%h1 Open table
|
%h1 Open table
|
||||||
%h2= "Played #{@hand}"
|
%h2
|
||||||
|
Played
|
||||||
|
- @game.plays.last.player_cards.each do |card|
|
||||||
|
= card.to_s
|
||||||
|
|
||||||
.controls
|
.controls
|
||||||
- if @game.control_user == current_user
|
- if @game.control_user == current_user
|
||||||
|
|||||||
13
db/schema.rb
13
db/schema.rb
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150417112103) do
|
ActiveRecord::Schema.define(version: 20150503133556) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -32,6 +32,7 @@ ActiveRecord::Schema.define(version: 20150417112103) do
|
|||||||
t.integer "value"
|
t.integer "value"
|
||||||
t.string "rank"
|
t.string "rank"
|
||||||
t.string "suit"
|
t.string "suit"
|
||||||
|
t.integer "play_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "player_cards", ["card_id"], name: "index_player_cards_on_card_id", using: :btree
|
add_index "player_cards", ["card_id"], name: "index_player_cards_on_card_id", using: :btree
|
||||||
@ -47,6 +48,16 @@ ActiveRecord::Schema.define(version: 20150417112103) do
|
|||||||
add_index "players", ["game_id"], name: "index_players_on_game_id", using: :btree
|
add_index "players", ["game_id"], name: "index_players_on_game_id", using: :btree
|
||||||
add_index "players", ["user_id"], name: "index_players_on_user_id", using: :btree
|
add_index "players", ["user_id"], name: "index_players_on_user_id", using: :btree
|
||||||
|
|
||||||
|
create_table "plays", force: true do |t|
|
||||||
|
t.integer "game_id"
|
||||||
|
t.integer "player_id"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "plays", ["game_id"], name: "index_plays_on_game_id", using: :btree
|
||||||
|
add_index "plays", ["player_id"], name: "index_plays_on_player_id", using: :btree
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: true do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: ""
|
t.string "encrypted_password", default: ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user