another stash
This commit is contained in:
parent
327f7d8f1b
commit
4db7bb0eb9
@ -6,7 +6,7 @@ class Deck
|
|||||||
self.cards = []
|
self.cards = []
|
||||||
Card::RANKS.each do |rank|
|
Card::RANKS.each do |rank|
|
||||||
Card::SUITS.each do |suit|
|
Card::SUITS.each do |suit|
|
||||||
self.cards << Card.new(value, rank.to_i, suit)
|
self.cards << Card.new(value, rank, suit)
|
||||||
value += 1
|
value += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,6 +25,11 @@ class Game < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
player.save
|
player.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set status to first turn
|
||||||
|
# Player with the lowest card
|
||||||
|
self.status = "First Play at: " + self.lowest_card.player.user.email
|
||||||
|
self.control_player_id = self.lowest_card.player.id
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,17 +37,23 @@ class Game < ActiveRecord::Base
|
|||||||
@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
|
||||||
errors[:players] = 'Must be less than 5 players.' if @player_count > 4
|
errors[:players] = 'Must be less than 5 players.' if @player_count > 4
|
||||||
errors[:status] = 'Game already started...' if self.status == 'Game Started'
|
errors[:status] = 'Game already started...' if self.status != nil
|
||||||
raise StandardError, errors if errors
|
errors[:player_cards] = 'Cards already dealt...' unless player_cards.empty?
|
||||||
|
raise StandardError, errors if errors.count > 0
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def startable?
|
def startable?
|
||||||
@player_count = players.count
|
begin
|
||||||
tests = [
|
self.validate_startable
|
||||||
@player_count.between?(2, 4),
|
rescue
|
||||||
status != 'Game Started'
|
end
|
||||||
]
|
#@player_count = players.count
|
||||||
return tests.all?
|
#tests = [
|
||||||
|
#@player_count.between?(2, 4),
|
||||||
|
#status != 'Game Started'
|
||||||
|
#]
|
||||||
|
#return tests.all?
|
||||||
end
|
end
|
||||||
|
|
||||||
def lowest_card
|
def lowest_card
|
||||||
@ -65,4 +76,15 @@ class Game < ActiveRecord::Base
|
|||||||
def full?
|
def full?
|
||||||
players.count >= 4
|
players.count >= 4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The player whose turn it is
|
||||||
|
def control_player
|
||||||
|
self.players.find(self.control_player_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# The user whose turn it is
|
||||||
|
def control_user
|
||||||
|
self.players.find(self.control_player_id).user
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,17 +12,27 @@
|
|||||||
- if @game.startable? && @game.already_has?(current_user)
|
- if @game.startable? && @game.already_has?(current_user)
|
||||||
= link_to 'Start', game_start_path(@game)
|
= link_to 'Start', game_start_path(@game)
|
||||||
|
|
||||||
= link_to 'Start', game_start_path(@game)
|
= link_to 'Debug Start', game_start_path(@game)
|
||||||
|
|
||||||
%p
|
%p
|
||||||
%b Players:
|
%b Players:
|
||||||
%ol
|
%ol
|
||||||
- @game.players.each do |player|
|
- @game.players.each do |player|
|
||||||
%li= player
|
%li
|
||||||
|
%strong= "My Turn " if @game.control_player == player
|
||||||
|
= player.user.email
|
||||||
|
= "Me" if player.user == current_user
|
||||||
- unless player.player_cards.empty?
|
- unless player.player_cards.empty?
|
||||||
%ul.cards
|
%ul.cards
|
||||||
- player.player_cards.each do |card|
|
- player.player_cards.order(:value).each do |card|
|
||||||
%li= [card.rank, card.suit].join(' ')
|
%li
|
||||||
|
%label
|
||||||
|
= check_box_tag 'player_card_ids[]', card.id
|
||||||
|
= [card.rank, card.suit].join(' ')
|
||||||
|
|
||||||
|
%p
|
||||||
|
- if @game.control_user == current_user
|
||||||
|
= link_to 'Play Hand', '#'
|
||||||
|
|
||||||
= link_to 'Edit', edit_game_path(@game)
|
= link_to 'Edit', edit_game_path(@game)
|
||||||
\|
|
\|
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
class AddControlPlayerIdToGame < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :games, :control_player_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -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: 20150409115031) do
|
ActiveRecord::Schema.define(version: 20150417112103) 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"
|
||||||
@ -21,6 +21,7 @@ ActiveRecord::Schema.define(version: 20150409115031) do
|
|||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "status"
|
t.string "status"
|
||||||
|
t.integer "control_player_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "player_cards", force: true do |t|
|
create_table "player_cards", force: true do |t|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user