Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New choice joker is now working

  • Loading branch information...
commit 75d0d3ef5e79d47b68ab1e52f75602f514ef2ea6 1 parent 8eed7b6
@RadoRado RadoRado authored
View
16 index.php
@@ -20,7 +20,7 @@
$("#lotteryCards").children().each(function(index, item) {
var card = new Lottery.FlipCard({
flipboxId : item.id,
- backContent : '<img src="images/back.png" />',
+ backContent : '<img src="images/front.png" />',
faceContent : '<img src="images/front.png" />'
});
Lottery.FlipCardsTable[item.id] = card;
@@ -57,25 +57,25 @@
<h1>Team Score : <span id="teamScore">0</span></h1>
<div id="lotteryCards">
<div class="flipbox" id="flipbox">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox2">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox3">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox4">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox5">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox6">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
<div class="flipbox" id="flipbox7">
- <img src="images/back.png" />
+ <img src="images/front.png" />
</div>
</div>
<br />
View
37 js/flipcard.js
@@ -24,43 +24,14 @@ Lottery.FlipCard = function FlipCard(config) {
this.uiFlip = function(content) {
this.isFront = !this.isFront;
+ if( typeof (content) !== "undefined") {
+ this.isFront = true;
+ }
$("#{0}".format(this.getId())).flip({
direction : 'tb',
- content : this.getContent(),
+ content : typeof (content) !== "undefined" ? content : this.getContent(),
speed : 500,
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)
- }
- }
- });
- };
}
View
14 js/gameconstants.js
@@ -9,7 +9,7 @@ Lottery.gameConstants.rewards = {};
Lottery.gameConstants.rewards.GAIN_15_POINTS = {
name : "GAIN_15_POINTS",
description : "Gain 15 points",
- image : "images/team_points.png",
+ image : "<img src='images/team_points.png' />",
chance : 20, // in percent
effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 15 * modifier;
@@ -20,7 +20,7 @@ Lottery.gameConstants.rewards.GAIN_15_POINTS = {
Lottery.gameConstants.rewards.GAIN_25_POINTS = {
name : "GAIN_25_POINTS",
description : "Gain 25 points",
- image : "images/book.png",
+ image : "<img src='images/book.png' />",
chance : 17.5, // in percent
effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 25 * modifier;
@@ -31,7 +31,7 @@ Lottery.gameConstants.rewards.GAIN_25_POINTS = {
Lottery.gameConstants.rewards.GAIN_40_POINTS = {
name : "GAIN_40_POINTS",
description : "Gain 40 points",
- image : "images/help_card.png",
+ image : "<img src='images/help_card.png' />",
chance : 10, // in percent
effect : function(gameConfig, modifier) {
gameConfig["teamScore"] += 40 * modifier;
@@ -42,7 +42,7 @@ Lottery.gameConstants.rewards.GAIN_40_POINTS = {
Lottery.gameConstants.rewards.GAIN_2_JOKERS = {
name : "GAIN_2_JOKERS",
description : "Jokers count + 2",
- image : "images/new_skill.png",
+ image : "<img src='images/new_skill.png' />",
chance : 15, // in percent
effect : function(gameConfig, modifier) {
gameConfig["jokersCount"] += 2 * modifier;
@@ -53,7 +53,7 @@ Lottery.gameConstants.rewards.GAIN_2_JOKERS = {
Lottery.gameConstants.rewards.LOSE_15_POINTS = {
name : "LOSE_15_POINTS",
description : "Lose 15 points.",
- image : "images/skill_points.png",
+ image : "<img src='images/skill_points.png' />",
chance : 17.5, // in percent
effect : function(gameConfig, modifier) {
gameConfig["teamScore"] -= 15 * modifier;
@@ -63,7 +63,7 @@ Lottery.gameConstants.rewards.LOSE_15_POINTS = {
Lottery.gameConstants.rewards.LOSE_30_POINTS = {
name : "LOSE_30_POINTS",
- image : "images/quote.png",
+ image : "<img src='images/quote.png' />",
description : "Lose 30 points",
chance : 12.5, // in percent
effect : function(gameConfig, modifier) {
@@ -75,7 +75,7 @@ Lottery.gameConstants.rewards.LOSE_30_POINTS = {
Lottery.gameConstants.rewards.BOMB = {
name : "BOMB",
description : "Lose 75% of total score",
- image : "images/modifier_x2.png",
+ image : "<img src='images/modifier_x2.png' />",
chance : 7.5, // in percent
effect : function(gameConfig, modifier) {
gameConfig["teamScore"] -= 0.75 * gameConfig["teamScore"] * modifier;
View
55 js/lottery.logic.js
@@ -39,10 +39,13 @@ Lottery.UI = {
attachCardHandlers : function() {
$(".flipbox").bind("click", {}, function() {
var reward = Lottery.play();
- Lottery.gameConfig["rewards"] = [reward];
- Lottery.gameConfig["selectedCards"] = [$(this).attr("id")];
- Lottery.FlipCardsTable[$(this).attr("id")].uiFlip();
- Lottery.endOfRound();
+ console.log("Card is picked up : ", reward.description);
+ Lottery.gameConfig["rewards"].push(reward);
+ Lottery.gameConfig["selectedCards"].push($(this).attr("id"));
+ Lottery.FlipCardsTable[$(this).attr("id")].uiFlip(reward.image);
+ if(Lottery.gameConfig["newChoice"] === false) {
+ Lottery.endOfRound();
+ }
});
},
deattachCardHandlers : function() {
@@ -50,13 +53,20 @@ Lottery.UI = {
},
attachJokersHandlers : function() {
$(".joker").bind("click", {}, function() {
+ Lottery.gameConfig["jokersCount"]--;
+ Lottery.UI.updateJokersAmount();
var id = $(this).attr("id");
if(id === "double") {
Lottery.gameConfig["modifier"] = 2;
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() {
@@ -72,8 +82,13 @@ Lottery.applyEffect = function() {
console.log(item.description);
Lottery.UI.updateUI();
});
-}
+ Lottery.clearRewards();
+};
+Lottery.clearRewards = function() {
+ Lottery.gameConfig["rewards"] = [];
+ Lottery.gameConfig["selectedCards"] = [];
+};
Lottery.setup = function() {
var initialConfig = {
"teamScore" : 10,
@@ -84,7 +99,10 @@ Lottery.setup = function() {
"jokersTimeout" : 15, // seconds
"roundTimer" : null,
"jokersTimer" : null,
- "modifier" : 1
+ "modifier" : 1,
+ "rewards" : [],
+ "selectedCards" : [],
+ "newChoice" : false
};
Lottery.gameConfig = initialConfig;
@@ -121,11 +139,16 @@ Lottery.endOfRound = function(playJokers) {
};
Lottery.playJoker = function() {
- Lottery.gameConfig["jokersTimer"].reset();
- $(".joker").removeAttr("disabled");
- Lottery.gameConfig["jokersTimer"].start();
- Lottery.UI.attachJokersHandlers();
- Lottery.gameConfig["jokersClearCode"] = setTimeout(Lottery.changeRound, Lottery.gameConfig["jokersTimeout"] * 1000);
+ if(Lottery.gameConfig["jokersCount"] > 0) {
+ Lottery.gameConfig["jokersTimer"].reset();
+ $(".joker").removeAttr("disabled");
+ Lottery.gameConfig["jokersTimer"].start();
+ Lottery.UI.attachJokersHandlers();
+ Lottery.gameConfig["jokersClearCode"] = setTimeout(Lottery.changeRound, Lottery.gameConfig["jokersTimeout"] * 1000);
+
+ } else {
+ Lottery.changeRound();
+ }
};
Lottery.changeRound = function() {
@@ -134,6 +157,10 @@ Lottery.changeRound = function() {
Lottery.gameConfig["currentRound"]++;
Lottery.gameConfig["jokersTimer"].reset();
+ // reset joker modifiers
+ Lottery.gameConfig["newChoice"] = false;
+ Lottery.gameConfig["modifier"] = 1;
+
if(Lottery.gameConfig["currentRound"] > Lottery.gameConfig["totalRounds"]) {
alert("The game has ended!");
clearInterval(Lottery.gameConfig["clearCode"]);
@@ -145,12 +172,12 @@ Lottery.changeRound = function() {
Lottery.UI.disableJokerButtons();
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.UI.attachCardHandlers();
console.log("New round has started");
-}
+};
Lottery.start = function() {
Lottery.UI.attachCardHandlers();

0 comments on commit 75d0d3e

Please sign in to comment.
Something went wrong with that request. Please try again.