-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
86 lines (65 loc) · 2.33 KB
/
game.js
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
class Game {
static newGame(targetNumber) {
View.init();
View.setKnobs([7,7,7,7,7]);
targetNumber = +targetNumber + +2;
$.get("/changeLevel?targetNumber=" + targetNumber, function() {
AwsUtil.updateFixedRaster(targetNumber, Charts.drawRaster);
Game.changeCombination();
});
}
static finishGame() {
$.get("/finishGame", function(response) {
View.disableKnobsAndSimulateButton();
if (response == 1) {
// if this is a highscore, we show the form to enter the nickname
View.hideFinishGameButton();
View.displayNicknamePanel();
} else {
// if there was no highscore, we don't need to wait for other user input
// and we can display the highscores
View.displayEndedGamePanel();
AwsUtil.getAlgorithmScoreAndDisplayHighscores();
}
});
}
static submitNickname(nickname) {
$.get("/submitNickname?nickname=" + nickname, function(response) {
// also on the server it checks again if its a true highscore
View.hideNicknamePanel();
View.displayEndedGamePanel();
AwsUtil.getAlgorithmScoreAndDisplayHighscores();
});
}
static changeCombination() {
var knobs=View.getKnobs();
var targetNumber=View.getTargetNumber();
AwsUtil.display(knobs, targetNumber);
$.getJSON("/update?k1=" + knobs[0] + ";k2=" + knobs[1] + ";k3=" + knobs[2] + ";k4=" +
knobs[3] + ";k5=" + knobs[4], function (levelMeta) {
var best_cost = levelMeta.bestScore;
View.displayBestCost(best_cost);
});
}
static jumpToBestCombinationFoundSoFar() {
$.get("/jumpToBestCombinationFoundSoFar", function(result) {
var knobs=result.split(",");
View.setKnobs(knobs);
Game.refreshGameOutput();
});
}
static refreshGameOutput() {
var knobs=View.getKnobs();
var targetNumber=View.getTargetNumber();
$.getJSON("/getCurrentScore?k1=" + knobs[0] + ";k2=" + knobs[1] + ";k3=" + knobs[2] + ";k4=" +
knobs[3] + ";k5=" + knobs[4], function (levelMeta) {
var best_cost = levelMeta.bestScore;
View.displayBestCost(best_cost);
});
AwsUtil.display(knobs, targetNumber);
}
static showBestFit() {
View.hideBestFitButton();
AwsUtil.showBestFit(Charts.drawRaster);
}
}