Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jQuery to make jeopardy game interaction work! #3

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0aef8f3
moved code from my cloned repo to my forked repo
oliverswitzer Jan 31, 2014
bd3cbb2
remove score1, score2, score3 vars in beginning
oliverswitzer Jan 31, 2014
0c8bb6a
added alert to make sure user changes points before moving on to the …
oliverswitzer Jan 31, 2014
65f25b4
card.rb => memory_card.rb
oliverswitzer Feb 1, 2014
42a28f3
merge fix in jeopardy2 and card.rb
oliverswitzer Feb 1, 2014
77a6c9f
create basic outline of cards/colors. JS added to resize card heights…
oliverswitzer Feb 1, 2014
dcf209d
wrote code to differentiate between cases in which user trys to match…
oliverswitzer Feb 2, 2014
12cd099
create four states based on the variable chances. Chances = 0, user m…
oliverswitzer Feb 3, 2014
5b591aa
game now keeps track of score. Create addPoints func in JS that adds …
oliverswitzer Feb 4, 2014
5a77794
each card now says how many cards it should be matched with
oliverswitzer Feb 4, 2014
16345a1
fix bug where score was eval to NaN
oliverswitzer Feb 4, 2014
a980c81
bug fix so you cant click in the same card or played cards and rack u…
oliverswitzer Feb 4, 2014
507cdad
git merge changes to score tracker logic and bug fixes for double cli…
oliverswitzer Feb 4, 2014
23fc4b9
add timer which will countdown from 30 seconds and make all the cards…
oliverswitzer Feb 6, 2014
338e939
when timer is up, cards removed and game over is displayed in header …
oliverswitzer Feb 6, 2014
d0ca980
change timer to 30 sec
oliverswitzer Feb 6, 2014
5f93054
change description of how game works
oliverswitzer Feb 6, 2014
f063dd0
bundle + updated readme
oliverswitzer Jul 22, 2014
f97a9fa
remove debugger gem
oliverswitzer Jul 22, 2014
802eee7
fix bug where root path was returning error because couldnt find righ…
oliverswitzer Jul 22, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#gambit + trebek
#gambit + trebek + Oliver's JS magic = mempoints

A game I created to test your memory under pressure. Can you rack up 2000 points before the time limit is up?



## gambit is a server side application that allows you to design cards and build decks and serve them to a client
Expand Down
12 changes: 9 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ class Gambit < Sinatra::Application
set :public_folder, 'public'
end

get "/oliversmemorygame.css" do
scss :oliversmemorygame
end

get "/styles.css" do
scss :trebek
end

get "/" do
haml :index
deck = Deck.new("data/olivers_memory_game.yml")
@cards = deck.cards
haml :olivers_memory_game
end

get "/games/new/" do
Expand Down Expand Up @@ -62,13 +68,13 @@ def partial(template,locals=nil)
template = template.is_a?(Array) ? :"_#{template.first.class.to_s.downcase}" : :"_#{template.class.to_s.downcase}"
end
if locals.is_a?(Hash)
haml template, {}, locals
haml template, {}, locals
elsif locals
locals=[locals] unless locals.respond_to?(:inject)
locals.inject([]) do |output,element|
output << haml(template,{template.to_s.delete("_").to_sym => element})
end.join("\n")
else
else
haml template
end
end
Expand Down
40 changes: 40 additions & 0 deletions data/olivers_memory_game.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- points: 200
siblings: two
- points: 200
siblings: two
- points: 200
siblings: two
- points: 200
siblings: two
- points: 200
siblings: two
- points: 200
siblings: two
- points: 300
siblings: three
- points: 300
siblings: three
- points: 300
siblings: three
- points: 300
siblings: three
- points: 300
siblings: three
- points: 300
siblings: three
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
- points: 400
siblings: four
8 changes: 8 additions & 0 deletions lib/memory_card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Card
attr_reader :points, :siblings

def initialize(data)
@points, @siblings = data["points"], data["siblings"];
end

end
24 changes: 24 additions & 0 deletions public/jquery.shuffle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function($){

$.fn.shuffle = function() {

var allElems = this.get(),
getRandom = function(max) {
return Math.floor(Math.random() * max);
},
shuffled = $.map(allElems, function(){
var random = getRandom(allElems.length),
randEl = $(allElems[random]).clone(true)[0];
allElems.splice(random, 1);
return randEl;
});

this.each(function(i){
$(this).replaceWith($(shuffled[i]));
});

return $(shuffled);

};

})(jQuery);
76 changes: 76 additions & 0 deletions public/oliver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// nikliver.js


$(document).ready(function() {

var $cards = $(".card").not(".cat-card");
var $buttons = $("button");

$cards.on("click", function(){
var $this = $(this);
var $value = $this.find(":first-child");
var $question = $this.find(":nth-child(2)");
var $answer = $this.find(":nth-child(3)");
var $notChosen = $cards.not(this);

//if player hasn't chosen this card already and the selected card isn't disabled
if (!$this.hasClass("played") && !$this.hasClass("disabled")) {

if(isVisible($value)) { // if point value is visible
$this.addClass("chosen"); //card is chosen
$notChosen.addClass("disabled"); //disabled all other cards
$value.fadeOut();
$question.fadeIn();
enableButtons($value.text());
} else if(isVisible($question)) { //if question is visible
$question.fadeOut();
$answer.fadeIn();
} else { // if answer is visible
if(clicked == false) {
alert("Please change the score of whoever guessed correctly!");
return false
}
$this.removeClass("chosen").addClass("played");;
$notChosen.removeClass("disabled");
$answer.toggle();
$buttons.addClass("disabled");
}

}
});


function isVisible(cardObject) {
return cardObject.is(":visible");
}

function enableButtons(cardValue) {
var cardValInt = Number(cardValue);
clicked = false;
var $buttons = $(".score button"); // must get all buttons again because this function doesn't have access to the scope in which I first defined $buttons
$buttons.removeClass("disabled");
$buttons.on("click", function() {
clicked = true;
var $this = $(this);
var $scoreContainer = $this.parent().children().filter("h2");
var score = Number($scoreContainer.text());
if(!$this.hasClass("disabled")) { // if this button isn't disabled
if($this.hasClass("up")) { //if user is clicking on an up button
score += cardValInt; //increment the score by the value of the card
$scoreContainer.text(String(score)); //set the container text to the score
$buttons.addClass("disabled")
} else { //if button clicked is down
score -= cardValue; // subtract card value from score
$scoreContainer.text(String(score)); //set the container text to the score
$buttons.addClass("disabled");
}
}

});
return clicked
}


});


Loading