summaryrefslogtreecommitdiff
path: root/Userland/Games/Minesweeper/main.cpp
diff options
context:
space:
mode:
authorPedro Pereira <pmh.pereira@gmail.com>2021-11-14 11:53:56 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-15 14:05:03 +0000
commit7b4b060b9ce986ab2870d68e9675fbef4774b467 (patch)
treec4083468b36d7ad025bdc2d2993232862cdef88c /Userland/Games/Minesweeper/main.cpp
parent1c29633110e39d51925616b15ca02dd6e1695b19 (diff)
downloadserenity-7b4b060b9ce986ab2870d68e9675fbef4774b467.zip
Minesweeper: Create field from Difficulty enum
This change makes it easier to generate a new field. Instead of using hard-coded values everywhere, we now just need to keep track of the Difficulty enum value.
Diffstat (limited to 'Userland/Games/Minesweeper/main.cpp')
-rw-r--r--Userland/Games/Minesweeper/main.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/Userland/Games/Minesweeper/main.cpp b/Userland/Games/Minesweeper/main.cpp
index d91186db7e..d8b8237357 100644
--- a/Userland/Games/Minesweeper/main.cpp
+++ b/Userland/Games/Minesweeper/main.cpp
@@ -125,30 +125,30 @@ int main(int argc, char** argv)
difficulty_actions.set_exclusive(true);
auto action = GUI::Action::create_checkable("&Beginner", { Mod_Ctrl, Key_B }, [&](auto&) {
- field.set_field_size(9, 9, 10);
+ field.set_field_difficulty(Field::Difficulty::Beginner);
});
- action->set_checked(field.rows() == 9 && field.columns() == 9 && field.mine_count() == 10);
+ action->set_checked(field.difficulty() == Field::Difficulty::Beginner);
difficulty_menu.add_action(action);
difficulty_actions.add_action(action);
action = GUI::Action::create_checkable("&Intermediate", { Mod_Ctrl, Key_I }, [&](auto&) {
- field.set_field_size(16, 16, 40);
+ field.set_field_difficulty(Field::Difficulty::Intermediate);
});
- action->set_checked(field.rows() == 16 && field.columns() == 16 && field.mine_count() == 40);
+ action->set_checked(field.difficulty() == Field::Difficulty::Intermediate);
difficulty_menu.add_action(action);
difficulty_actions.add_action(action);
action = GUI::Action::create_checkable("&Expert", { Mod_Ctrl, Key_E }, [&](auto&) {
- field.set_field_size(16, 30, 99);
+ field.set_field_difficulty(Field::Difficulty::Expert);
});
- action->set_checked(field.rows() == 16 && field.columns() == 30 && field.mine_count() == 99);
+ action->set_checked(field.difficulty() == Field::Difficulty::Expert);
difficulty_menu.add_action(action);
difficulty_actions.add_action(action);
action = GUI::Action::create_checkable("&Madwoman", { Mod_Ctrl, Key_M }, [&](auto&) {
- field.set_field_size(32, 60, 350);
+ field.set_field_difficulty(Field::Difficulty::Madwoman);
});
- action->set_checked(field.rows() == 32 && field.columns() == 60 && field.mine_count() == 350);
+ action->set_checked(field.difficulty() == Field::Difficulty::Madwoman);
difficulty_menu.add_action(action);
difficulty_actions.add_action(action);
@@ -156,6 +156,7 @@ int main(int argc, char** argv)
action = GUI::Action::create_checkable("&Custom game...", { Mod_Ctrl, Key_C }, [&](auto&) {
CustomGameDialog::show(window, field);
});
+ action->set_checked(field.difficulty() == Field::Difficulty::Custom);
difficulty_menu.add_action(action);
difficulty_actions.add_action(action);