"plain": PhotoImage(file = "images/tile_plain.gif"), Minesweeper game javascript code#Python 3 Tkinter Minesweeper Game GUI Desktop App Using Random and Datetime Library With Source Code # Python Version 2.7.3įrom tkinter import messagebox as tkMessageBoxįrom datetime import time, date, datetimeīTN_FLAG = "" if platform.system() = 'Darwin' else "" We hope the doubts will be resolved through this article. The reason for that is that our friends have a lot of doubts. Hello, friend Python 3 Tkinter Minesweeper Game GUI Desktop App Using Random and Datetime Library With Source Code article We are going to know the topic clearly. Python 3 Tkinter Minesweeper Game GUI Desktop App Using Random and Datetime Library With Source Code.var x= index% columns // Convert index into (x,y) coordinates. If( board!=' mine'& picture( index)=" x") // If it's covered and not a mine: revealed++ // If it was uncovered, increase the count of revealed tiles. you win!įunction reveal( index) // Uncover the tile If( revealed= rows* columns- mines) // If all tiles revealed: If((x1>= 0)&(y1>= 0)&(x1 Click here to restart' Įlse if( picture( id)=' x') reveal( id) // otherwise reveal the tile. In either case we display all the mines.įunction check(x1, y1) // this function returns the value of the tile using the (x1,y1) coordinates. The game ends when the player clicks on a tile that contains a mine (lose) or all non-mine tiles are revealed (win). That's probably the most interesting part of this code. The function 'reveal' will call itself recursively, until all the neighboring zero tiles are revealed. If any of the surrounding tiles' value is zero, we'll reveal the tiles surrounding that tile. If the value of the tile equals zero (which means none of the neighboring tiles have a mine), we'll also reveal all the surrounding tiles. When the player left clicks on a covered tile, we'll reveal its contents. These two are only shown after the game is finished:Į.png - a place where a flag was incorrectly placed The image can be:Ġ.png thru 8.png - number of mines in neighboring tiles (blank means zero) "tile", which will consist of dynamically created image (IMG) objects, on which the player will click. "board", which will contain: 'M' for mine or a number 0 thru 8 which is the number of mines in the eight neighboring tiles. The mechanism of uncovering all tiles with zero value is a good exercise in recursive functions - the function calls itself multiple times. Play the game by clicking the tiles on top of the page!Ĭoding this game in Javascript is a lot of fun, since it is a relatively short and easy algorithm, but at the same time quite interesting. This allows you to simulate different scenarios - you can place a question mark and then verify if the neighboring tiles have the correct numbers. A question mark is placed if you suspect a mine might be there, but you're not certain. This reduces the count of mines remaining. You place a flag when you are sure the tile has a mine. Right-clicking on a tile toggles between uncovered, flag and question mark. You repeat the process until all safe tiles are revealed. Based on the revealed numbers, you calculate which of the neighboring tiles contain mines, mark them with a flag and click on the safe ones to reveal them. Otherwise, the tile will show the sum of mines in the eight neighboring tiles. When you click a tile, its content is revealed. The point of the game is to uncover all the tiles except the ones containing the mines. The board consists of rows and columns of tiles, some of which contain a mine. If you're older than 30, let me remind you the rules, since at our age memory no longer serves us well: If you're younger than 30, let me teach you the rules. It probably led to millions of hours of productivity wasted when people played it at work. Minesweeper game javascript windows#Let's bring the 1989 Minesweeper game back to life!Īctually the game is much older, but it gained worldwide fame after it was bundled with Windows 3.1. The Minesweeper game in 80 lines of Javascript
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |