I wrote a HTML version of
Yahtzee many years ago as a small "I'm bored at work" project. It enjoyed a brief state of popularity when my mate
Alan put it on his site as the 404 page. Even today, many years later and with no advertising by me, I still get around 1,600 hits a month.
Anyway, my girlfriend was recently playing it and mentioned that it didn't seem to work too well in
Firefox. No surprise there really as I wrote it very much for
Internet Explorer, seeing at that is the only browser we have at work.
Anyway I took a look at the code and it's just a horrible mess. I probably thought it was great at the time but now it just looks awful. Also, having not touched it for some time, I've completely forgotten what does what.
So a tidy up and some reworking was very much in order. It's a work in progress and I'll post updates here as they take place.
First steps:
- Remove the javascript to a seperate file.
- Correct a CSS problem with a font value (found using the Firefox Javascript console).
- Replace direct element addressing with getElementById:
Replace: DstatusLine.innerHTML=displayString
With: document.getElementById("DstatusLine").innerHTML=displayString;
- Very few of the lines have terminating semi-colons so I'm adding them in as and when.
- Very few of the HTML values have quotes round then so I'm adding quotes as and when to make it more XHTML compliant.
Switching to using getElementById has enabled me to get rid of eval statements like
eval("Dheld"+i+".innerHTML='"+indic+"'"); with
document.getElementById("Dheld" + i).innerHTML = indic;. Getting rid of eval can only be an improvement.
The next things to be looked at are:
- Sorting out the key press code that doesn't work in Firefox.
- Look at use of Wingdings which doesn't work in Firefox.
- General tidy-up of the code and logic. Maybe create a dice class.
- Polish the graphics.