";
+
+ //create cells
for (let r = 0; r < this.options.rows; r++) {
content += '
';
for (let c = 0; c < this.options.cols; c++) {
@@ -261,7 +236,7 @@ class Minesweeper {
this.save();
}
- //debgugging function to print the grid to console
+ //debugging function to print the grid to console
gridToString() {
let result = "";
for (let r = 0, r_len = this.grid.length; r < r_len; r++) {
@@ -314,9 +289,31 @@ class Cell {
//create a new game
function newGame(opts = {}) {
game = new Minesweeper(opts);
+ startTimer()
+
console.log(game.gridToString());
}
+function startTimer() {
+ clearInterval(countdown);
+ document.getElementById('timer').textContent = 70;
+ countdown = setInterval(updateTimer, 1000);
+}
+
+function updateTimer() {
+ const timerDisplay = document.getElementById('timer');
+
+ const currentTime = parseInt(timerDisplay.textContent, 10);
+ if (currentTime > 0) {
+ timerDisplay.textContent = currentTime - 1;
+ // Call your function here every second
+ } else {
+ clearInterval(countdown);
+ alert('Time run out!');
+ }
+}
+
+
window.onload = function () {
//attack click to new game button
document.
@@ -389,8 +386,8 @@ window.onload = function () {
};
//global vars
-
var game;
+var countdown
//check support for local storage: credit - http://diveintohtml5.info/storage.html
const hasLocalStorage = function () {