Title: | Mine Sweeper Game |
---|---|
Description: | This is the very popular mine sweeper game! The game requires you to find out tiles that contain mines through clues from unmasking neighboring tiles. Each tile that does not contain a mine shows the number of mines in its adjacent tiles. If you unmask all tiles that do not contain mines, you win the game; if you unmask any tile that contains a mine, you lose the game. For further game instructions, please run `help(run_game)` and check details. This game runs in X11-compatible devices with `grDevices::x11()`. |
Authors: | Xiurui Zhu [aut, cre] |
Maintainer: | Xiurui Zhu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2025-02-24 04:18:30 UTC |
Source: | https://github.com/zhuxr11/minesweepr |
run_game
runs mine sweeper game. It opens a window through x11
.
Please do not run multiple instances (windows) of the game. For game instructions, please check the details.
run_game( n_mine = max(round(0.2 * n_row * n_col), 1L), n_row = 10L, n_col = 10L, unmask_button = 0L, flag_button = 2L, digit_char = format(seq_len(8L), scientific = FALSE), mine_char = "M", flag_char = "F", unmask_color = "#9F9F9F", mask_color = "#3F3F3F", hit_color = "#9F3F3F", wrong_color = "#7F1F7F", digit_color = pals::cols25(n = 8L), mine_color = "black", flag_color = "white", window_title = "Mine Sweeper in R", x11_args = list(), time_prec = 3L, restart_key = "r", exit_key_press = 2L, debug = FALSE )
run_game( n_mine = max(round(0.2 * n_row * n_col), 1L), n_row = 10L, n_col = 10L, unmask_button = 0L, flag_button = 2L, digit_char = format(seq_len(8L), scientific = FALSE), mine_char = "M", flag_char = "F", unmask_color = "#9F9F9F", mask_color = "#3F3F3F", hit_color = "#9F3F3F", wrong_color = "#7F1F7F", digit_color = pals::cols25(n = 8L), mine_color = "black", flag_color = "white", window_title = "Mine Sweeper in R", x11_args = list(), time_prec = 3L, restart_key = "r", exit_key_press = 2L, debug = FALSE )
n_mine , n_row , n_col
|
Integers as numbers of mines/rows/columns in game panel,
|
unmask_button , flag_button
|
Integers as buttons to unmask/flag tiles. Usually, 0 for left mouse button (to unmask) and 2 for right mouse button (to flag). |
digit_char , mine_char , flag_char
|
Characters to mark counts/mines/flags. |
unmask_color , mask_color , hit_color , wrong_color
|
Strings as colors for unmasked tiles / masked tiles / mine-triggering tile / wrongly flagged tiles. |
digit_color , mine_color , flag_color
|
Strings as colors for |
window_title |
String as window title. |
x11_args |
Named list of arguments passed on to |
time_prec |
Integer as time precision (e.g. 0 for seconds or 3 for miliseconds). |
restart_key |
Character as the key to restart game, used when you have won or lost a game. |
exit_key_press |
Integer as the times of boss key presses (boss key is any key
other than |
debug |
Logical, internal use only. |
Game instructions:
All tiles start masked. If you unmask all tiles without mines, you win the game; if you unmask any tiles containing mines, you lose the game.
You may click with unmask_button
on any masked tile to unmask.
The first tile unmasked cannot contain a mine. Timing starts when any tile is unmasked.
Each unmasked tile tells you the number of mines in adjacent tiles, unless itself contains a mine. You may use these numbers to find out the adjacent tiles with mines.
You may click with flag_button
on an unmasked tile to flag it as a possible mine.
Flagged tiles cannot be unmasked, unless you click on them with flag_button
again to remove the flags.
You may click with unmask_button
on any unmasked tile to unmask adjacent unflagged tiles,
after you have set up the number of flags that equals to the count of adjacent mines shown on this tile.
If any unflagged adjacent tiles contain mines, one of them is triggered and you lose the game.
After you win or lose a game, game statistics are recorded.
You may restart game with restart_key
at any time. If you have not won or lost the game,
it is not recorded in game statistics.
You may press boss key (any key other than restart_key
) for
exit_key_press
times
to close game window.
A data.frame
containing game statistics, invisibly, where each row is a game play.
To look at game statistics, save the output of run_game()
to a variable
for later use or run print(run_grame)
to print.
Change log:
0.1.0 Xiurui Zhu - Initiate the function.
Xiurui Zhu
if (interactive() == TRUE) { run_game() }
if (interactive() == TRUE) { run_game() }