diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 41989e2f..de4c0e47 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -56,22 +56,8 @@ class GamesController < ApplicationController flash[:notice] = "Game already started..." return redirect_to(@game) end - - @game.status = 'Game Started' if @game.startable? - @game.save - - # Create a deck - d = Deck.new - # Shuffle the deck - d.cards.shuffle! - # Deal the cards - @game.players.each do |player| - 13.times do - card = d.cards.shift - player.player_cards.new(card.instance_values) - end - player.save - end + + @game.start redirect_to(@game) end diff --git a/app/models/game.rb b/app/models/game.rb index f80397cc..baef028b 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -8,8 +8,23 @@ class Game < ActiveRecord::Base def start # Save the game to the database return false unless startable? - save + # Start the game TODO + self.status = 'Game Started' if startable? + + # Create a deck + d = Deck.new + # Shuffle the deck + d.cards.shuffle! + # Deal the cards + players.each do |player| + 13.times do + card = d.cards.shift + player.player_cards.new(card.instance_values) + end + player.save + end + save end def validate_startable @@ -20,8 +35,14 @@ class Game < ActiveRecord::Base def startable? @player_count = players.size - bool = @player_count.between?(2, 4) - #bool = status != 'Game Started' + tests = [ + @player_count.between?(2, 4), + status != 'Game Started' + ] + tests.each do |test| + if test == false then return false end + end + return true end def add_player_from_user(user)