Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minesweeper win and lose faces #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion programs/minesweeper/face.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ minesweeper.face.prototype.get_element = function() {
this.element = $.createElement("div")
.style({"width": 26, "height": 26, "margin": "auto", "background-image": minesweeper.sprite, "background-repeat": "no-repeat"})
.addEventListener("mousedown", function() {
if(self.state === "smile") self.set_state("depressed_smile");
self.set_state("depressed_smile");
})
.addEventListener("mouseup", function() {
if(self.state === "depressed_smile") {
Expand Down
2 changes: 2 additions & 0 deletions programs/minesweeper/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var set_difficulty = function(difficulty){
height: extra_height + tile_size * difficulty[1],
});
}
// got this from the $menu_bar close_menu function
$menu_bar.find(".menu-button").trigger("release");
};
var is_at_difficulty = function(difficulty){
return (
Expand Down
12 changes: 8 additions & 4 deletions programs/minesweeper/minesweeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,23 @@ minesweeper.prototype.new_game = function(width, height, number_mines) {

var face = new minesweeper.face(this, this.header_td_face);

this.face = face;

this.play_table.removeEventListener("mousedown,mouseup").style({"cursor": "default", "border": "1px solid #444"});
this.play_table
.addEventListener("mousedown", function(e) {
if(e.target === face.get_element()) return false;
if(e.which === 1) face.set_state("scared");
if(e.which === 1 && !self.game_over) face.set_state("scared");
})
.addEventListener("mouseup", function(e) {
face.set_state("smile");
if(!self.game_over) face.set_state("smile");
});

this.mine_counter = new minesweeper.ssd(this.header_td_mine_count, number_mines)
var timer = new minesweeper.ssd(this.header_td_timer, 0);

this.timer_interval = setInterval(function() { timer.increment(); }, 1000);

;
this.grid = new minesweeper.grid(this, this.grid_area, width, height, face);
this.grid.generate(number_mines);
}
Expand All @@ -141,12 +143,14 @@ minesweeper.prototype.lose = function() {
if(!this.game_over) {
clearInterval(this.timer_interval);
this.game_over = true;
this.face.set_state("dead");
// alert('You lose!');
}
}
minesweeper.prototype.win = function() {
if(!this.game_over) {
clearInterval(this.timer_interval);
this.face.set_state("sunglasses");
this.game_over = true;
// alert('You win!');
}
Expand Down Expand Up @@ -238,7 +242,7 @@ $.ready(function() {
}

}
else { // Single tile reveals are simple
else if(!minesweeper_.game_over) { // Single tile reveals are simple
minesweeper_.grid.reveal_area(click_coordinates.x, click_coordinates.y);
}

Expand Down