Skip to content

Commit

Permalink
Redid daily befuddle index
Browse files Browse the repository at this point in the history
  • Loading branch information
suitangi committed Jul 5, 2023
1 parent e405651 commit a8e820b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#Ignore the ignore directory
ignore/
stats/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ A Magic: The Gathering card art letter guessing game similar to Hangman. With da

# Changelog
```
7/2/2023 Routine card list update
5/6/2023: Updated cards list and new year of daily befuddles
6/20/2022: Daily Befuddle Bug fixes
5/8/2022: Stability and optimization fixes
Expand Down
2 changes: 1 addition & 1 deletion dailyList.json

Large diffs are not rendered by default.

45 changes: 17 additions & 28 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ function loadCard(data) {
window.gameSesh.tlv = window.game[window.game.mode].lives;

if (window.game.mode == 'daily') {
let dday = new Date();
window.gameSesh.doy = dday.getYear() * 1000 + dday.getDOY();
window.gameSesh.doy = getDateNumber();
window.gameSesh.giveUp = false;
}

Expand Down Expand Up @@ -416,9 +415,9 @@ function gameLostDaily() {
}

//new daily stat, not just a refresh
let doy = (new Date()).getDOY();
if (window.stats.daily.doy != doy) {
window.stats.daily.doy = doy
let dn = getDateNumber();
if (window.stats.daily.doy != dn) {
window.stats.daily.doy = dn;
window.stats.daily.streak = 0;
if (!window.gameSesh.hideBlanks) {
window.stats.daily.WL[1]++;
Expand Down Expand Up @@ -491,11 +490,11 @@ function gameWinDaily() {
}

let wr = window.gameSesh.wrongGuess.length;
let doy = (new Date()).getDOY();
let dn = getDateNumber();

//new daily stat, not just a refresh
if (window.stats.daily.doy != doy) {
window.stats.daily.doy = doy
if (window.stats.daily.doy != dn) {
window.stats.daily.doy = dn;
window.stats.daily.streak++;

//streak data
Expand Down Expand Up @@ -1609,7 +1608,7 @@ function loadGame() {
Cookies.set('befuddle', JSON.stringify(window.game), {
expires: 365
});
loadCard(data[d.getDOY()]);
loadCard(data.list[getDateNumber() - data.start]);
}

if (window.dailyList == null) { //fetch first if null
Expand Down Expand Up @@ -1966,7 +1965,7 @@ function checkTabFocused() {
function submitDailyData(win) {
const uri = "https://docs.google.com/forms/u/0/d/e/1FAIpQLSf8M4zoBjF6ZcY0v4ebBXmBCKr0vpB_EtAZLPE2-B0ZDfGBLg/formResponse";
const entryNames = ['entry.1034508364', 'entry.462826655', 'entry.2082961611'];
const values = [window.gameSesh.doy % 1000, window.gameSesh.guesses, win];
const values = [window.gameSesh.doy, window.gameSesh.guesses, win];

let tmpinput;
let ddFrame = document.createElement('iframe');
Expand Down Expand Up @@ -2068,7 +2067,7 @@ $(document).ready(function() {
if (Cookies.get('daily')) { //check for new day in daily
let tmp = JSON.parse(Cookies.get('daily'));
let dday = new Date();
if (tmp.doy == undefined || (dday.getYear() * 1000 + dday.getDOY()) != tmp.doy)
if (tmp.doy == undefined || getDateNumber() != tmp.doy)
Cookies.remove('daily');
}

Expand Down Expand Up @@ -2170,20 +2169,10 @@ $(document).ready(function() {

});

//Lets pollute the date prototype
//Get leap year
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
if ((year & 3) != 0) return false;
return ((year % 100) != 0 || (year % 400) == 0);
};

// Get Day of Year
Date.prototype.getDOY = function() {
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
var mn = this.getMonth();
var dn = this.getDate();
var dayOfYear = dayCount[mn] + dn;
if (mn > 1 && this.isLeapYear()) dayOfYear++;
return dayOfYear;
};
//gets date corresponding number for daily befuddle
function getDateNumber() {
d1 = new Date('5/6/2022 0:00');
d2 = new Date();
dd = Math.floor((d2.getTime() - d1.getTime()) / 86400000) - 1;
return dd;
}

0 comments on commit a8e820b

Please sign in to comment.