Created
February 26, 2018 17:43
-
-
Save HarryZ10/8c9906ffb1f8ea1dc555dd7e1c9f1120 to your computer and use it in GitHub Desktop.
Guess-that-song game! via Studio.code.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* THIS PPOGRAM IS MADE FOR THE AP EXAM! | |
THIS GAME IS CALLED "Guess-that-song!" challenge!! GL;HF!!! */ | |
/* VARIABLES for OTHER related things */ | |
var playerScore = 0; | |
var moreTimeCount = 0; | |
var guessUserInput = getText("guessingInput"); | |
/* VARIABLES for DIFFICULTY MODE related things */ | |
var easyMode = false; | |
var userInputDifficulty; | |
/* VARIABLES for TIMER related things */ | |
var timeStarts = 10; | |
var playSongTimer; | |
var timer; | |
/* VARIABLES for SONG related things */ | |
var globalIndex = 0; | |
var songNames = ["logic - america", "luis fonsi - despacito", "shawn mendes - treat you better", "taylor swift - end game"]; | |
var songs = []; //appends the items on call | |
/* !!! BEYOND THIS POINT, DO NOT CHANGE OR EDIT ANYTHING! IFF YOU KNOW .JS !!! */ | |
onEvent("startBtn", "click", function() { | |
setScreen("objectiveScreen"); | |
}); | |
function difficultyMode(){ | |
if(userInputDifficulty == "easy"){ | |
runEasy(); | |
console.log("Game is EASY"); | |
setText("text", "10"); | |
timerClock(); | |
} else if (userInputDifficulty == "hard") { | |
runHard(); | |
console.log("Game is HARD"); | |
setText("text", "10"); | |
timerClock(); | |
} else if (userInputDifficulty == "HJddeJlsd329cDs") { | |
setScreen("guessingScreen"); | |
globalIndex = 3; | |
appendItems(); | |
easyMode = true; | |
playSong(3000); | |
} | |
} | |
function timerClock(){ //abstraction, 1/2 | |
timer = setInterval(function(){ | |
timeStarts--; | |
setText("text", timeStarts); | |
if(timeStarts <= 0){ | |
clearInterval(timer); | |
setScreen("guessingScreen"); | |
if(easyMode === true){ | |
playSong(3000); | |
} else if (easyMode === false) { | |
playSong(1000); | |
} | |
} | |
}, 1000); | |
} | |
function playSong(ms){ //abstration 2/2 | |
playSound(songs[globalIndex]); | |
playSongTimer = setTimeout(function() { | |
stopSound(songs[globalIndex]); | |
}, ms); | |
} | |
function gameOver(){ | |
setScreen("endScreen"); | |
setText("guessNowLbl2", "Your score is ..."); | |
setText("scoreLbl2", playerScore); | |
} | |
onEvent("objectiveScreen", "click", function(){ | |
userInputDifficulty = prompt("Enter 'easy' or 'hard' difficulty"); | |
userInputDifficulty = userInputDifficulty.toLowerCase(); | |
difficultyMode(); | |
}); | |
function runEasy(){ | |
appendItems(); | |
easyMode = true; | |
setScreen("playingScreen"); | |
} | |
function runHard(){ | |
appendItems(); | |
easyMode = false; | |
setScreen("playingScreen"); | |
} | |
function appendItems(){ | |
appendItem(songs, "Logic_-_America_ft._Black_Thought_Chuck_D_Big_Lenbo_No_I.D._Official_Audio-j3Pe0oUqFkw (mp3cut.net).mp3"); | |
appendItem(songs, "Luis_Fonsi_-_Despacito_ft._Daddy_Yankee-kJQP7kiw5Fk (mp3cut.net) (1).mp3"); | |
appendItem(songs, "Shawn_Mendes_-_Treat_You_Better-lY2yjAdbvdQ (mp3cut.net).mp3"); | |
appendItem(songs, "Taylor_Swift_-_End_Game_ft._Ed_Sheeran_Future-dfnCAmr569k-[AudioTrimmer.com].mp3"); | |
} | |
onEvent("moreTime", "click", function() { | |
var playedSongCount = 0; | |
if (moreTimeCount > 0) { | |
hideElement("moreTime"); | |
} else if (moreTimeCount === 0) { | |
moreTimeCount++; | |
playedSongCount--; | |
playSong(6000); | |
hideElement("moreTime"); | |
} | |
}); | |
function checkCorrectInput(ms){ //parent algorithm 1/3 | |
var seconds = 0; | |
if (songNames[globalIndex] != guessUserInput){ | |
updateScore(); | |
var wrongImageTimer; | |
wrongImageTimer = setInterval(function(){ | |
seconds++; | |
showElement("wrongImage"); | |
if (seconds == 5){ | |
hideElement("wrongImage"); | |
clearInterval(wrongImageTimer); | |
} | |
}, ms); | |
} else if (songNames[globalIndex] == guessUserInput){ | |
updateScore(); | |
if (globalIndex == songs.length - 1){ | |
gameOver(); | |
} else { | |
globalIndex++; | |
updateMoreTime(); | |
if (easyMode === true){ | |
playSong(3000); | |
} else { | |
playSong(1000); | |
} | |
} | |
} | |
} | |
function updateMoreTime(){ //child algorithm 2/3 | |
if (moreTimeCount == 1) { | |
moreTimeCount--; | |
showElement("moreTime"); | |
} else { | |
showElement("moreTime"); | |
} | |
} | |
function updateScore(){ //child algorithm 3/3 | |
if(songNames[globalIndex] == guessUserInput){ | |
playerScore++; | |
setText("score#", playerScore); | |
} else { | |
playerScore--; | |
setText("score#", playerScore); | |
} | |
} | |
onEvent("guessingBtn", "click", function() { | |
guessUserInput = getText("guessingInput").toLowerCase(); | |
stopSound(songs[globalIndex]); | |
checkCorrectInput(1000); | |
setText("guessingInput",""); | |
}); | |
onEvent("resetBtn", "click", function() { | |
//The order of the commands do matter in this case | |
stopSound(songs[globalIndex]); | |
playerScore = 0; | |
moreTimeCount = 0; | |
globalIndex = 0; | |
timeStarts = 10; | |
clearTimeout(playSongTimer); | |
setText("score#", playerScore); | |
updateMoreTime(); | |
setScreen("guessingScreen"); | |
if (easyMode === true){ | |
playSong(3000); | |
} else { | |
playSong(1000); | |
} | |
}); | |
/* Work Cited | |
[1] http://codespark.org/wp-content/uploads/2014/07/Button_PlayNow.png (PlayNow button) | |
[2] https://cdn2.iconfinder.com/data/icons/pointed-edge-web-navigation/101/cross-red-128.png (Wrong answer picture) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment