Word Le Code
Word Le Code
// When play again button is clicked, squares and global variables are reset
// When stats button is clicked, all recorded statistics for the session are displayed
// Bar graph is drawn based on win distribution
onEvent("Stats" ,"click", function() {
if (statsOpen == true) {
statsOpen = false;
hideElement("StatsList");
hideElement("StatisticsTitle");
hideElement("Played");
hideElement("PlayedText");
hideElement("Win%");
hideElement("Win%Text");
hideElement("CurrentStreak");
hideElement("CurrentStreakText");
hideElement("MaxStreak");
hideElement("MaxStreakText");
hideElement("GuessDistribution");
} else {
statsOpen = true;
var data = [
{ guess: "1", won: (wonOne) },
{ guess: "2", won: (wonTwo) },
{ guess: "3", won: (wonThree) },
{ guess: "4", won: (wonFour) },
{ guess: "5", won: (wonFive) },
{ guess: "6", won: (wonSix) }
];
drawChart("GuessDistribution", "bar", data);
setText("Played", gamesPlayed);
if (gamesPlayed == 0) {
setText("Win%", 0);
} else {
setText("Win%", Math.floor(100 * gamesWon / gamesPlayed));
}
setText("CurrentStreak", curStreak);
setText("MaxStreak", maxStreak);
// When settings button is clicked, mobile mode is enabled to allow typing on mobile devices
onEvent("Settings" ,"click", function() {
if (settingsOpen == true) {
settingsOpen = false;
hideElement("MobileInput");
} else {
settingsOpen = true;
showElement("MobileInput");
}
});
// When mobile mode text box receives input, the characters are deleted. All game inputs are recorded through the
screen event handler
onEvent("MobileInput", "input", function() {
setText("MobileInput", "MOBILE MODE");
});