2022-09-19 07:39:13 -05:00
//<TO-DO>
//-FIX TIMER
//-FIX IMAGE RATIOS
//-FIX CALENDAR
2022-08-07 03:40:24 -05:00
//
2022-09-19 07:39:13 -05:00
// var fake_date = new Date("September 19, 2022 23:58:00");
// Date = function(){return fake_date;};
// Date.now = () => fake_date.getTime();
window . onload = deathOftheDay ;
2022-08-07 03:40:24 -05:00
var playedBefore = false ;
2022-09-07 09:05:49 -05:00
var sameDay = false ;
2022-08-07 03:40:24 -05:00
for ( var i = 0 ; i < localStorage . length ; i ++ ) {
console . log ( localStorage . key ( i ) ) ;
}
2022-09-11 03:32:29 -05:00
2022-09-11 09:11:13 -05:00
var movies = [ "A Nightmare on Elm Street" , "Friday the 13th" , "Event Horizon" , "Hellraiser" , "The Cabin in the Woods" , "American Psycho" , "It Follows" , "Candyman" , "Child's Play" , "The Texas Chain Saw Massacre" , "Alien" , "Halloween" ] ;
2022-08-07 03:40:24 -05:00
var pix = [ ] ;
autocomplete ( document . getElementById ( "guess" ) , movies ) ;
2022-09-19 07:39:13 -05:00
var gameBeginning = new Date ( 'September 18, 2022 00:00:00' ) ;
2022-09-11 07:41:49 -05:00
var countDownTime = new Date ( ) ;
var present _date = new Date ( ) ;
2022-08-07 03:40:24 -05:00
// gameBeginning = new Date(gameBeginning.getTime() + 0 * 60 * 1000);
console . log ( gameBeginning . getTimezoneOffset ( ) ) ;
2022-09-19 07:39:13 -05:00
dayCounter ( ) ;
2022-08-07 03:40:24 -05:00
console . log ( "gameBeginning: " , gameBeginning ) ;
console . log ( "now: " , present _date ) ;
2022-09-19 07:39:13 -05:00
2022-08-07 03:40:24 -05:00
var textResult = "Horrordle #" + dayCount + "\n🔪" ;
2022-09-19 07:39:13 -05:00
function dayCounter ( ) {
dayCount = Math . floor ( ( present _date - gameBeginning ) / ( 1000 * 60 * 60 * 24 ) ) ;
return dayCount ;
}
2022-08-07 03:40:24 -05:00
markCalendar ( ) ;
function markCalendar ( ) {
dates = document . getElementsByClassName ( 'calendar__number' ) ;
console . log ( dates [ 10 ] . innerHTML ) ;
var tag = [ ] ;
for ( var i = 0 ; i < dates . length ; i ++ ) {
if ( dates [ i ] . innerHTML == dayCount ) {
dates [ i ] . classList . add ( 'current' ) ;
for ( var j = 0 ; j < i ; j ++ ) {
if ( localStorage . getItem ( 'day' + ( j + 1 ) ) ) {
if ( localStorage . getItem ( 'day' + ( j + 1 ) ) == 'true' ) {
dates [ j ] . classList . add ( 'won' ) ;
} else if ( localStorage . getItem ( 'day' + ( j + 1 ) ) == 'false' ) {
dates [ j ] . classList . add ( 'lost' ) ;
}
} else {
dates [ j ] . classList . add ( 'past' ) ;
dates [ j ] = document . createElement ( 'a' ) ;
//dates[j].setAttribute('href','#');
dates [ j ] . setAttribute ( 'onclick' , 'getArchive(' + ( j + 1 ) + ')' ) ;
dates [ j ] = "<a href='#'>" + dates [ j ] + "</a>" ;
}
// dates[j] = "<a href='" + dayCount + "'>" + dates[j] + "</a>";
//tag[j].appendChild(dates[j]);
//console.log(tag[j]);
console . log ( dates [ j ] ) ;
}
console . log ( dates [ i ] ) ;
}
}
}
var points = "⬛⬛⬛"
//check if the user played this before
2022-09-11 03:32:29 -05:00
firstCheck ( )
function firstCheck ( ) {
guessNo = 0 ;
2022-08-07 03:40:24 -05:00
feedback . textContent = "🩸 " + ( 3 - guessNo ) + " guesses remaining" ;
if ( ! localStorage . getItem ( 'streak' ) ) { localStorage . setItem ( 'streak' , 0 ) }
2022-09-11 03:32:29 -05:00
if ( ! localStorage . getItem ( 'firstGuessStat' ) ) { localStorage . setItem ( 'firstGuessStat' , 0 ) }
if ( ! localStorage . getItem ( 'secondGuessStat' ) ) { localStorage . setItem ( 'secondGuessStat' , 0 ) }
if ( ! localStorage . getItem ( 'thirdGuessStat' ) ) { localStorage . setItem ( 'thirdGuessStat' , 0 ) }
}
2022-09-07 09:05:49 -05:00
2022-08-07 03:40:24 -05:00
2022-09-11 10:54:00 -05:00
textResult = "Horrordle #" + dayCount + "\n🔪" ;
2022-08-07 03:40:24 -05:00
function clearGuess ( ) {
localStorage . removeItem ( 'firstGuess' ) ;
localStorage . removeItem ( 'secondGuess' ) ;
localStorage . removeItem ( 'guessNo' ) ;
localStorage . removeItem ( 'winningGuess' ) ;
2022-09-11 10:54:00 -05:00
// localStorage.removeItem('result');
2022-09-11 03:32:29 -05:00
document . getElementById ( "firstGuess" ) . style . display = "none" ;
document . getElementById ( "secondGuess" ) . style . display = "none" ;
2022-09-11 04:00:27 -05:00
document . getElementById ( "shareResult" ) . style . display = "none" ;
document . getElementById ( "guessForm" ) . style . display = "block" ;
2022-09-11 07:41:49 -05:00
document . getElementById ( "countDown" ) . style . display = "none"
2022-09-11 10:54:00 -05:00
2022-08-07 03:40:24 -05:00
}
function checkingGuess ( ) {
2022-09-07 09:05:49 -05:00
2022-08-07 03:40:24 -05:00
streakNumber . textContent = localStorage . getItem ( 'streak' ) ;
if ( localStorage . getItem ( 'day' ) == dayCount ) {
playedBefore = true ;
textResult = localStorage . getItem ( 'result' )
console . log ( "played before: " , playedBefore ) ;
console . log ( localStorage . getItem ( 'firstGuess' ) ) ;
console . log ( localStorage . getItem ( 'secondGuess' ) ) ;
if ( localStorage . getItem ( 'guessNo' ) ) { guessNo = localStorage . getItem ( 'guessNo' ) } ;
feedback . textContent = "🩸 " + ( 3 - guessNo ) + " guesses remaining" ;
2022-09-11 09:11:13 -05:00
if ( localStorage . getItem ( 'result' ) ) { localStorage . setItem ( 'result' , textResult ) ; document . getElementById ( "resultText" ) . innerHTML = textResult }
2022-08-07 03:40:24 -05:00
if ( localStorage . getItem ( 'firstGuess' ) ) { firstGuess . textContent = "❌" + localStorage . getItem ( 'firstGuess' ) ; document . getElementById ( "firstGuess" ) . style . display = "block" ; }
if ( localStorage . getItem ( 'secondGuess' ) ) { secondGuess . textContent = "❌" + localStorage . getItem ( 'secondGuess' ) ; document . getElementById ( "secondGuess" ) . style . display = "block" ; }
2022-09-11 09:11:13 -05:00
if ( localStorage . getItem ( 'winningGuess' ) ) { document . getElementById ( "feedback" ) . innerHTML = "Next movie will reveal at <b>midnight!</b> 🕛" ; document . getElementById ( "shareResult" ) . style . display = "block" ; document . getElementById ( "countDown" ) . style . display = "block" ; document . getElementById ( "guessForm" ) . style . display = "none" ; document . getElementById ( "firstGuess" ) . style . display = "none" ; document . getElementById ( "secondGuess" ) . style . display = "none" ; } else { document . getElementById ( "shareResult" ) . style . display = "none" ; document . getElementById ( "guessForm" ) . style . display = "block" ; } ;
2022-08-07 03:40:24 -05:00
secondGuess . textContent = "❌" + localStorage . getItem ( 'secondGuess' ) ;
} else {
clearGuess ( ) ;
2022-09-07 09:05:49 -05:00
localStorage . setItem ( 'day' , dayCount ) ;
2022-08-07 03:40:24 -05:00
}
}
2022-09-07 09:05:49 -05:00
checkingGuess ( ) ;
2022-08-07 03:40:24 -05:00
console . log ( dayCount ) ;
function deathOftheDay ( ) {
pix = [ ] ;
movieOfTheDay = movies [ dayCount - 1 ] ;
for ( let i = 1 ; i < 4 ; i ++ ) {
2022-09-11 07:41:49 -05:00
pix . push ( "images/" + movieOfTheDay + "/" + i + ".png" ) ;
2022-08-07 03:40:24 -05:00
}
console . log ( 'Movie: ' , movieOfTheDay ) ;
console . log ( 'Array: ' , pix ) ;
document . getElementById ( "movieFrame" ) . src = pix [ guessNo ] ;
}
function checkGuess ( ) {
2022-09-11 03:32:29 -05:00
2022-08-07 03:40:24 -05:00
console . log ( "day count:" + dayCount ) ;
let myGuess = guess . value
if ( myGuess === movieOfTheDay ) {
2022-09-11 03:32:29 -05:00
if ( guessNo == 0 ) { localStorage . setItem ( 'firstGuessStat' , parseInt ( localStorage . getItem ( 'firstGuessStat' ) ) + 1 ) ; }
if ( guessNo == 1 ) { localStorage . setItem ( 'secondGuessStat' , parseInt ( localStorage . getItem ( 'secondGuessStat' ) ) + 1 ) ; }
if ( guessNo == 2 ) { localStorage . setItem ( 'thirdGuessStat' , parseInt ( localStorage . getItem ( 'thirdGuessStat' ) ) + 1 ) ; }
2022-08-07 03:40:24 -05:00
localStorage . setItem ( 'streak' , parseInt ( localStorage . getItem ( 'streak' ) ) + 1 ) ;
localStorage . setItem ( 'day' + dayCount , 'true' ) ;
2022-09-19 07:39:13 -05:00
// document.getElementById("movieFrame").src = "images/"+movieOfTheDay+"/poster.jpg";
2022-08-07 03:40:24 -05:00
console . log ( localStorage . getItem ( 'day' + dayCount ) ) ;
streakNumber . textContent = " " + localStorage . getItem ( 'streak' ) ;
document . getElementById ( "guessForm" ) . style . display = "none" ;
2022-09-11 10:54:00 -05:00
document . getElementById ( "movieName" ) . innerHTML = movieOfTheDay + " ✅" ;
2022-09-11 07:41:49 -05:00
document . getElementById ( "countDown" ) . style . display = "block" ;
2022-08-07 03:40:24 -05:00
document . getElementById ( "shareResult" ) . style . display = "block" ;
localStorage . setItem ( "winningGuess" , guess . value ) ;
2022-09-11 04:00:27 -05:00
document . getElementById ( "firstGuess" ) . style . display = "none" ;
document . getElementById ( "secondGuess" ) . style . display = "none" ;
2022-09-11 03:32:29 -05:00
2022-08-07 03:40:24 -05:00
textResult = textResult + "🟩" ;
for ( var i = 1 ; i < ( 3 - guessNo ) ; i ++ ) {
textResult = textResult + "⬛" ;
}
localStorage . setItem ( 'result' , textResult ) ;
2022-09-11 09:11:13 -05:00
document . getElementById ( "feedback" ) . innerHTML = "Next movie revealed at midnight! 🕛 <br>" ;
document . getElementById ( "resultText" ) . innerHTML = textResult ;
2022-08-07 03:40:24 -05:00
dates [ dayCount - 1 ] . classList . add ( 'won' ) ;
2022-09-11 09:11:13 -05:00
2022-08-07 03:40:24 -05:00
} else if ( guessNo == 1 ) {
guessNo = guessNo + 1 ;
localStorage . setItem ( 'guessNo' , guessNo ) ;
2022-09-11 03:32:29 -05:00
feedback . textContent = "🩸 " + ( 3 - guessNo ) + " guesses remaining" ;
2022-08-07 03:40:24 -05:00
document . getElementById ( "movieFrame" ) . src = pix [ guessNo ] ;
firstGuess . textContent = "❌" + guess . value ;
localStorage . setItem ( 'firstGuess' , guess . value ) ;
document . getElementById ( "firstGuess" ) . style . display = "block" ;
textResult = textResult + "🟥" ;
localStorage . setItem ( 'result' , textResult ) ;
} else if ( guessNo < 2 ) {
guessNo = guessNo + 1 ;
localStorage . setItem ( 'guessNo' , guessNo ) ;
2022-09-11 03:32:29 -05:00
feedback . textContent = "🩸 " + ( 3 - guessNo ) + " guesses remaining" ;
2022-08-07 03:40:24 -05:00
document . getElementById ( "movieFrame" ) . src = pix [ guessNo ] ;
secondGuess . textContent = "❌" + guess . value ;
localStorage . setItem ( 'secondGuess' , guess . value ) ;
document . getElementById ( "secondGuess" ) . style . display = "block" ;
textResult = textResult + "🟥" ;
localStorage . setItem ( 'result' , textResult ) ;
}
else {
feedback . textContent = "GAME OVER" ;
textResult = textResult + "🟥" ;
localStorage . setItem ( 'guessNo' , guessNo ) ;
localStorage . setItem ( 'streak' , 0 ) ;
localStorage . setItem ( 'day' + dayCount , 'false' ) ;
dates [ dayCount - 1 ] . classList . add ( 'lost' ) ;
}
console . log ( textResult ) ;
2022-09-11 03:32:29 -05:00
document . getElementById ( "guessForm" ) . reset ( ) ;
2022-08-07 03:40:24 -05:00
}
function autocomplete ( inp , arr ) {
/ * t h e a u t o c o m p l e t e f u n c t i o n t a k e s t w o a r g u m e n t s ,
the text field element and an array of possible autocompleted values : * /
var currentFocus ;
/*execute a function when someone writes in the text field:*/
inp . addEventListener ( "input" , function ( e ) {
var a , b , i , val = this . value ;
/*close any already open lists of autocompleted values*/
closeAllLists ( ) ;
if ( ! val ) { return false ; }
currentFocus = - 1 ;
/*create a DIV element that will contain the items (values):*/
a = document . createElement ( "DIV" ) ;
a . setAttribute ( "id" , this . id + "autocomplete-list" ) ;
a . setAttribute ( "class" , "autocomplete-items" ) ;
/*append the DIV element as a child of the autocomplete container:*/
this . parentNode . appendChild ( a ) ;
/*for each item in the array...*/
for ( i = 0 ; i < arr . length ; i ++ ) {
2022-09-11 07:41:49 -05:00
// newArray = arr[i].split(" ");
newArray = arr [ i ] . split ( " " ) ;
2022-08-07 03:40:24 -05:00
/*check if the item starts with the same letters as the text field value:*/
for ( var j = 0 ; j < newArray . length ; j ++ ) {
if ( newArray [ j ] . substr ( 0 , val . length ) . toUpperCase ( ) == val . toUpperCase ( ) ) {
/*create a DIV element for each matching element:*/
b = document . createElement ( "DIV" ) ;
/*make the matching letters bold:*/
b . innerHTML = newArray . slice ( 0 , j ) . join ( ' ' ) + " <strong>" + newArray [ j ] . substr ( 0 , val . length ) + "</strong>" ;
b . innerHTML += newArray [ j ] . substr ( val . length ) + " " + newArray . slice ( j + 1 , newArray . length ) . join ( ' ' ) ;
/*insert a input field that will hold the current array item's value:*/
b . innerHTML += "<input type='hidden' value='" + newArray . join ( ' ' ) + "'>" ;
/*execute a function when someone clicks on the item value (DIV element):*/
b . addEventListener ( "click" , function ( e ) {
/*insert the value for the autocomplete text field:*/
inp . value = this . getElementsByTagName ( "input" ) [ 0 ] . value ;
/ * c l o s e t h e l i s t o f a u t o c o m p l e t e d v a l u e s ,
( or any other open lists of autocompleted values : * /
closeAllLists ( ) ;
} ) ;
a . appendChild ( b ) ;
}
}
}
} ) ;
/*execute a function presses a key on the keyboard:*/
inp . addEventListener ( "keydown" , function ( e ) {
var x = document . getElementById ( this . id + "autocomplete-list" ) ;
if ( x ) x = x . getElementsByTagName ( "div" ) ;
if ( e . keyCode == 40 ) {
/ * I f t h e a r r o w D O W N k e y i s p r e s s e d ,
increase the currentFocus variable : * /
currentFocus ++ ;
/*and and make the current item more visible:*/
addActive ( x ) ;
} else if ( e . keyCode == 38 ) { //up
/ * I f t h e a r r o w U P k e y i s p r e s s e d ,
decrease the currentFocus variable : * /
currentFocus -- ;
/*and and make the current item more visible:*/
addActive ( x ) ;
} else if ( e . keyCode == 13 ) {
/*If the ENTER key is pressed, prevent the form from being submitted,*/
e . preventDefault ( ) ;
if ( currentFocus > - 1 ) {
/*and simulate a click on the "active" item:*/
if ( x ) x [ currentFocus ] . click ( ) ;
}
}
} ) ;
function addActive ( x ) {
/*a function to classify an item as "active":*/
if ( ! x ) return false ;
/*start by removing the "active" class on all items:*/
removeActive ( x ) ;
if ( currentFocus >= x . length ) currentFocus = 0 ;
if ( currentFocus < 0 ) currentFocus = ( x . length - 1 ) ;
/*add class "autocomplete-active":*/
x [ currentFocus ] . classList . add ( "autocomplete-active" ) ;
}
function removeActive ( x ) {
/*a function to remove the "active" class from all autocomplete items:*/
for ( var i = 0 ; i < x . length ; i ++ ) {
x [ i ] . classList . remove ( "autocomplete-active" ) ;
}
}
function closeAllLists ( elmnt ) {
/ * c l o s e a l l a u t o c o m p l e t e l i s t s i n t h e d o c u m e n t ,
except the one passed as an argument : * /
var x = document . getElementsByClassName ( "autocomplete-items" ) ;
for ( var i = 0 ; i < x . length ; i ++ ) {
if ( elmnt != x [ i ] && elmnt != inp ) {
x [ i ] . parentNode . removeChild ( x [ i ] ) ;
}
}
}
/*execute a function when someone clicks in the document:*/
document . addEventListener ( "click" , function ( e ) {
closeAllLists ( e . target ) ;
} ) ;
}
function copyToClipboard ( ) {
navigator . clipboard . writeText ( textResult ) . then ( ( ) => {
shareResult . value = "copied!" ;
// Alert the user that the action took place.
// Nobody likes hidden stuff being done under the hood!
} ) ;
}
function getArchive ( j ) {
dates [ dayCount - 1 ] . classList . remove ( 'current' ) ;
dayCount = j ;
dates [ j - 1 ] . classList . add ( 'current' ) ;
deathOftheDay ( ) ;
clearGuess ( ) ;
checkingGuess ( ) ;
2022-09-11 04:00:27 -05:00
// checkGuess();
2022-09-11 03:32:29 -05:00
firstCheck ( ) ;
2022-08-07 03:40:24 -05:00
document . getElementById ( 'guess' ) . value = "" ;
location . href = '#' ;
//window.open("#");
}
submitGuess . addEventListener ( 'click' , checkGuess )
2022-09-11 03:32:29 -05:00
const labels = [
'First Guess' ,
'Second Guess' ,
'Third Guess' ,
] ;
const data = {
labels : labels ,
datasets : [ {
label : 'Number of guesses' ,
backgroundColor : 'rgb(255, 99, 132)' ,
fontColor : 'white' ,
color : 'white' ,
data : [ localStorage . getItem ( 'firstGuessStat' ) , localStorage . getItem ( 'secondGuessStat' ) , localStorage . getItem ( 'thirdGuessStat' ) ] ,
} ]
} ;
Chart . defaults . color = 'white'
Chart . defaults . borderColor = 'grey'
const config = {
type : 'bar' ,
data : data ,
options : {
scales : {
yAxes : {
ticks : {
stepSize : 1
}
}
}
}
} ;
2022-09-11 07:41:49 -05:00
var x = setInterval ( function ( ) {
2022-09-11 09:11:13 -05:00
// countDownTime.setDate(Math.floor((present_date - gameBeginning) / (1000 * 60 * 60 * 24))+2);
2022-09-19 07:39:13 -05:00
dayCounter ( ) ;
dateVariable = present _date . getDate ( )
countDownTime . setDate ( dateVariable + 1 ) ;
countDownTime . setHours ( 0 ) ;
2022-09-11 09:11:13 -05:00
countDownTime . setMinutes ( 0 ) ;
2022-09-11 07:41:49 -05:00
countDownTime . setSeconds ( 0 ) ;
var now = new Date ( ) ;
2022-09-19 07:39:13 -05:00
console . log ( "now: " , now ) ;
2022-09-11 07:41:49 -05:00
var remainingTime = countDownTime - now ;
const second = 1000 ;
const minute = second * 60 ;
const hour = minute * 60 ;
const day = hour * 24 ;
hoursLeft = Math . trunc ( ( remainingTime % day ) / hour ) ;
minutesLeft = Math . trunc ( ( remainingTime % hour ) / minute ) ;
secondsLeft = Math . trunc ( ( remainingTime % minute ) / second ) ;
document . getElementById ( "countDown" ) . innerHTML = hoursLeft + "h "
+ minutesLeft + "m " + secondsLeft + "s " ;
2022-09-19 07:39:13 -05:00
//console.log(remainingTime);
console . log ( localStorage . getItem ( 'day' ) ) ;
console . log ( "day count: " + dayCount ) ;
dayCount = Math . floor ( ( now - gameBeginning ) / ( 1000 * 60 * 60 * 24 ) ) ;
if ( localStorage . getItem ( 'day' ) != dayCount ) {
window . location . reload ( ) ;
2022-09-11 07:41:49 -05:00
}
} , 1000 ) ;
2022-09-19 07:39:13 -05:00
2022-09-11 03:32:29 -05:00
const myChart = new Chart (
document . getElementById ( 'myChart' ) ,
config
2022-09-19 07:39:13 -05:00
) ;
//window.localStorage.clear();