Russian Minesweeper - multiplayer version of the game "Minesweeper"
Hello dear readers. I sincerely hope that among the readers of Habr there will be lovers of such a wonderful game as Minesweeper .
If I remember correctly, then for the first time this game appeared on the Windows 3.1 operating system back in the 1994th year. At that time, this game was positioned as a tool for teaching the use of a computer mouse and, in general, the graphical interface of the OS. It looked something like this:
The principle of the game according to Wikipedia
A flat or three-dimensional playing field is divided into adjacent cells (squares, hexagons, cubes, etc.), some of which are “mined”; the number of "mined" cells is known. The aim of the game is to open all cells that do not contain mines.
The player opens the cells, trying not to open the cell with the mine. Opening a cell with a mine, he loses. Mines are placed after the first move, so it is impossible to lose on the first move. If there is no mine under the open cell, then a number appears in it showing how many cells adjacent to the just opened one are “mined” (in each version of the game, the neighborhood is determined in its own way); using these numbers, the player tries to calculate the location of the mines, but sometimes even in the middle and at the end of the game some cells still have to be opened at random. If there are no mines under the neighboring cells, then a certain “non-mined” area opens up to the cells in which there are numbers. The player can mark the “mined” cells so as not to accidentally open them. Having opened all the "non-mined" cells, the player wins.
The player opens the cells, trying not to open the cell with the mine. Opening a cell with a mine, he loses. Mines are placed after the first move, so it is impossible to lose on the first move. If there is no mine under the open cell, then a number appears in it showing how many cells adjacent to the just opened one are “mined” (in each version of the game, the neighborhood is determined in its own way); using these numbers, the player tries to calculate the location of the mines, but sometimes even in the middle and at the end of the game some cells still have to be opened at random. If there are no mines under the neighboring cells, then a certain “non-mined” area opens up to the cells in which there are numbers. The player can mark the “mined” cells so as not to accidentally open them. Having opened all the "non-mined" cells, the player wins.
However, time goes by, the sapper's popularity is falling, and I want to bring new life and colors to this game. That is how the multiplayer version of the game, named as " Russian Minesweeper ", which is a browser-based online game, was born . Interested, I ask for cat.
Game features
Of course, for a certain number of players to be able to play this game together, the rules will have to be modernized in some way and altered altogether. However, the main rule is to leave the essential principle as in the original.
Thus, in fact, a set of rules was developed to allow several players to simultaneously play on the same field.
The basic rules of the game are as follows:
- The goal of the game is to flag all mines first.
- Each player has their own (local) flags.
- Players have the same (global) field with mines.
- Players take turns ( however, a “parallel” mode is being developed now ).
- If a player clicks on a mine, he will lose, and his opponent will win accordingly.
- Time for the player’s turn is limited (~ 25 sec.) - you must walk as quickly as possible.
- If a player skips a move three times in a row, he will lose, and his opponent will win accordingly.
- If a player misses six moves during the whole game, he will lose, and his opponent will win accordingly.
- A draw is impossible. In any case, one of the players will set flags correctly faster than the other.
- The first move goes to a random player.
- A player may surrender at any time during the game.
A number of characteristics of the minefield for the game have also been developed:
- Undermining the opening of the first cell at the beginning of the game is impossible.
- Mines are evenly distributed across the playing field.
- Properties of the "emptiness" that opens upon first click:
- Size A to B empty cells ( 0 min around ).
- The void should not be a line of open cells on only one of the sides of the orientation.
- The percentage of mine cells ( type of regulator is real ) and the size of the field are regulated in the application settings.
Thus, with the current configuration, the first click opens a “void” of 3 to 12 “zero” cells, and the field is 32x20 in size .
I apologize for the huge number of lists, however, I cannot but mention that the game also has the following functionality:
- Chord - opening more than one cell per turn. This is possible in the case of a click (LMB) on the number in the cell on the playing field, and the number of flags around adjacent cells is equal to the desired number.
- Help the opponent - by the middle mouse button, or [click on the opponent’s nickname on the top + click on the desired cell]. It is displayed in green:
- Chat - between players in real time.
- Nickname in the game.
- Soundtrack in the game.
Technology
The full list of technologies used in product development is as follows:
- C # .NET + ASP .NET is the foundation for the web server.
- HTML5 / CSS3 - for developing the client side interface.
- JavaScript - for the dynamic operation of the client side.
- JSON - for serialization / deserialization of client-server packets.
- WebSocket - the protocol is used as a client-server communication method.
- HTML Canvas is a technology for rendering a minefield.
- jQuery is an efficient and fast interaction between HTML and JS.
- JSON Newton is a library for convenient work with JSON.
- Adobe Photoshop - for rendering graphical interface elements.
- GitHub - as a convenient platform for version control of the project.
- Microsoft Azure - for hosting a web server on the Internet.
- Yandex.Metrica - statistics and analysis of player behavior.
- CloudFlare - as a CDN proxy / SSL / Anti DDoS.
- Microsoft Visual Studio - as the main development environment.
- Sublime Text - as a development tool for JavaScript.
- Microsoft IIS - for deploying ASP. NET
The most problematic places in the project were as follows:
- Sync players with each other
- Problem : how to quickly notify players about changes in the field?
Options: long polling; websockets; cyclic polling; etc - Solution : use WebSocket
- Problem : how to quickly notify players about changes in the field?
- Drawing a minefield and other elements of the game
- Problem : which tools will be most optimal?
Options: HTML table / div; SVG; HTML5 Canvas etc - Solution : HTML5 Canvas + JavaScript
- Problem : which tools will be most optimal?
Interesting numbers
- At least 23 people took part in the testing.
- 183,298 clicks were made across the field during testing.
- From the 119th attempt, the minefield was completed to the end.
- A 32x20 field is most suitable for the game ( empirical observation ).
- From 3 to 12 “zero” cells are best opened at the first click ( empirical observation ).
And also I attach a click map from Yandex.Metrica, a number of interesting conclusions can be made from it. For example, it is obvious that the main area of the “battle” is the center of the field, and chat is popular.
Future plans
In the future, I want to finish the following functionality:
- Implement a room for N players.
- The ability to create a "friendly room" (playing with a friend by reference) and single player mode.
- Player registration and leaderboard.
- "Balance by skill" (so that players play with peers in experience).
- Optimization of the application for mobile devices.
- Switching to more powerful servers for implementing the application to the masses.
- Creating a bug tracker.
- Implementing convenient feedback with players.
- More detailed application usage statistics.
Conclusion
In conclusion, I want to say the following - please be careful with the game server :)
It is received for free by subscription from Microsoft Azure and its capacity is extremely modest.
I sincerely hope that after this article we will be able to enjoy this game together.
I remind you that it is available at https://rmsweeper.com , and there is also a community on VKontakte.
Thank you for your attention
. Peter was with you.
Only registered users can participate in the survey. Please come in.
Do you know how to play classic sapper?
- 92.9% Yes 345
- 7% No 26