Skip to content

Commit

Permalink
implementing blake pairing results, visuals looking good
Browse files Browse the repository at this point in the history
  • Loading branch information
efatsi committed Aug 3, 2012
1 parent 4f8abf3 commit 1fb7f71
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 61 deletions.
Binary file added app/assets/images/.DS_Store
Binary file not shown.
Binary file added app/assets/images/deck.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,132 @@

.previous-trick-info {
display: none;
}

/* @group hands */

.hand {
# overflow: hidden;
# padding-top: 40px;
# width: 100%;

.card {
float: left;
position: relative;
margin-right: -55px;
top: 0;
@include transition(all .25s);

&.elevated {
top: -10px;

&:hover {
left: -10px;
@include rotate(-5deg);
}

&:active {
top: -20px;
}
}
}
}

/* @group cards */

.card {
background: #fff url(../assets/deck.gif);
display: block;
height: 100px;
overflow: hidden;
text-indent: -9999px;
width: 72px;
}

@for $i from 2 through 10 {
.card-#{$i}-heart {
background-position: -72px * $i + 72px 0;
}
}

.card-J-heart {
background-position: -720px 0;
}

.card-Q-heart {
background-position: -792px 0;
}

.card-K-heart {
background-position: -864px 0;
}

.card-A-heart {
background-position: 0 0;
}

@for $i from 2 through 10 {
.card-#{$i}-diamond {
background-position: -72px * $i + 72px -100px;
}
}

.card-J-diamond {
background-position: -720px -100px;
}

.card-Q-diamond {
background-position: -792px -100px;
}

.card-K-diamond {
background-position: -864px -100px;
}

.card-A-diamond {
background-position: 0 -100px;
}

@for $i from 2 through 10 {
.card-#{$i}-club {
background-position: -72px * $i + 72px -200px;
}
}

.card-J-club {
background-position: -720px -200px;
}

.card-Q-club {
background-position: -792px -200px;
}

.card-K-club {
background-position: -864px -200px;
}

.card-A-club {
background-position: 0 -200px;
}

@for $i from 2 through 10 {
.card-#{$i}-spade {
background-position: -72px * $i + 72px -300px;
}
}

.card-J-spade {
background-position: -720px -300px;
}

.card-Q-spade {
background-position: -792px -300px;
}

.card-K-spade {
background-position: -864px -300px;
}

.card-A-spade {
background-position: 0 -300px;
}
4 changes: 2 additions & 2 deletions app/controllers/card_passings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def create
reload_partial
end

def flip_passing_status
def toggle_passing_status
player_choice = PlayerCard.find(params[:card].to_i)
player_choice.flip_passing_status
player_choice.toggle_passing_status
reload_partial("shared/my_hand")
end

Expand Down
9 changes: 2 additions & 7 deletions app/models/player_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ def hand_order
suit_weight*13 + value_weight
end

def flip_passing_status
def toggle_passing_status
new_value = (card_passing_set_id.present? ? nil : player.card_passing_set.id)
self.update_attributes(:card_passing_set_id => new_value)
end

def is_a_scoring_card?
is_a_heart || is_queen_of_spades
end

def image_path
suit_letter = suit[0]
"/assets/cards/#{suit_letter}#{value}.gif"
end


private
def is_not_chosen?
card_passing_set_id.nil?
Expand Down
88 changes: 47 additions & 41 deletions app/views/shared/_my_hand.html.erb
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
<% if current_user.is_playing_in?(@game) %>
<% if current_player.try(:hand).present? %>
<br />

<div id="pass-button">
<%= progress_button("passing_set_ready", "remove-pass-button", "button btn-info") if player_can_pass? %>
</div>
<ul>
<% current_player.try(:hand).each do |card| %>
<li>
<% if @game.passing_time? %>
<% if card.has_been_chosen? %>
<% if !player_has_passed? %>
<form action="<%= game_flip_passing_status_path(@game, :card => card) %>" class="reload-hand" data-remote="true" method="post">
<%= image_submit_tag(card.image_path, :class => "elevated-card") %>
</form>
<% else %>
<%= image_tag(card.image_path, :class => "elevated-card") %>
<% end %>
<% elsif card.can_be_chosen? %>
<form action="<%= game_flip_passing_status_path(@game, :card => card) %>" class="reload-hand" data-remote="true" method="post">
<%= image_submit_tag(card.image_path) %>
</form>
<% else %>
<%= image_tag(card.image_path) %>
<% end %>
<% elsif @game.is_current_players_turn?(current_player) %>
<% if card.is_valid?(@game.get_lead_suit, @game.trick_is_first?) %>
<form action="<%= game_play_one_card_path(@game, :card => card) %>" class="immediate-reload" data-remote="true" method="post">
<%= image_submit_tag(card.image_path, :class => "elevated-card") %>
<!-- <input class="card-button" type="image" src="<%= card.image_path %>"> -->
</form>
<% else %>
<%= image_tag(card.image_path) %>
<% end %>
<% else %>
<%= image_tag(card.image_path) %>
<div id="pass-button">
<%= progress_button("passing_set_ready", "remove-pass-button", "button btn-info") if player_can_pass? %>
</div>
<div class="hand">
<ul>
<% current_player.try(:hand).each do |card| %>
<li>
<% if @game.passing_time? %>
<% if card.has_been_chosen? %>
<% if !player_has_passed? %>
<div class="card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% else %>
<div class="card card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% end %>
</li>
<% elsif card.can_be_chosen? %>
<div class="card elevated card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% else %>
<div class="card card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% end %>
<% elsif @game.is_current_players_turn?(current_player) %>
<% if card.is_valid?(@game.get_lead_suit, @game.trick_is_first?) %>
<div class="card elevated card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% else %>
<div class="card card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% end %>
<% else %>
<div class="card card-<%= card.value + "-" + card.suit %>">
<%= card.value + " of " + card.suit %>
</div>
<% end %>
</ul>

</li>
<% end %>
</ul>
</div>
</div>
<% else %>
<br />
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
post 'new_trick' => 'tricks#create'
post 'play_one_card' => 'played_cards#create'
post 'pass_cards' => 'card_passings#create'
post 'flip_passing_status' => 'card_passings#flip_passing_status'
post 'toggle_passing_status' => 'card_passings#toggle_passing_status'
post 'passing_set_ready' => 'card_passings#passing_set_ready'
end

Expand Down
13 changes: 3 additions & 10 deletions spec/models/player_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,16 @@

describe "#methods" do

context "image_path" do

it "should work for a generic card (they're all generic ahaha)" do
@p_c1.image_path.should == "/assets/cards/c2.gif"
end
end

context "flip_passing_status" do
context "toggle_passing_status" do

it "should work if original status is nil" do
id_will_be = @p_c1.player.card_passing_set.id
expect{ @p_c1.flip_passing_status }.to change{ @p_c1.card_passing_set_id }.from(nil).to(id_will_be)
expect{ @p_c1.toggle_passing_status }.to change{ @p_c1.card_passing_set_id }.from(nil).to(id_will_be)
end

it "should work if original status is not nil" do
@p_c1.update_attributes(:card_passing_set_id => 39)
expect{ @p_c1.flip_passing_status }.to change{ @p_c1.card_passing_set_id }.from(39).to(nil)
expect{ @p_c1.toggle_passing_status }.to change{ @p_c1.card_passing_set_id }.from(39).to(nil)
end
end

Expand Down

0 comments on commit 1fb7f71

Please sign in to comment.