Skip to content

Commit

Permalink
Finished Basic Game Logic. Minor issues remain.
Browse files Browse the repository at this point in the history
Still has some minor issues to resolve.
  • Loading branch information
djcheung committed Nov 2, 2013
1 parent 26961e7 commit c32eec9
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 117 deletions.
2 changes: 1 addition & 1 deletion assets/www/assign_drink.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Assign Drink</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Assign Drink</h2>
<input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue">
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
188 changes: 128 additions & 60 deletions assets/www/crayplay.js

Large diffs are not rendered by default.

22 changes: 6 additions & 16 deletions assets/www/crayplaydb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function populateDB(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS PLAYERS (p_id INTEGER PRIMARY KEY AUTOINCREMENT, p_name TEXT)');
tx.executeSql('CREATE TABLE IF NOT EXISTS GAMELOG (g_id INTEGER PRIMARY KEY AUTOINCREMENT, p_winner INTEGER, played_date DATE)');
tx.executeSql('CREATE TABLE IF NOT EXISTS GAMETRANLOG (gt_id INTEGER PRIMARY KEY AUTOINCREMENT, g_id INTEGER, p_id INTEGER, def_id INTEGER, def_used_ind INTEGER)');
tx.executeSql('CREATE TABLE IF NOT EXISTS PLAYERANSWERS (pa_id INTEGER PRIMARY KEY AUTOINCREMENT, g_id INTEGER, p_id INTEGER, word_id, round_id INTEGER, def_id INTEGER, a_vote_count INTEGER, a_rank INTEGER)');
tx.executeSql('CREATE TABLE IF NOT EXISTS PLAYERANSWERS (pa_id INTEGER PRIMARY KEY AUTOINCREMENT, g_id INTEGER, p_id INTEGER, word_id INTEGER, round_id INTEGER, def_id INTEGER, a_vote_count INTEGER, a_rank INTEGER)');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEFINITIONS (def_id INTEGER KEY UNIQUE, def_type INTEGER, def_text TEXT)');
tx.executeSql('CREATE TABLE IF NOT EXISTS SETUPPARAMS (setup_id INTEGER KEY UNIQUE, setup_text TEXT, setup_value TEXT)');

Expand Down Expand Up @@ -61,16 +61,6 @@ 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")'); */

//CREATE SETUP PARAMETERS
tx.executeSql('INSERT INTO SETUPPARAMS (setup_id, setup_text, setup_value) VALUES (1, "handsize", "5")');
Expand Down Expand Up @@ -204,9 +194,11 @@ function addPlayerAnswerDB(errorCallBack, successCallBack){
}
function addPlayerAnswerDBCall(tx){
var setPlayerName="";
//alert(numPlayers);
var a_def_id = $("input:radio:checked").val();
var a_def_id = $('input[name="definition"]:checked').val();//$("input:radio:checked").val();
//alert(a_def_id);
//alert(currentPlayer);
tx.executeSql('INSERT INTO PLAYERANSWERS(g_id,p_id,word_id,def_id,a_vote_count,a_rank) VALUES (?,?,?,?,?,?)', [currentGameID, currentPlayer, currentQID, a_def_id, 0,0], successCB, errorCB);
thePlayerAnswers.add(a_def_id, currentQID, currentPlayer, currentRound, currentGameID, 0, 0);
}
function addPlayerAnswerDBSuccess(){
//alert('inside add player answer success db');
Expand All @@ -220,9 +212,7 @@ function getPlayerAnswerDBCall(tx){
tx.executeSql('SELECT def_id, p_id from PLAYERANSWERS WHERE g_id = ? and word_id = ? and p_id = ?', [currentPlayer, currentQID, currentGameID], getDBPlayerAnswerDBSuccess, errorCB);
}
function getDBPlayerAnswerDBSuccess(tx, results) {
//alert("inside queryDBPlayersDBSuccess");
for(var i=0; i<results.rows.length;i++){
//alert(results.rows.item(i).def_id);
//alert(results.rows.item(i).p_id);
//thePlayerAnswers.add(results.rows.item(i).p_id, currentQID, results.rows.item(i).def_id, currentGameID, currentRound, 0, 0);
}
}
64 changes: 61 additions & 3 deletions assets/www/crayplaystructures.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var PlayerCollection=function()
{
if(this.collection.hasOwnProperty(key))
{
block(key, this.collection[key]);
block(key, this.collection[key].p_name);
}
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ var WordCollection=function()
block(key, this.collection[key].word_text, this.collection[key].word_realdef, this.collection[key].used_ind);
}
}
}
}
}

var DefinitionCollection=function()
Expand Down Expand Up @@ -269,7 +269,7 @@ var DefinitionCollection=function()
{
return this.collection[key];
}

this.forEach=function(block)
{
for(key in this.collection)
Expand All @@ -280,4 +280,62 @@ var DefinitionCollection=function()
}
}
}
}

var PlayerAnswerCollection=function()
{
this.count=0;
this.collection={};

this.add=function(key, w_id, p_id, r_id, g_id, d_v_count, d_rank )
{
if(this.collection[key]!=undefined)
return undefined;

this.collection[key] = {
def_id: key,
word_id: w_id,
player_id: p_id,
round_id: r_id,
game_id: g_id,
def_vote_count: d_v_count,
def_rank: d_rank
};
return ++this.count;
}

this.remove=function(key)
{
if(this.collection[key]==undefined)
return undefined;
delete this.collection[key];
return --this.count;
}

this.item=function(key)
{
return this.collection[key];
}

this.setRank=function(key, rank)
{
if(this.collection[key]!=undefined)
return undefined;

this.collection[key].def_rank = rank;

return this.collection[key].def_rank;
}

this.forEach=function(block)
{
for(key in this.collection)
{
if(this.collection.hasOwnProperty(key))
{
block(key, this.collection[key].word_id, this.collection[key].player_id, this.collection[key].round_id, this.collection[key].def_vote_count,
this.collection[key].def_rank);
}
}
}
}
12 changes: 12 additions & 0 deletions assets/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>CrayPlay</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="crayplaystructures.js"></script>
<script type="text/javascript" charset="utf-8" src="crayplay.js"></script>
<script type="text/javascript" charset="utf-8" src="crayplaydb.js"></script>
<script>
$('#rank_answers').bind('pageinit', function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
<!-- Refresh list to the end of sort to have a correct display -->
$( "#sortable" ).bind( "sortstop", function(event, ui) {
$('#sortable').listview('refresh');
});
});
</script>
</head>

<body onload="init()">
Expand Down
91 changes: 60 additions & 31 deletions assets/www/rank_answers.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,79 @@
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Rank Answers</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

</head>
<body>

<div data-role="page" id="rank_answers">
<script>
$('#rank_answers').bind('pageshow', function(){
//alert("inside select_definition pageshow");
resetPageVariables(5);
grabCurrentVariables();

$('ul')
.addClass('ui-corner-top')
.removeClass('ui-corner-all')
.sortable({
'containment': 'parent',
'opacity': 0.6,
update: function(event, ui) {
alert("dropped");
}
/*
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
<!-- Refresh list to the end of sort to have a correct display -->
$( "#sortable" ).bind( "sortstop", function(event, ui) {
$('#sortable').listview('refresh');
});

*/

sort_ul = $('#sortable');
itemsCount = $('#sortable li').length;

function updateIndexes(){
$('li input').each(function(i){
$(this).val(i+1);
});
}

updateIndexes();

$('#sortable li').removeClass('ui-corner-bottom');

sort_ul.sortable({
items: "li:not(.ui-li-divider)"
});
</script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script>
$(document).bind('pageinit', function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
<!-- Refresh list to the end of sort to have a correct display -->
$( "#sortable" ).bind( "sortstop", function(event, ui) {
$('#sortable').listview('refresh');

sort_ul.disableSelection();

sort_ul.bind( "sortstop", function(event, ui) {
updateIndexes();
});

$('li input').keyup(function(event) {
if(event.keyCode == '13'){
event.preventDefault();

order = parseInt($(this).val());

li = $(this).parent();
if(order>=1 && order <= itemsCount){

li.effect('drop', function(){
li.detach();

if(order == itemsCount)
sort_ul.append(li);
else
li.insertBefore($('#sortable li:eq('+(order-1)+')'));

updateIndexes();
li.effect('slide');
});
}else{
li.effect('highlight');
}
}
});
});

</script>
<div data-role="header" data-theme="e">
<a data-role="button" data-rel="back" data-mini="true">Back</a></h3>
Expand All @@ -50,15 +85,9 @@ <h1>Rank Answers</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Rank Answers</h2>
<ul data-role="listview" data-inset="true" data-theme="d" id="sortable">
<li data-role="list-divider">List</li>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
<!-- <input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue"> -->
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>

<ul data-role="listview" data-divider-theme="b" data-inset="true" id="sortable"></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
2 changes: 1 addition & 1 deletion assets/www/read_answers.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Read Answers</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Read Answers</h2>
<input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue">
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
2 changes: 1 addition & 1 deletion assets/www/read_new_word.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Read New Word</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Read New Word</h2>
<!-- / button -- <input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue"> -->
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
2 changes: 1 addition & 1 deletion assets/www/read_real_def.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Read Real Definition</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Read Real Definition</h2>
<input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue">
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
2 changes: 1 addition & 1 deletion assets/www/read_winner.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Read Winner</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Read Winner</h2>
<input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue">
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
</div><!-- /content -->

<div data-role="footer" class="ui-bar" data-theme="e">
Expand Down
1 change: 1 addition & 0 deletions assets/www/select_definition.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>Select Definition</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Select Definition</h2>
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
<!-- /content -- <input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue"> -->
</div><!-- /content -->

Expand Down
3 changes: 2 additions & 1 deletion assets/www/verify_def.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>

Expand All @@ -27,6 +27,7 @@ <h1>Verify Definition</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Verify Definition</h2>
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
<!-- <input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="Player - Click To Continue"> -->
</div><!-- /content -->

Expand Down
3 changes: 2 additions & 1 deletion assets/www/verify_def_last_player.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>

Expand All @@ -27,6 +27,7 @@ <h1>Verify Definition Last Player</h1>

<div data-role="content" id="content" data-theme="e">
<h2>Verify Definition Last Player</h2>
<ul id='currentvariables' data-role='listview' data-inset='true'></ul>
<!-- <input type="button" id="clicktoContinue" onClick="moveToNextPage()" value="All Answers Received - Click To Continue"> -->
</div><!-- /content -->

Expand Down

0 comments on commit c32eec9

Please sign in to comment.