diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-26 19:54:31 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-26 19:54:31 +0200 |
commit | 146aedc32cd90bbf7a6b6fa8646311114c0b86ac (patch) | |
tree | ab17c28e9ec3329d543a94f411231de0536eb101 /Games/Minesweeper/main.cpp | |
parent | e90b501b319e1e4dbb3966b540851d913126f176 (diff) | |
download | serenity-146aedc32cd90bbf7a6b6fa8646311114c0b86ac.zip |
Minesweeper: Implement some feature requests.
Someone was playing this game and suggested a number of improvements so here
we go trying to address them:
- Add "chording" support, where you can click a numbered square using both
mouse buttons simultaneously to sweep all non-flagged adjacent squares.
- Mis-flagged squares are now revealed as such on game over, with a special
"bad flag" icon.
- The game timer now shows tenths of seconds. It also doesn't start until
you click the first square.
- Add the three difficulty modes from the classic Windows version.
Diffstat (limited to 'Games/Minesweeper/main.cpp')
-rw-r--r-- | Games/Minesweeper/main.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index d1771b70ad..88c62da9a8 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -7,6 +7,7 @@ #include <LibGUI/GMenuBar.h> #include <LibGUI/GAction.h> #include <LibGUI/GLabel.h> +#include <LibCore/CConfigFile.h> int main(int argc, char** argv) { @@ -31,11 +32,28 @@ int main(int argc, char** argv) flag_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/flag.png")); auto* flag_label = new GLabel(container); auto* face_button = new GButton(container); + face_button->set_button_style(ButtonStyle::CoolBar); + face_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); + face_button->set_preferred_size({ 36, 0 }); auto* time_icon_label = new GLabel(container); time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png")); auto* time_label = new GLabel(container); auto* field = new Field(*flag_label, *time_label, *face_button, widget); + field->on_size_changed = [&] { + auto size = field->preferred_size(); + size.set_height(size.height() + container->preferred_size().height()); + window->resize(size); + }; + + { + auto config = CConfigFile::get_for_app("Minesweeper"); + int mine_count = config->read_num_entry("Game", "MineCount", 10); + int rows = config->read_num_entry("Game", "Rows", 9); + int columns = config->read_num_entry("Game", "Columns", 9); + field->set_field_size(rows, columns, mine_count); + } + auto menubar = make<GMenuBar>(); auto app_menu = make<GMenu>("Minesweeper"); @@ -49,6 +67,16 @@ int main(int argc, char** argv) game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [field] (const GAction&) { field->reset(); })); + game_menu->add_separator(); + game_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [field] (const GAction&) { + field->set_field_size(9, 9, 10); + })); + game_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [field] (const GAction&) { + field->set_field_size(16, 16, 40); + })); + game_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [field] (const GAction&) { + field->set_field_size(16, 30, 99); + })); menubar->add_menu(move(game_menu)); auto help_menu = make<GMenu>("Help"); |