From e3bcd8705078f73796b3a083f0f883af9bea8957 Mon Sep 17 00:00:00 2001 From: Dave Cheung Date: Tue, 5 Nov 2013 00:30:41 -0700 Subject: [PATCH] Added winning points game over logic. Added winnings points game over logic of 3 points. Remaining issue of how to deal same definition cards to each player instead of cycling through new cards each time. --- assets/www/crayplay.js | 44 ++++++++++++++++++++++++------- assets/www/crayplaydb.js | 45 +++++++++++++++++++++++++++++--- assets/www/crayplaystructures.js | 34 +++++++++++++++++++++--- assets/www/game_over.html | 2 +- 4 files changed, 108 insertions(+), 17 deletions(-) diff --git a/assets/www/crayplay.js b/assets/www/crayplay.js index 1275fc4..19af101 100644 --- a/assets/www/crayplay.js +++ b/assets/www/crayplay.js @@ -37,6 +37,11 @@ var nextPlayerName = ""; var currentStage = 0; var maxRounds = 7; + +var maxPoints = 3; +var currentPoints = 0; +var currentMax = 0; + var listCreated = true; var numPlayers = 3; var currentAllPlayers = new PlayerCollection(); @@ -69,6 +74,7 @@ function onStartClick(){ function onRankAnswersSubmit(){ var answers = $(".sub_answers"); + ids = []; for(var x=0; x currentMax) + { + currentMax = currentPoints; + } for (var i = 0; i < ids.length; i++) { thePlayerAnswers.setRank(parseInt(ids[i]), i+1); // Trim the excess whitespace. @@ -340,7 +351,7 @@ function moveToNextPage(){ case 10: currentRound++; // if we are on the last stage we will increment the round and set the stage back to 1 - if (currentRound > maxRounds) + if (currentPoints >= maxPoints) { currentStage = 10; $.mobile.changePage("game_over.html", {transition: "none"} ); @@ -349,8 +360,11 @@ function moveToNextPage(){ { currentStage = 0; //todo remove this - just for testing. - currentReader = currentAllPlayers.grabSecondPlayer().p_id; - currentReaderName = currentAllPlayers.grabSecondPlayer().p_name; + var tempRoundPlayer = RoundPlayerCollection(); + tempRoundPlayer = currentAllPlayers.grabNextPlayer(); + currentReader = tempRoundPlayer.p_id; + currentReaderName = tempRoundPlayer.p_name; + currentRoundPlayers.empty(); currentRoundPlayers.resetPlayers(currentReader); currentPlayer = currentRoundPlayers.grabNextPlayer().p_id; currentPlayerName = currentRoundPlayers.grabNextPlayer().p_name; @@ -359,7 +373,7 @@ function moveToNextPage(){ } break; case 11: - $.mobile.changePage("index.html#mainmenu", {transition: "none"} ); + $.mobile.changePage("index.html", {transition: "none"} ); break; default: } @@ -388,14 +402,12 @@ function appendToRoundOne(){ } function appendCurrentVariables(){ - //$("#currentvariables").append("
  • "); $("#currentvariables").append("
  • "); // HEADER switch(currentStage) { case 1: - //$("#currentvariables").append("
  • "); $("#currentvariables").append("
  • "); $("#currentvariables").append("
    "); $("#currentvariables").append("
    "); @@ -404,7 +416,6 @@ function appendCurrentVariables(){ $("#currentvariables").append("
  • \"" + currentQText + "\"
  • "); $("#currentvariables").append("
    "); $("#currentvariables").append("
    "); - //$("#currentvariables").append("
  • "); break; case 2: $("#currentvariables").append("
  • "); @@ -439,8 +450,11 @@ function appendCurrentVariables(){ $("#currentvariables").append("
  • "); $("#currentvariables").append("
  • \"" + currentQText + "\"
  • "); break; + case 10: + $("#currentvariables").append("
  • "); + $("#currentvariables").append("
  • "); + break; default: - //$("#currentvariables").append("
  • "); $("#currentvariables").append("
  • "); break; } @@ -551,6 +565,14 @@ function appendCurrentVariables(){ case 8: $("#currentvariables").append("Winner for the round is:"); $("#currentvariables").append("
  • "+currentWinnerName+"
  • "); + if(currentPoints == 1) + { + $("#currentvariables").append("
  • You have "+currentPoints+" point
  • "); + } + else + { + $("#currentvariables").append("
  • You have "+currentPoints+" points
  • "); + } $("#currentvariables").append(""); $("#currentvariables").listview("refresh"); $("#content").append(""); @@ -574,6 +596,10 @@ function appendCurrentVariables(){ $("#content").append(""); $("#content").trigger("create"); break; + case 10: + $("#currentvariables").listview("refresh"); + $("#content").append(""); + $("#content").trigger("create"); default: break; } diff --git a/assets/www/crayplaydb.js b/assets/www/crayplaydb.js index c238746..b73f154 100644 --- a/assets/www/crayplaydb.js +++ b/assets/www/crayplaydb.js @@ -61,6 +61,46 @@ function populateDB(tx){ tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (18, 1, "Definition 18")'); tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (19, 1, "Definition 19")'); tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (20, 1, "Definition 20")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (21, 1, "Definition 21")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (22, 1, "Definition 22")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (23, 1, "Definition 23")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (24, 1, "Definition 24")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (25, 1, "Definition 25")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (26, 1, "Definition 26")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (27, 1, "Definition 27")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (28, 1, "Definition 28")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (29, 1, "Definition 29")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (30, 1, "Definition 30")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (31, 1, "Definition 31")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (32, 1, "Definition 32")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (33, 1, "Definition 33")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (34, 1, "Definition 34")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (35, 1, "Definition 35")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (36, 1, "Definition 36")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (37, 1, "Definition 37")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (38, 1, "Definition 38")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (39, 1, "Definition 39")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (40, 1, "Definition 40")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (41, 1, "Definition 41")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (42, 1, "Definition 42")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (43, 1, "Definition 43")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (44, 1, "Definition 44")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (45, 1, "Definition 45")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (46, 1, "Definition 46")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (47, 1, "Definition 47")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (48, 1, "Definition 48")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (49, 1, "Definition 49")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (50, 1, "Definition 50")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (51, 1, "Definition 51")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (52, 1, "Definition 52")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (53, 1, "Definition 53")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (54, 1, "Definition 54")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (55, 1, "Definition 55")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (56, 1, "Definition 56")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (57, 1, "Definition 57")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (58, 1, "Definition 58")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (59, 1, "Definition 59")'); + tx.executeSql('INSERT INTO DEFINITIONS (def_id, def_type, def_text) VALUES (60, 1, "Definition 60")'); //CREATE SETUP PARAMETERS tx.executeSql('INSERT INTO SETUPPARAMS (setup_id, setup_text, setup_value) VALUES (1, "handsize", "5")'); @@ -85,7 +125,7 @@ function deletePlayersDB(errorCallBack, successCallBack){ var db = window.openDatabase("CrayPlay", "1.0", "CrayPlay DB", 1000000); db.transaction(deletePlayersDBCall, errorCallBack, successCallBack); currentAllPlayers.forEach( - function(p_id, p_name) + function(p_id, p_name, p_points) { currentAllPlayers.remove(p_id); } @@ -123,7 +163,7 @@ function getPlayersDBCall(tx){ function getDBPlayersDBSuccess(tx, results) { //alert("inside queryDBPlayersDBSuccess"); for(var i=0; i this.count) + { + tempIndex = 0; + this.index = 0; + } + for(key in this.collection) + { + nextKey = key; + if(counter == tempIndex) + break; + counter++; + } + if(this.collection[nextKey]==undefined) + return undefined; + + return this.collection[nextKey]; + } + + this.forEach=function(block) { for(key in this.collection) { if(this.collection.hasOwnProperty(key)) { - block(key, this.collection[key].p_name); + block(key, this.collection[key].p_name, this.collection[key].p_points); } } } diff --git a/assets/www/game_over.html b/assets/www/game_over.html index 90380b2..9e01265 100644 --- a/assets/www/game_over.html +++ b/assets/www/game_over.html @@ -27,7 +27,7 @@

    Game Over

    Game Over

    - +