feature/MAPG-235-basic-challenge-mode #48
@ -295,36 +295,29 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
return;
|
||||
}
|
||||
|
||||
Game.history = this.response.history;
|
||||
|
||||
if (this.response.history !== undefined) {
|
||||
for (var i = 0; i < this.response.history.length; ++i) {
|
||||
var round = this.response.history[i];
|
||||
|
||||
if (round.result) {
|
||||
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
||||
Game.addPositionToResultMap(true);
|
||||
if (round.result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
||||
}
|
||||
Game.scoreSum += round.result.score;
|
||||
|
||||
|
||||
if (round.allResults !== undefined) {
|
||||
for (var j = 0; j < round.allResults.length; ++j) {
|
||||
var result = round.allResults[j];
|
||||
if (result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Game.loadHistory(this.response.history);
|
||||
|
||||
if (this.response.finished) {
|
||||
|
||||
Game.transitToResultMap();
|
||||
Game.showSummary();
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
Game.panoId = this.response.place.panoId;
|
||||
Game.pov = this.response.place.pov;
|
||||
|
||||
Game.startNewRound();
|
||||
}
|
||||
|
||||
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
|
||||
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
|
||||
});
|
||||
},
|
||||
|
||||
transitToResultMap: function() {
|
||||
// TODO: refactor - it is necessary for mobile
|
||||
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
||||
document.getElementById('showGuessButton').click();
|
||||
@ -345,20 +338,65 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
draggableCursor: 'grab'
|
||||
});
|
||||
|
||||
Game.showSummary();
|
||||
|
||||
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
return;
|
||||
document.getElementById('showSummaryButton').style.display = 'block';
|
||||
} else if (Game.type == GameType.MULTI) {
|
||||
if (Game.multi.owner) {
|
||||
if (!Game.readyToContinue) {
|
||||
document.getElementById('continueButton').disabled = true;
|
||||
}
|
||||
} else {
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Game.panoId = this.response.place.panoId;
|
||||
Game.pov = this.response.place.pov;
|
||||
loadHistory: function (history) {
|
||||
if(!history)
|
||||
return;
|
||||
|
||||
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
|
||||
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
|
||||
Game.history = history;
|
||||
|
||||
Game.startNewRound();
|
||||
});
|
||||
for (var i = 0; i < Game.rounds.length; ++i) {
|
||||
var round = Game.rounds[i];
|
||||
|
||||
if (round.realMarker) {
|
||||
round.realMarker.setMap(null);
|
||||
}
|
||||
for (var j = 0; j < round.guessMarkers.length; ++j) {
|
||||
var guessMarker = round.guessMarkers[j];
|
||||
guessMarker.marker.setMap(null);
|
||||
guessMarker.line.setMap(null);
|
||||
if (guessMarker.info) {
|
||||
guessMarker.info.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Game.rounds = [];
|
||||
|
||||
for (var i = 0; i < Game.history.length; ++i) {
|
||||
var round = Game.history[i];
|
||||
|
||||
if (round.result) {
|
||||
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
||||
Game.addPositionToResultMap(true);
|
||||
if (round.result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
||||
balazs marked this conversation as resolved
Outdated
|
||||
}
|
||||
Game.scoreSum += round.result.score;
|
||||
|
||||
|
||||
if(round.allResults !== undefined) {
|
||||
for (var j = 0; j < round.allResults.length; ++j) {
|
||||
var result = round.allResults[j];
|
||||
if (result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reset: function () {
|
||||
@ -542,25 +580,9 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
},
|
||||
|
||||
showResultMap: function (result, resultBounds) {
|
||||
// TODO: refactor - it is necessary for mobile
|
||||
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
||||
document.getElementById('showGuessButton').click();
|
||||
}
|
||||
|
||||
if (Game.adaptGuess) {
|
||||
document.getElementById('guess').classList.remove('adapt');
|
||||
}
|
||||
Game.transitToResultMap();
|
||||
|
||||
if (Game.guessMarker) {
|
||||
Game.guessMarker.setMap(null);
|
||||
Game.guessMarker = null;
|
||||
}
|
||||
|
||||
document.getElementById('guess').classList.add('result');
|
||||
|
||||
Game.map.setOptions({
|
||||
draggableCursor: 'grab'
|
||||
});
|
||||
Game.map.fitBounds(resultBounds);
|
||||
|
||||
var distanceInfo = document.getElementById('distanceInfo');
|
||||
@ -579,19 +601,6 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
var scoreBar = document.getElementById('scoreBar');
|
||||
scoreBar.style.backgroundColor = scoreBarProperties.backgroundColor;
|
||||
scoreBar.style.width = scoreBarProperties.width;
|
||||
|
||||
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
document.getElementById('showSummaryButton').style.display = 'block';
|
||||
} else if (roomId) {
|
||||
if (Game.multi.owner) {
|
||||
if (!Game.readyToContinue) {
|
||||
document.getElementById('continueButton').disabled = true;
|
||||
}
|
||||
} else {
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
guess: function () {
|
||||
@ -783,43 +792,6 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
},
|
||||
|
||||
showSummary: function () {
|
||||
for (var i = 0; i < Game.rounds.length; ++i) {
|
||||
var round = Game.rounds[i];
|
||||
|
||||
if (round.realMarker) {
|
||||
round.realMarker.setMap(null);
|
||||
}
|
||||
for (var j = 0; j < round.guessMarkers.length; ++j) {
|
||||
var guessMarker = round.guessMarkers[j];
|
||||
guessMarker.marker.setMap(null);
|
||||
guessMarker.line.setMap(null);
|
||||
if (guessMarker.info) {
|
||||
guessMarker.info.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Game.rounds = [];
|
||||
|
||||
for (var i = 0; i < Game.history.length; ++i) {
|
||||
var round = Game.history[i];
|
||||
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
||||
Game.addPositionToResultMap(true);
|
||||
if (round.result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
||||
}
|
||||
Game.scoreSum += round.result.score;
|
||||
|
||||
if(round.allResults !== undefined) {
|
||||
for (var j = 0; j < round.allResults.length; ++j) {
|
||||
var result = round.allResults[j];
|
||||
if (result.guessPosition) {
|
||||
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var distanceInfo = document.getElementById('distanceInfo');
|
||||
distanceInfo.children[0].style.display = 'none';
|
||||
distanceInfo.children[1].style.display = 'none';
|
||||
|
Loading…
Reference in New Issue
Block a user
I had to create span from javascript, because I didn't know, how else to control the display css attribute from both css (depending on screen size) and javascript (depending on the game type). Javascript overrides the css attribute even for narrow screens. Is there a more elegant solution?
It could be solved with a hidden element, for example with class
hidden
which can be removed by JavaScript when it should be shown (it still can have classhideOnNarrowScreen
). But I think it is also a good solution.