[go: up one dir, main page]

Menu

[0511a8]: / common.js  Maximize  Restore  History

Download this file

224 lines (176 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//***********************
// Define some constants.
//***********************
var dlg = {
'Window' : '#dialog',
'Header' : '#dlgtitle',
'Body' : '#dlgbody',
'Buttons' : '#dlgokcancel'
};
// Global variables.
var teamCount=0; // Number of teams playing.
//******************************************************
// This function is called first to get number of teams.
//******************************************************
function initialize()
{
// Hide elements that need to be hidden.
closeWindow();
closeDialog();
document.title = Title;
var userInput = prompt('How many teams are playing?', '2');
if (userInput != '' && userInput != null)
{
teamCount = parseInt(userInput);
}
// Once we know how many teams there are, we can create the score table
$("#score").html( makeScoreTable());
// And then the controls for adjusting scores after answers.
$("#controls").html(makeControls());
}
function getRandom(min,max)
{
return (Math.round(Math.random()*(max-min)))+min;
}
/*******************************************************************
* Title: Title in the dialog title portion.
* Body: The content that goes in the dialog's body portion.
* OnFinish: The function that is called after the dialog closes.
* -- default ""
* ok, cancel: The text in the buttons for ok and cancel.
* -- defaults: "Ok", "Cancel"
******************************************************************/
function showDialog(title, body, onfinish, oktext, canceltext)
{
// If variabls not passed in use a default.
onfinish=argv(onfinish,"");
oktext=argv(oktext, "Ok");
canceltext=argv(canceltext, "Cancel");
$(dlg.Header).html(title);
$(dlg.Body).html(body);
var ok = "<input type='button' value='" + oktext + "' > + onfinish + "' />";
var cancel = "<input type='button' value='" + canceltext + "' />";
$(dlg.Buttons).html(ok + cancel);
$(dlg.Window).show();
}
function closeDialog(onfinish)
{
$(dlg.Window).hide();
}
/*******************************************************************
* Process:
* Get wager amounts from each team
* Show question, teams must write their answer down
* Read answers / Reveal answer
* Show options for correct or incorrect to change totals.
******************************************************************/
function getFinalWagers()
{
var title = "Final Category: " + FinalCategory;
var body = "<table id='finalwager'>";
body += "<tr><th>Team</th><th>Wager</th><th>Current $</th></tr>";
for (var i=1; i<=teamCount; i++)
{
var money = parseInt($("#team" + i).html());
body += "<tr>";
body += "<td align=center> Team " + i + "</th>";
body += "<td> <input type='text' name='finalwageramt" + i + "' value='0' /> </td>";
body += "<td>" + money + "</td>";
body += "</tr>";
}
body += "</table>";
// Show the get wagers dialog, when finished call revealFinalAnswer().
showDialog(title, body, "revealFinalAnswer()");
}
function getScore(team)
{
var id = "#team" + team;
var val = parseInt($(id).html());
return val;
}
// team is a number identifying the team.
function incScore(team)
{
// Get the team's current winnings.
var id = "#team" + team;
var val = parseInt($(id).html());
// Get the team's current wager.
var amount = wagerAmount.getTeamWager(team-1);
// Adjust accordingly.
$(id).html(val + amount);
if (autoCloseOnScore()) closeWindow();
}
function decScore(team)
{
var id = "#team" + team;
var val = parseInt($(id).html());
var amount = wagerAmount.getTeamWager(team-1);
$(id).html(val - amount);
if (autoCloseOnScore()) closeWindow();
}
//**********************
// Countdown timer code.
//**********************
var timerVariable=null;
function startTimer(numSeconds)
{
// Use default if nothing passed in.
numSeconds=argv(numSeconds, TimePerQuestion);
if (timerVariable != null) stopTimer();
// Reset countdown timer panel.
$(qa.Timer).css("color", "white");
$(qa.Timer).html(numSeconds);
// Reset the timer to go off every second.
timerVariable = setInterval("decTimer()", 1000);
}
function stopTimer()
{
if (timerVariable != null)
{
clearInterval(timerVariable);
timerVariable = null;
}
}
// This decrements the timer 1 second at a time.
function decTimer()
{
var val = parseInt($(qa.Timer).html());
val--;
$(qa.Timer).html(val);
// Change the color to red for the last 10 seconds.
if (val < 10) $(qa.Timer).css("color", "red");
// Stop the countdown at 0.
if (val == 0) stopTimer();
}
//*******************************************************************
// Set an argument to its value, if it is undefined, use the default.
// Allows you to have defaults arguments with functions such as:
// function x(a,b,c) { a=argv(a,1); b=argv(b,2); c=argv(c,3); }
//*******************************************************************
function argv(arg, val) { return typeof arg !== 'undefined' ? arg : val; }
function WebSocketTest()
{
var socket = io.connect('http://localhost:8080');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
}
//*************************************************************************
// While this appears to be a function, it is actually a javascript object.
// value, answer and question are it's member variables.
//*************************************************************************
function Question(v, q, a)
{
// Set instance variables for this object.
this.value = v;
this.answer = a;
this.question = q;
// Add methods to this object.
this.getValue = getValue;
this.getQuestion = getQuestion;
this.getAnswer = getAnswer;
}
function getValue() { return this.value; }
function getQuestion() { return this.question; }
function getAnswer() { return this.answer; }