Skip to content

Commit

Permalink
New choice joker is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslav Georgiev committed Apr 15, 2012
1 parent 8eed7b6 commit 75d0d3e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 62 deletions.
16 changes: 8 additions & 8 deletions index.php
Expand Up @@ -20,7 +20,7 @@
$("#lotteryCards").children().each(function(index, item) { $("#lotteryCards").children().each(function(index, item) {
var card = new Lottery.FlipCard({ var card = new Lottery.FlipCard({
flipboxId : item.id, flipboxId : item.id,
backContent : '<img src="images/back.png" />', backContent : '<img src="images/front.png" />',
faceContent : '<img src="images/front.png" />' faceContent : '<img src="images/front.png" />'
}); });
Lottery.FlipCardsTable[item.id] = card; Lottery.FlipCardsTable[item.id] = card;
Expand Down Expand Up @@ -57,25 +57,25 @@
<h1>Team Score : <span id="teamScore">0</span></h1> <h1>Team Score : <span id="teamScore">0</span></h1>
<div id="lotteryCards"> <div id="lotteryCards">
<div class="flipbox" id="flipbox"> <div class="flipbox" id="flipbox">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox2"> <div class="flipbox" id="flipbox2">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox3"> <div class="flipbox" id="flipbox3">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox4"> <div class="flipbox" id="flipbox4">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox5"> <div class="flipbox" id="flipbox5">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox6"> <div class="flipbox" id="flipbox6">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
<div class="flipbox" id="flipbox7"> <div class="flipbox" id="flipbox7">
<img src="images/back.png" /> <img src="images/front.png" />
</div> </div>
</div> </div>
<br /> <br />
Expand Down
37 changes: 4 additions & 33 deletions js/flipcard.js
Expand Up @@ -24,43 +24,14 @@ Lottery.FlipCard = function FlipCard(config) {


this.uiFlip = function(content) { this.uiFlip = function(content) {
this.isFront = !this.isFront; this.isFront = !this.isFront;
if( typeof (content) !== "undefined") {
this.isFront = true;
}
$("#{0}".format(this.getId())).flip({ $("#{0}".format(this.getId())).flip({
direction : 'tb', direction : 'tb',
content : this.getContent(), content : typeof (content) !== "undefined" ? content : this.getContent(),
speed : 500, speed : 500,
color : "#FFFFFF" color : "#FFFFFF"
}); });
} }

this.flip = function(giveReward/*bool*/, flipContent) {
var isFront = this.isFront;
if(isFront && giveReward == true) {
var reward = Lottery.play(function() {
return true;
// for testing right now
});
}
var content = "";
var cardId = this.config["flipboxId"];

// determine the content
if( typeof (flipContent) !== "undefined") {
content = "<img src={0} />".format(flipContent);
} else {
content = (isFront && giveReward) ? "<img src={0} />".format(reward.image) : this.getContent();
}
this.isFront = !this.isFront;

$("#{0}".format(cardId)).flip({
direction : 'tb',
content : content/*turns this.isFront*/,
speed : 500,
color : "#FFFFFF",
onEnd : function() {
if( typeof (reward) !== "undefined") {
Lottery.turnAllCards([cardId], reward)
}
}
});
};
} }
14 changes: 7 additions & 7 deletions js/gameconstants.js
Expand Up @@ -9,7 +9,7 @@ Lottery.gameConstants.rewards = {};
Lottery.gameConstants.rewards.GAIN_15_POINTS = { Lottery.gameConstants.rewards.GAIN_15_POINTS = {
name : "GAIN_15_POINTS", name : "GAIN_15_POINTS",
description : "Gain 15 points", description : "Gain 15 points",
image : "images/team_points.png", image : "<img src='images/team_points.png' />",
chance : 20, // in percent chance : 20, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 15 * modifier; gameConfig["teamScore"] += 15 * modifier;
Expand All @@ -20,7 +20,7 @@ Lottery.gameConstants.rewards.GAIN_15_POINTS = {
Lottery.gameConstants.rewards.GAIN_25_POINTS = { Lottery.gameConstants.rewards.GAIN_25_POINTS = {
name : "GAIN_25_POINTS", name : "GAIN_25_POINTS",
description : "Gain 25 points", description : "Gain 25 points",
image : "images/book.png", image : "<img src='images/book.png' />",
chance : 17.5, // in percent chance : 17.5, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 25 * modifier; gameConfig["teamScore"] += 25 * modifier;
Expand All @@ -31,7 +31,7 @@ Lottery.gameConstants.rewards.GAIN_25_POINTS = {
Lottery.gameConstants.rewards.GAIN_40_POINTS = { Lottery.gameConstants.rewards.GAIN_40_POINTS = {
name : "GAIN_40_POINTS", name : "GAIN_40_POINTS",
description : "Gain 40 points", description : "Gain 40 points",
image : "images/help_card.png", image : "<img src='images/help_card.png' />",
chance : 10, // in percent chance : 10, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 40 * modifier; gameConfig["teamScore"] += 40 * modifier;
Expand All @@ -42,7 +42,7 @@ Lottery.gameConstants.rewards.GAIN_40_POINTS = {
Lottery.gameConstants.rewards.GAIN_2_JOKERS = { Lottery.gameConstants.rewards.GAIN_2_JOKERS = {
name : "GAIN_2_JOKERS", name : "GAIN_2_JOKERS",
description : "Jokers count + 2", description : "Jokers count + 2",
image : "images/new_skill.png", image : "<img src='images/new_skill.png' />",
chance : 15, // in percent chance : 15, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["jokersCount"] += 2 * modifier; gameConfig["jokersCount"] += 2 * modifier;
Expand All @@ -53,7 +53,7 @@ Lottery.gameConstants.rewards.GAIN_2_JOKERS = {
Lottery.gameConstants.rewards.LOSE_15_POINTS = { Lottery.gameConstants.rewards.LOSE_15_POINTS = {
name : "LOSE_15_POINTS", name : "LOSE_15_POINTS",
description : "Lose 15 points.", description : "Lose 15 points.",
image : "images/skill_points.png", image : "<img src='images/skill_points.png' />",
chance : 17.5, // in percent chance : 17.5, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["teamScore"] -= 15 * modifier; gameConfig["teamScore"] -= 15 * modifier;
Expand All @@ -63,7 +63,7 @@ Lottery.gameConstants.rewards.LOSE_15_POINTS = {


Lottery.gameConstants.rewards.LOSE_30_POINTS = { Lottery.gameConstants.rewards.LOSE_30_POINTS = {
name : "LOSE_30_POINTS", name : "LOSE_30_POINTS",
image : "images/quote.png", image : "<img src='images/quote.png' />",
description : "Lose 30 points", description : "Lose 30 points",
chance : 12.5, // in percent chance : 12.5, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
Expand All @@ -75,7 +75,7 @@ Lottery.gameConstants.rewards.LOSE_30_POINTS = {
Lottery.gameConstants.rewards.BOMB = { Lottery.gameConstants.rewards.BOMB = {
name : "BOMB", name : "BOMB",
description : "Lose 75% of total score", description : "Lose 75% of total score",
image : "images/modifier_x2.png", image : "<img src='images/modifier_x2.png' />",
chance : 7.5, // in percent chance : 7.5, // in percent
effect : function(gameConfig, modifier) { effect : function(gameConfig, modifier) {
gameConfig["teamScore"] -= 0.75 * gameConfig["teamScore"] * modifier; gameConfig["teamScore"] -= 0.75 * gameConfig["teamScore"] * modifier;
Expand Down
55 changes: 41 additions & 14 deletions js/lottery.logic.js
Expand Up @@ -39,24 +39,34 @@ Lottery.UI = {
attachCardHandlers : function() { attachCardHandlers : function() {
$(".flipbox").bind("click", {}, function() { $(".flipbox").bind("click", {}, function() {
var reward = Lottery.play(); var reward = Lottery.play();
Lottery.gameConfig["rewards"] = [reward]; console.log("Card is picked up : ", reward.description);
Lottery.gameConfig["selectedCards"] = [$(this).attr("id")]; Lottery.gameConfig["rewards"].push(reward);
Lottery.FlipCardsTable[$(this).attr("id")].uiFlip(); Lottery.gameConfig["selectedCards"].push($(this).attr("id"));
Lottery.endOfRound(); Lottery.FlipCardsTable[$(this).attr("id")].uiFlip(reward.image);
if(Lottery.gameConfig["newChoice"] === false) {
Lottery.endOfRound();
}
}); });
}, },
deattachCardHandlers : function() { deattachCardHandlers : function() {
$(".flipbox").unbind("click"); $(".flipbox").unbind("click");
}, },
attachJokersHandlers : function() { attachJokersHandlers : function() {
$(".joker").bind("click", {}, function() { $(".joker").bind("click", {}, function() {
Lottery.gameConfig["jokersCount"]--;
Lottery.UI.updateJokersAmount();
var id = $(this).attr("id"); var id = $(this).attr("id");
if(id === "double") { if(id === "double") {
Lottery.gameConfig["modifier"] = 2; Lottery.gameConfig["modifier"] = 2;
Lottery.endOfRound(false /*no jokers time*/); Lottery.endOfRound(false /*no jokers time*/);
} else if(id === "addChoice") {


} else if(id === "newChoice") {
Lottery.gameConfig["newChoice"] = true;
Lottery.UI.turnAllCards();
Lottery.UI.attachCardHandlers();
Lottery.clearRewards();
} }
console.log($(this).val());
}); });
}, },
deattachJokersHandlers : function() { deattachJokersHandlers : function() {
Expand All @@ -72,8 +82,13 @@ Lottery.applyEffect = function() {
console.log(item.description); console.log(item.description);
Lottery.UI.updateUI(); Lottery.UI.updateUI();
}); });
} Lottery.clearRewards();
};


Lottery.clearRewards = function() {
Lottery.gameConfig["rewards"] = [];
Lottery.gameConfig["selectedCards"] = [];
};
Lottery.setup = function() { Lottery.setup = function() {
var initialConfig = { var initialConfig = {
"teamScore" : 10, "teamScore" : 10,
Expand All @@ -84,7 +99,10 @@ Lottery.setup = function() {
"jokersTimeout" : 15, // seconds "jokersTimeout" : 15, // seconds
"roundTimer" : null, "roundTimer" : null,
"jokersTimer" : null, "jokersTimer" : null,
"modifier" : 1 "modifier" : 1,
"rewards" : [],
"selectedCards" : [],
"newChoice" : false
}; };
Lottery.gameConfig = initialConfig; Lottery.gameConfig = initialConfig;


Expand Down Expand Up @@ -121,11 +139,16 @@ Lottery.endOfRound = function(playJokers) {
}; };


Lottery.playJoker = function() { Lottery.playJoker = function() {
Lottery.gameConfig["jokersTimer"].reset(); if(Lottery.gameConfig["jokersCount"] > 0) {
$(".joker").removeAttr("disabled"); Lottery.gameConfig["jokersTimer"].reset();
Lottery.gameConfig["jokersTimer"].start(); $(".joker").removeAttr("disabled");
Lottery.UI.attachJokersHandlers(); Lottery.gameConfig["jokersTimer"].start();
Lottery.gameConfig["jokersClearCode"] = setTimeout(Lottery.changeRound, Lottery.gameConfig["jokersTimeout"] * 1000); Lottery.UI.attachJokersHandlers();
Lottery.gameConfig["jokersClearCode"] = setTimeout(Lottery.changeRound, Lottery.gameConfig["jokersTimeout"] * 1000);

} else {
Lottery.changeRound();
}
}; };


Lottery.changeRound = function() { Lottery.changeRound = function() {
Expand All @@ -134,6 +157,10 @@ Lottery.changeRound = function() {
Lottery.gameConfig["currentRound"]++; Lottery.gameConfig["currentRound"]++;
Lottery.gameConfig["jokersTimer"].reset(); Lottery.gameConfig["jokersTimer"].reset();


// reset joker modifiers
Lottery.gameConfig["newChoice"] = false;
Lottery.gameConfig["modifier"] = 1;

if(Lottery.gameConfig["currentRound"] > Lottery.gameConfig["totalRounds"]) { if(Lottery.gameConfig["currentRound"] > Lottery.gameConfig["totalRounds"]) {
alert("The game has ended!"); alert("The game has ended!");
clearInterval(Lottery.gameConfig["clearCode"]); clearInterval(Lottery.gameConfig["clearCode"]);
Expand All @@ -145,12 +172,12 @@ Lottery.changeRound = function() {
Lottery.UI.disableJokerButtons(); Lottery.UI.disableJokerButtons();
Lottery.UI.updateRounds(); Lottery.UI.updateRounds();


Lottery.gameConfig["clearCode"] = setInterval(Lottery.endOfRound, Lottery.gameConfig["roundTime"] * 1000); //Lottery.gameConfig["clearCode"] = setInterval(Lottery.endOfRound, Lottery.gameConfig["roundTime"] * 1000);
Lottery.gameConfig["roundTimer"].start(); Lottery.gameConfig["roundTimer"].start();


Lottery.UI.attachCardHandlers(); Lottery.UI.attachCardHandlers();
console.log("New round has started"); console.log("New round has started");
} };


Lottery.start = function() { Lottery.start = function() {
Lottery.UI.attachCardHandlers(); Lottery.UI.attachCardHandlers();
Expand Down

0 comments on commit 75d0d3e

Please sign in to comment.