Skip to content

Commit 92bf457

Browse files
committed
Removed some unnecessary comments, added a few, reorganized methods to a more logical order, and other small things - Issue #20
1 parent 9996f12 commit 92bf457

9 files changed

+112
-132
lines changed

public_html/framework/CommunicationManager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CommunicationManager.post = function(requestUrl, requestObject, callback) {
3030
/*
3131
If you are not logged into the school wifi, the AJAX request will succeed,
3232
but of course you get garbage data (login html) and the parser throws an
33-
error. Catch this error if that occurs, and mark it as a 407 (TODO?)
33+
error. Catch this error if that occurs, and mark it as a 407
3434
Error 407 = Proxy Authentication Required
3535
*/
3636
try {

public_html/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ <h1 class = 'mainMenuTitle'>Select a Topic!</h1>
205205
<!-- Dynamically Added -->
206206
</div>
207207
<div id = 'highScores'>
208-
<!-- Dynamically add high scores here -->
209208
<div id = 'names'>
210209
<!--Dyanically add names -->
211210
</div>

public_html/src/css/GameScreen.css

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* Main Game UI */
2+
13
#gameUI {
24
margin: 0px;
35
text-align: center;
@@ -62,9 +64,7 @@
6264
float: right;
6365
}
6466

65-
/*
66-
Loading
67-
*/
67+
/* Loading UI */
6868

6969
#loadingUI {
7070
position: absolute;
@@ -86,19 +86,7 @@
8686
padding-left: 150px;
8787
}
8888

89-
/*
90-
completed
91-
*/
92-
93-
#gameCompletedUI {
94-
position: absolute;
95-
font-size: 36px;
96-
width: 530px;
97-
}
98-
99-
.button.incorrect {
100-
background-color: red !important;
101-
}
89+
/* Animation for score flash-in-out */
10290

10391
@-moz-keyframes flashInOut {
10492
0% { opacity: 0; }
@@ -125,4 +113,16 @@
125113
-webkit-animation-duration: 800ms;
126114
-moz-animation-duration: 800ms;
127115
animation-duration: 800ms;
116+
}
117+
118+
/* Game Completed UI */
119+
120+
#gameCompletedUI {
121+
position: absolute;
122+
font-size: 36px;
123+
width: 530px;
124+
}
125+
126+
.button.incorrect {
127+
background-color: red !important;
128128
}

public_html/src/css/HighScoreScreen.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* TODO - Remove? */
2+
13
#highScoreUI {
24
position: absolute;
35
min-width: 800px;

public_html/src/css/MoleculeFlashcards.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* Classes */
1+
/* Main Components */
22

33
body {
44
margin: 0;
55
padding: 0;
66
background-color: #EBFBFF;
77
font-family: Tahoma, Geneva, sans-serif;
8-
/*user-select: none;*/ /* Note: If this ever gets spec, you can uncomment this */
8+
/* user-select: none;*/ /* Note: If this ever gets spec, you can uncomment this */
99
-webkit-user-select: none;
1010
-moz-user-select: none;
1111
-ms-user-select: none;
@@ -45,7 +45,7 @@ div.flashcardsGame {
4545
float: right;
4646
}
4747

48-
/* Components */
48+
/* Component Classes */
4949

5050
div.button {
5151
text-align: center;

public_html/src/js/GameScreen.js

+71-77
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@
1313

1414
this.defaultHTML = $('#gameButtons').html();
1515

16-
//variables redefined when the game starts
1716
this.loadingState = undefined;
1817
this.questionList = undefined;
1918
this.gameData = undefined;
2019
this.currentQuestion = undefined;
2120
this.currentAnswer = undefined;
2221
this.questionIterator = undefined;
2322

24-
//add light to the scene
2523
var pointLight = new THREE.PointLight(0xFFFFFF);
2624
pointLight.position.set(0, 0, 130);
2725
this.scene.add(pointLight);
2826
};
2927

30-
//constants
3128
var BUTTON_HTML = '<div id="$refId" class="button" data-logic="$id">$text</div>';
3229
var QUESTION_MOLECULE = 0;
3330
var QUESTION_TEXT = 1;
@@ -40,7 +37,6 @@
4037
GameScreen.prototype.constructor = GameScreen;
4138

4239
GameScreen.prototype.onUpdate = function(delta) {
43-
//update the this.timer
4440
if(this.getSecondsLeft() === 0 && this.currentQuestion !== undefined) {
4541
this.endGame( );
4642
}
@@ -52,7 +48,6 @@
5248
$('#time').text(Timer.getDigitalRep(this.getSecondsLeft( )));
5349
$('#score').text(this.scoreManager.score);
5450

55-
//update the molecule
5651
if(MouseManager.leftButton.isPressed && this.currentQuestion !== undefined) {
5752
this.currentQuestion[QUESTION_MOLECULE].rotation.z -=
5853
(MouseManager.currentX - MouseManager.leftButton.pressedX) / 1000;
@@ -86,7 +81,6 @@
8681

8782
GameScreen.prototype.onResume = function( ) {
8883
function receiveQuestionList(data) {
89-
/* Receives list of questions */
9084
this.gameData = data;
9185
this.loadingState = -1;
9286
$('#loadingMessage').text('Loading');
@@ -110,6 +104,11 @@
110104
FCCommunicationManager.loadFlashcardGame(UserData.auth, UserData.gameID, receiveQuestionList.bind(this));
111105
};
112106

107+
GameScreen.prototype.getSecondsLeft = function() {
108+
var time = this.gameLength - this.timer.getElapsedSec();
109+
return (time > 0) ? time : 0;
110+
};
111+
113112
GameScreen.prototype.startGame = function( ) {
114113
$('#beginButton').removeClass('in');
115114
$('#loadingUI').removeClass('in active');
@@ -121,74 +120,6 @@
121120
this.nextQuestion( );
122121
};
123122

124-
GameScreen.prototype.endGame = function( ) {
125-
function allowExit(response) {
126-
$('#finalScore').text('Final Score: ' + response.final_score);
127-
$('#rank').text('Rank: #' + response.rank);
128-
$('#gameCompletedUI').addClass('in active');
129-
}
130-
disableButtons( );
131-
this.scene.remove(this.currentQuestion[ QUESTION_MOLECULE ]);
132-
this.currentQuestion = undefined;
133-
this.timer.stop( );
134-
$('#scoreChange')
135-
.stop(true, true)
136-
.animate({
137-
opacity: 0
138-
},
139-
300);
140-
FCCommunicationManager.endFlashcardGame(UserData.auth,
141-
this.gameData.game_session_id,
142-
this.timer.getElapsedMs(),
143-
allowExit.bind(this));
144-
};
145-
146-
GameScreen.prototype.nextQuestion = function( ) {
147-
function insertInfo(replacements, templateString, selector) {
148-
var result = templateString;
149-
for(var key in replacements) {
150-
result = result.replace(key, replacements[key]);
151-
}
152-
153-
$(selector).append(result);
154-
}
155-
156-
function setQuestionText(questionText) {
157-
if(questionText) {
158-
$('#questionPanel').text(questionText);
159-
$('#questionPanel').addClass('in');
160-
} else {
161-
$('#questionPanel').empty();
162-
$('#questionPanel').removeClass('in');
163-
}
164-
}
165-
166-
function setButtons(answers) {
167-
$('#gameButtons').empty();
168-
answers.forEach(function(answer) {
169-
insertInfo({
170-
'$refId': answer.id,
171-
'$id': answer.id,
172-
'$text': answer.text
173-
},
174-
BUTTON_HTML, '#gameButtons');
175-
});
176-
}
177-
178-
this.userAnswers = new Map( );
179-
if(this.questionIterator.hasNext( )) {
180-
if(this.questionIterator.index !== -1) {
181-
this.scene.remove(this.currentQuestion[ QUESTION_MOLECULE ]);
182-
}
183-
this.currentQuestion = this.questionIterator.next( );
184-
this.scene.add(this.currentQuestion[ QUESTION_MOLECULE ]);
185-
setQuestionText(this.currentQuestion[ QUESTION_TEXT ]);
186-
setButtons(this.currentQuestion[ QUESTION_ANSWERS ]);
187-
} else {
188-
this.endGame( );
189-
}
190-
};
191-
192123
GameScreen.prototype.createPDB = function(data) {
193124
/* Pulls in PDB's for each question and builds them */
194125
this.loadingState++;
@@ -247,9 +178,50 @@
247178
}
248179
};
249180

250-
GameScreen.prototype.getSecondsLeft = function() {
251-
var time = this.gameLength - this.timer.getElapsedSec();
252-
return (time > 0) ? time : 0;
181+
GameScreen.prototype.nextQuestion = function( ) {
182+
function insertInfo(replacements, templateString, selector) {
183+
var result = templateString;
184+
for(var key in replacements) {
185+
result = result.replace(key, replacements[key]);
186+
}
187+
188+
$(selector).append(result);
189+
}
190+
191+
function setQuestionText(questionText) {
192+
if(questionText) {
193+
$('#questionPanel').text(questionText);
194+
$('#questionPanel').addClass('in');
195+
} else {
196+
$('#questionPanel').empty();
197+
$('#questionPanel').removeClass('in');
198+
}
199+
}
200+
201+
function setButtons(answers) {
202+
$('#gameButtons').empty();
203+
answers.forEach(function(answer) {
204+
insertInfo({
205+
'$refId': answer.id,
206+
'$id': answer.id,
207+
'$text': answer.text
208+
},
209+
BUTTON_HTML, '#gameButtons');
210+
});
211+
}
212+
213+
this.userAnswers = new Map( );
214+
if(this.questionIterator.hasNext( )) {
215+
if(this.questionIterator.index !== -1) {
216+
this.scene.remove(this.currentQuestion[ QUESTION_MOLECULE ]);
217+
}
218+
this.currentQuestion = this.questionIterator.next( );
219+
this.scene.add(this.currentQuestion[ QUESTION_MOLECULE ]);
220+
setQuestionText(this.currentQuestion[ QUESTION_TEXT ]);
221+
setButtons(this.currentQuestion[ QUESTION_ANSWERS ]);
222+
} else {
223+
this.endGame( );
224+
}
253225
};
254226

255227
GameScreen.prototype.answerQuestion = function(data) {
@@ -279,6 +251,28 @@
279251
);
280252
};
281253

254+
GameScreen.prototype.endGame = function( ) {
255+
function allowExit(response) {
256+
$('#finalScore').text('Final Score: ' + response.final_score);
257+
$('#rank').text('Rank: #' + response.rank);
258+
$('#gameCompletedUI').addClass('in active');
259+
}
260+
disableButtons( );
261+
this.scene.remove(this.currentQuestion[ QUESTION_MOLECULE ]);
262+
this.currentQuestion = undefined;
263+
this.timer.stop( );
264+
$('#scoreChange')
265+
.stop(true, true)
266+
.animate({
267+
opacity: 0
268+
},
269+
300);
270+
FCCommunicationManager.endFlashcardGame(UserData.auth,
271+
this.gameData.game_session_id,
272+
this.timer.getElapsedMs(),
273+
allowExit.bind(this));
274+
};
275+
282276
function enableButtons(gameScreen) {
283277
$('#gameUI .button[data-logic=\'return\']').on('click', function() {
284278
$(this).trigger(new ScreenChangeEvent('menu'));

public_html/src/js/HighScoreScreen.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* TODO Remove class?! */
2+
13
(function(window, $) {
24
'use strict';
35

@@ -39,6 +41,5 @@
3941
$('#highScoreUI .button').off('click');
4042
}
4143

42-
// export HighScoreScreen
4344
window.HighScoreScreen = HighScoreScreen;
4445
})(window, jQuery);

0 commit comments

Comments
 (0)