Explorar o código

Merge minesweeper from https://github.com/xMasterX/all-the-plugins

# Conflicts:
#	minesweeper/README.md
Willy-JL %!s(int64=2) %!d(string=hai) anos
pai
achega
93a003d47f
Modificáronse 87 ficheiros con 4085 adicións e 1417 borrados
  1. 21 674
      minesweeper/LICENSE
  2. 63 12
      minesweeper/README.md
  3. 16 8
      minesweeper/application.fam
  4. 0 144
      minesweeper/assets.h
  5. 0 0
      minesweeper/assets/.gitkeep
  6. BIN=BIN
      minesweeper/assets/Cry_dolph_55x52.png
  7. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_01.png
  8. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_02.png
  9. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_03.png
  10. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_04.png
  11. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_05.png
  12. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_06.png
  13. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_07.png
  14. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_08.png
  15. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_09.png
  16. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_10.png
  17. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_11.png
  18. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_12.png
  19. BIN=BIN
      minesweeper/assets/StartScreen_128x64/frame_13.png
  20. 1 0
      minesweeper/assets/StartScreen_128x64/frame_rate
  21. 0 48
      minesweeper/assets/asset
  22. BIN=BIN
      minesweeper/assets/minesweeper.png
  23. BIN=BIN
      minesweeper/assets/mockup.png
  24. 0 4
      minesweeper/assets/tile_0.xbm
  25. 0 0
      minesweeper/assets/tile_0_8x8.png
  26. 0 4
      minesweeper/assets/tile_1.xbm
  27. 0 0
      minesweeper/assets/tile_1_8x8.png
  28. 0 4
      minesweeper/assets/tile_2.xbm
  29. 0 0
      minesweeper/assets/tile_2_8x8.png
  30. 0 4
      minesweeper/assets/tile_3.xbm
  31. 0 0
      minesweeper/assets/tile_3_8x8.png
  32. 0 4
      minesweeper/assets/tile_4.xbm
  33. 0 0
      minesweeper/assets/tile_4_8x8.png
  34. 0 4
      minesweeper/assets/tile_5.xbm
  35. 0 0
      minesweeper/assets/tile_5_8x8.png
  36. 0 4
      minesweeper/assets/tile_6.xbm
  37. 0 0
      minesweeper/assets/tile_6_8x8.png
  38. 0 4
      minesweeper/assets/tile_7.xbm
  39. 0 0
      minesweeper/assets/tile_7_8x8.png
  40. 0 4
      minesweeper/assets/tile_8.xbm
  41. 0 0
      minesweeper/assets/tile_8_8x8.png
  42. 0 0
      minesweeper/assets/tile_empty_8x8.png
  43. 0 4
      minesweeper/assets/tile_flag.xbm
  44. 0 0
      minesweeper/assets/tile_flag_8x8.png
  45. BIN=BIN
      minesweeper/assets/tile_mine.png
  46. 0 4
      minesweeper/assets/tile_mine.xbm
  47. BIN=BIN
      minesweeper/assets/tile_mine_8x8.png
  48. 0 4
      minesweeper/assets/tile_uncleared.xbm
  49. 0 0
      minesweeper/assets/tile_uncleared_8x8.png
  50. 32 0
      minesweeper/docs/changelog.md
  51. 50 0
      minesweeper/helpers/mine_sweeper_haptic.c
  52. 17 0
      minesweeper/helpers/mine_sweeper_haptic.h
  53. 61 0
      minesweeper/helpers/mine_sweeper_led.c
  54. 15 0
      minesweeper/helpers/mine_sweeper_led.h
  55. 64 0
      minesweeper/helpers/mine_sweeper_speaker.c
  56. 18 0
      minesweeper/helpers/mine_sweeper_speaker.h
  57. 143 0
      minesweeper/helpers/mine_sweeper_storage.c
  58. 27 0
      minesweeper/helpers/mine_sweeper_storage.h
  59. BIN=BIN
      minesweeper/img/1.png
  60. BIN=BIN
      minesweeper/img/2.png
  61. 27 0
      minesweeper/img/SIMPLEREADME.md
  62. BIN=BIN
      minesweeper/img/github_images/MineSweeperGameplay.gif
  63. BIN=BIN
      minesweeper/img/github_images/StartScreenAnimationGif.gif
  64. BIN=BIN
      minesweeper/img/screenshot.png
  65. BIN=BIN
      minesweeper/img/screenshot1.png
  66. BIN=BIN
      minesweeper/img/screenshot2.png
  67. BIN=BIN
      minesweeper/img/screenshot3.png
  68. BIN=BIN
      minesweeper/img/screenshot4.png
  69. BIN=BIN
      minesweeper/img/screenshot5.png
  70. 123 483
      minesweeper/minesweeper.c
  71. 96 0
      minesweeper/minesweeper.h
  72. BIN=BIN
      minesweeper/minesweeper_icon.png
  73. 12 0
      minesweeper/scenes/README.md
  74. 103 0
      minesweeper/scenes/confirmation_scene.c
  75. 40 0
      minesweeper/scenes/game_screen_scene.c
  76. 72 0
      minesweeper/scenes/info_scene.c
  77. 103 0
      minesweeper/scenes/menu_scene.c
  78. 30 0
      minesweeper/scenes/minesweeper_scene.c
  79. 32 0
      minesweeper/scenes/minesweeper_scene.h
  80. 6 0
      minesweeper/scenes/minesweeper_scene_config.h
  81. 363 0
      minesweeper/scenes/settings_scene.c
  82. 84 0
      minesweeper/scenes/start_screen_scene.c
  83. 1761 0
      minesweeper/views/minesweeper_game_screen.c
  84. 103 0
      minesweeper/views/minesweeper_game_screen.h
  85. 125 0
      minesweeper/views/minesweeper_game_screen_i.h
  86. 321 0
      minesweeper/views/start_screen.c
  87. 156 0
      minesweeper/views/start_screen.h

+ 21 - 674
minesweeper/LICENSE

@@ -1,674 +1,21 @@
-                    GNU GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-                            Preamble
-
-  The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
-  The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works.  By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.  We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors.  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
-  To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights.  Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received.  You must make sure that they, too, receive
-or can get the source code.  And you must show them these terms so they
-know their rights.
-
-  Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
-  For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software.  For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
-  Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so.  This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software.  The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable.  Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products.  If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
-  Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary.  To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-                       TERMS AND CONDITIONS
-
-  0. Definitions.
-
-  "This License" refers to version 3 of the GNU General Public License.
-
-  "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
-  "The Program" refers to any copyrightable work licensed under this
-License.  Each licensee is addressed as "you".  "Licensees" and
-"recipients" may be individuals or organizations.
-
-  To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy.  The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
-  A "covered work" means either the unmodified Program or a work based
-on the Program.
-
-  To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy.  Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
-  To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies.  Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
-  An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License.  If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
-  1. Source Code.
-
-  The "source code" for a work means the preferred form of the work
-for making modifications to it.  "Object code" means any non-source
-form of a work.
-
-  A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
-  The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form.  A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
-  The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities.  However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work.  For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
-  The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
-  The Corresponding Source for a work in source code form is that
-same work.
-
-  2. Basic Permissions.
-
-  All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met.  This License explicitly affirms your unlimited
-permission to run the unmodified Program.  The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work.  This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
-  You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force.  You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright.  Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
-  Conveying under any other circumstances is permitted solely under
-the conditions stated below.  Sublicensing is not allowed; section 10
-makes it unnecessary.
-
-  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
-  No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
-  When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
-  4. Conveying Verbatim Copies.
-
-  You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
-  You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
-  5. Conveying Modified Source Versions.
-
-  You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
-    a) The work must carry prominent notices stating that you modified
-    it, and giving a relevant date.
-
-    b) The work must carry prominent notices stating that it is
-    released under this License and any conditions added under section
-    7.  This requirement modifies the requirement in section 4 to
-    "keep intact all notices".
-
-    c) You must license the entire work, as a whole, under this
-    License to anyone who comes into possession of a copy.  This
-    License will therefore apply, along with any applicable section 7
-    additional terms, to the whole of the work, and all its parts,
-    regardless of how they are packaged.  This License gives no
-    permission to license the work in any other way, but it does not
-    invalidate such permission if you have separately received it.
-
-    d) If the work has interactive user interfaces, each must display
-    Appropriate Legal Notices; however, if the Program has interactive
-    interfaces that do not display Appropriate Legal Notices, your
-    work need not make them do so.
-
-  A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit.  Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
-  6. Conveying Non-Source Forms.
-
-  You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
-    a) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by the
-    Corresponding Source fixed on a durable physical medium
-    customarily used for software interchange.
-
-    b) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by a
-    written offer, valid for at least three years and valid for as
-    long as you offer spare parts or customer support for that product
-    model, to give anyone who possesses the object code either (1) a
-    copy of the Corresponding Source for all the software in the
-    product that is covered by this License, on a durable physical
-    medium customarily used for software interchange, for a price no
-    more than your reasonable cost of physically performing this
-    conveying of source, or (2) access to copy the
-    Corresponding Source from a network server at no charge.
-
-    c) Convey individual copies of the object code with a copy of the
-    written offer to provide the Corresponding Source.  This
-    alternative is allowed only occasionally and noncommercially, and
-    only if you received the object code with such an offer, in accord
-    with subsection 6b.
-
-    d) Convey the object code by offering access from a designated
-    place (gratis or for a charge), and offer equivalent access to the
-    Corresponding Source in the same way through the same place at no
-    further charge.  You need not require recipients to copy the
-    Corresponding Source along with the object code.  If the place to
-    copy the object code is a network server, the Corresponding Source
-    may be on a different server (operated by you or a third party)
-    that supports equivalent copying facilities, provided you maintain
-    clear directions next to the object code saying where to find the
-    Corresponding Source.  Regardless of what server hosts the
-    Corresponding Source, you remain obligated to ensure that it is
-    available for as long as needed to satisfy these requirements.
-
-    e) Convey the object code using peer-to-peer transmission, provided
-    you inform other peers where the object code and Corresponding
-    Source of the work are being offered to the general public at no
-    charge under subsection 6d.
-
-  A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
-  A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling.  In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage.  For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product.  A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
-  "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source.  The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
-  If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information.  But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
-  The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed.  Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
-  Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
-  7. Additional Terms.
-
-  "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law.  If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
-  When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it.  (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.)  You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
-  Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
-    a) Disclaiming warranty or limiting liability differently from the
-    terms of sections 15 and 16 of this License; or
-
-    b) Requiring preservation of specified reasonable legal notices or
-    author attributions in that material or in the Appropriate Legal
-    Notices displayed by works containing it; or
-
-    c) Prohibiting misrepresentation of the origin of that material, or
-    requiring that modified versions of such material be marked in
-    reasonable ways as different from the original version; or
-
-    d) Limiting the use for publicity purposes of names of licensors or
-    authors of the material; or
-
-    e) Declining to grant rights under trademark law for use of some
-    trade names, trademarks, or service marks; or
-
-    f) Requiring indemnification of licensors and authors of that
-    material by anyone who conveys the material (or modified versions of
-    it) with contractual assumptions of liability to the recipient, for
-    any liability that these contractual assumptions directly impose on
-    those licensors and authors.
-
-  All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10.  If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term.  If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
-  If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
-  Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
-  8. Termination.
-
-  You may not propagate or modify a covered work except as expressly
-provided under this License.  Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
-  However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
-  Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
-  Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License.  If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
-  9. Acceptance Not Required for Having Copies.
-
-  You are not required to accept this License in order to receive or
-run a copy of the Program.  Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance.  However,
-nothing other than this License grants you permission to propagate or
-modify any covered work.  These actions infringe copyright if you do
-not accept this License.  Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
-  10. Automatic Licensing of Downstream Recipients.
-
-  Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License.  You are not responsible
-for enforcing compliance by third parties with this License.
-
-  An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations.  If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
-  You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License.  For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
-  11. Patents.
-
-  A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based.  The
-work thus licensed is called the contributor's "contributor version".
-
-  A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version.  For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
-  Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
-  In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement).  To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
-  If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients.  "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
-  If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
-  A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License.  You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
-  Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
-  12. No Surrender of Others' Freedom.
-
-  If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all.  For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
-  13. Use with the GNU Affero General Public License.
-
-  Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work.  The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
-  14. Revised Versions of this License.
-
-  The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-  Each version is given a distinguishing version number.  If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation.  If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
-  If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
-  Later license versions may give you additional or different
-permissions.  However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
-  15. Disclaimer of Warranty.
-
-  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-  16. Limitation of Liability.
-
-  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
-  17. Interpretation of Sections 15 and 16.
-
-  If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
-  If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
-    <program>  Copyright (C) <year>  <name of author>
-    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
-  You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<https://www.gnu.org/licenses/>.
-
-  The GNU General Public License does not permit incorporating your program
-into proprietary programs.  If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.  But first, please read
-<https://www.gnu.org/licenses/why-not-lgpl.html>.
+MIT License
+
+Copyright (c) 2024 Alexander Rodriguez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 63 - 12
minesweeper/README.md

@@ -1,18 +1,69 @@
-# Minesweeper
 
-This is a Minesweeper implementation for the Flipper Zero device.
 
-![screenshot](img/screenshot.png)
 
-## Controls
+# Minesweeper Implementation for the Flipper Zero.
+Hello!
 
-- Arrow buttons to move
-- Push center button to open field
-- Hold center button to toggle flag
-- Push center button on an already open field that has the correct amount of flags surrounding it to auto-open the remaining ones (thanks @gelin!)
+![Mine Sweeper Example Gameplay Gif](https://github.com/squee72564/F0_Minesweeper_Fap/blob/main/img/github_images/MineSweeperGameplay.gif)
+## Added features unique to this implementation:
+-	Enable board verifier for board generation to ensure unambiguous boards!
+-	Set board width and height
+-	Set difficulty
+-	A number of different button presses as shortcuts for game actions (see How To Play) 
 
-## Compiling
+## Installation
+1. Clone this repo to your computer ie:
+	`git clone https://github.com/squee72564/F0_Minesweeper_Fap.git`
+3. I would recommend using the [uFBT (micro Flipper Build Tool)](https://github.com/flipperdevices/flipperzero-ufbt) to build the application.
+	- It allows you to compile into .fap files on the SD card as opposed to re-flashing the entire firmware with the application.
+	- With uFBT installed you can go into the root directory of this project after cloning and type
+	`ufbt launch` to compile and launch the app on your Flipper Zero
+4. Profit
 
-```
-./fbt firmware_minesweeper
-```
+## How To Play
+- Up/Down/Left/Right Buttons to move around
+	- These buttons can be held down to keep moving in a direction
+- Center OK Button to attempt opening up a tile
+	- Press OK on a tile to open it up
+	- Hold OK on a cleared space with a number to clear all surrounding tiles (correct number of flags must be set around it)
+- Hold Back Button on a tile to toggle marking it with a flag
+- Hold Back Button on a cleared space to jump to one of the closest tiles (this can help find last tiles on a larger board)
+- Press Back Button to access the settings menu where you can do the following:
+	- Change board width
+	- Change board height
+	- Change difficulty
+	- Ensure Solvable (**Important!**)- This option will enable the board verifier for board generation and can significantly increase wait times for generating a board. Currently this may lock up the view port on the loading animation, but it should eventually resolve and return to the game.
+
+## IMPORTANT NOTICE:
+The way I set the board up leaves the corners as safe starting positions!
+
+In addition to this, with the "Ensure Solvable" option set to true, the board will always be solvable from 0,0! Without Ensure Solvable enabled in the settings the mine placement for the board generation is randomized and there is no guarantee that the game with be solvable without any guesses.
+
+## Application Structure
+The following is the application structure with a breakdown of each folder:
+-  **[F0_Minesweeper_Fap/](https://github.com/squee72564/F0_Minesweeper_Fap)**
+	- [github/workflows/](https://github.com/squee72564/F0_Minesweeper_Fap/tree/main/.github/workflows)
+		- Github workflows folder
+	- [dist/](https://github.com/squee72564/F0_Minesweeper_Fap/tree/main/dist)
+		-  Contains .fap file for game when compiled
+	- [images/](https://github.com/squee72564/F0_Minesweeper_Fap/tree/main/images)
+		-  Contains all custom image assets used for game
+	- [scenes/](https://github.com/squee72564/F0_Minesweeper_Fap/tree/main/scenes)
+		- Contains `minesweeper_scene.c`, `minesweeper_scene.h`, and `minesweeper_scene_config.h` files to automate creation of scene FP arrays and Scene enumeration types. View the `.README` in this folder for more information on adding new scenes.
+		-  Contains the enter/event/exit functions for each scene used in a .c file
+	- [views/](https://github.com/squee72564/F0_Minesweeper_Fap/tree/main/views)
+		-  Contains the .c and .h files for any custom views used.
+		- Right now there is the StartScreen custom view built for the game. 
+	- minesweeper.c / minesweeper.h
+		- Main Mine Sweeper App .c and .h file
+	- application.fam
+		- [Build system manifest file](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/AppManifests.md#application-definition) for the application
+
+
+Right now the current structure of the application is heavily inspired from [leedave's](https://github.com/leedave/flipper-zero-fap-boilerplate) boilerplate repo.
+
+
+## TODO
+- Multi-threading for board verifier for faster solvable board generation
+- Maybe trying to further optimize the board verification algorithm if possible
+	- I could try adding all of the corners to the starting positions for the verifier and see if this works better; although it is more simple for the user to just start from tile 0,0 and go from there.

+ 16 - 8
minesweeper/application.fam

@@ -1,14 +1,22 @@
+# For details & more options, see documentation/AppManifests.md in firmware repo
+
 App(
-    appid="minesweeper",
-    name="Minesweeper",
+    appid="minesweeper_redux",  # Must be unique
+    name="Mine Sweeper",  # Displayed in menus
     apptype=FlipperAppType.EXTERNAL,
     entry_point="minesweeper_app",
-    requires=["gui"],
-    stack_size=8 * 1024,
+    cdefines=["APP_MINESWEEPER"],
+    requires=[
+        "gui",
+        "storage",  # Require if we do any r/w to storage
+    ],
+    stack_size=2 * 1024,
+    fap_icon_assets="assets",  # Image assets to compile for this application
+    fap_icon="assets/minesweeper.png",  # 10x10 1-bit PNG
     fap_category="Games",
-    fap_icon="minesweeper_icon.png",
-    order=35,
-    fap_author="@panki27 & @xMasterX",
+    # Optional values
     fap_version="1.1",
-    fap_description="Minesweeper Game",
+    fap_description="Flipper Zero Minesweeper Implementation",
+    fap_author="Alexander Rodriguez",
+    fap_weburl="https://github.com/squee72564/F0_Minesweeper_Fap",
 )

+ 0 - 144
minesweeper/assets.h

@@ -1,144 +0,0 @@
-#define tile_0_width 8
-#define tile_0_height 8
-static uint8_t tile_0_bits[] = {
-    0x00,
-    0x00,
-    0x00,
-    0x00,
-    0x00,
-    0x00,
-    0x00,
-    0x00,
-};
-#define tile_1_width 8
-#define tile_1_height 8
-static uint8_t tile_1_bits[] = {
-    0x00,
-    0x10,
-    0x18,
-    0x10,
-    0x10,
-    0x10,
-    0x10,
-    0x00,
-};
-#define tile_2_width 8
-#define tile_2_height 8
-static uint8_t tile_2_bits[] = {
-    0x00,
-    0x1C,
-    0x20,
-    0x20,
-    0x18,
-    0x04,
-    0x3C,
-    0x00,
-};
-#define tile_3_width 8
-#define tile_3_height 8
-static uint8_t tile_3_bits[] = {
-    0x00,
-    0x1C,
-    0x20,
-    0x20,
-    0x18,
-    0x20,
-    0x1C,
-    0x00,
-};
-#define tile_4_width 8
-#define tile_4_height 8
-static uint8_t tile_4_bits[] = {
-    0x00,
-    0x04,
-    0x14,
-    0x14,
-    0x3C,
-    0x10,
-    0x10,
-    0x00,
-};
-#define tile_5_width 8
-#define tile_5_height 8
-static uint8_t tile_5_bits[] = {
-    0x00,
-    0x3C,
-    0x04,
-    0x1C,
-    0x20,
-    0x20,
-    0x1C,
-    0x00,
-};
-#define tile_6_width 8
-#define tile_6_height 8
-static uint8_t tile_6_bits[] = {
-    0x00,
-    0x18,
-    0x24,
-    0x04,
-    0x1C,
-    0x24,
-    0x18,
-    0x00,
-};
-#define tile_7_width 8
-#define tile_7_height 8
-static uint8_t tile_7_bits[] = {
-    0x00,
-    0x3C,
-    0x20,
-    0x20,
-    0x10,
-    0x08,
-    0x08,
-    0x00,
-};
-#define tile_8_width 8
-#define tile_8_height 8
-static uint8_t tile_8_bits[] = {
-    0x00,
-    0x18,
-    0x24,
-    0x18,
-    0x24,
-    0x24,
-    0x18,
-    0x00,
-};
-#define tile_flag_width 8
-#define tile_flag_height 8
-static uint8_t tile_flag_bits[] = {
-    0xFF,
-    0x81,
-    0xB9,
-    0x89,
-    0x89,
-    0x9D,
-    0x81,
-    0xFF,
-};
-#define tile_mine_width 8
-#define tile_mine_height 8
-static uint8_t tile_mine_bits[] = {
-    0x55,
-    0xAA,
-    0x55,
-    0xAA,
-    0x55,
-    0xAA,
-    0x55,
-    0xAA,
-};
-#define tile_uncleared_width 8
-#define tile_uncleared_height 8
-static uint8_t tile_uncleared_bits[] = {
-    0xFF,
-    0x81,
-    0x81,
-    0x81,
-    0x81,
-    0x81,
-    0x81,
-    0xFF,
-};

+ 0 - 0
minesweeper/assets/.gitkeep


BIN=BIN
minesweeper/assets/Cry_dolph_55x52.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_01.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_02.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_03.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_04.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_05.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_06.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_07.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_08.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_09.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_10.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_11.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_12.png


BIN=BIN
minesweeper/assets/StartScreen_128x64/frame_13.png


+ 1 - 0
minesweeper/assets/StartScreen_128x64/frame_rate

@@ -0,0 +1 @@
+3

+ 0 - 48
minesweeper/assets/asset

@@ -1,48 +0,0 @@
-#define tile_0_width 8
-#define tile_0_height 8
-static uint8_t tile_0_bits[] = {
-  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
-#define tile_1_width 8
-#define tile_1_height 8
-static uint8_t tile_1_bits[] = {
-  0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, };
-#define tile_2_width 8
-#define tile_2_height 8
-static uint8_t tile_2_bits[] = {
-  0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, };
-#define tile_3_width 8
-#define tile_3_height 8
-static uint8_t tile_3_bits[] = {
-  0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, };
-#define tile_4_width 8
-#define tile_4_height 8
-static uint8_t tile_4_bits[] = {
-  0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, };
-#define tile_5_width 8
-#define tile_5_height 8
-static uint8_t tile_5_bits[] = {
-  0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, };
-#define tile_6_width 8
-#define tile_6_height 8
-static uint8_t tile_6_bits[] = {
-  0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, };
-#define tile_7_width 8
-#define tile_7_height 8
-static uint8_t tile_7_bits[] = {
-  0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, };
-#define tile_8_width 8
-#define tile_8_height 8
-static uint8_t tile_8_bits[] = {
-  0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, };
-#define tile_flag_width 8
-#define tile_flag_height 8
-static uint8_t tile_flag_bits[] = {
-  0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, };
-#define tile_mine_width 8
-#define tile_mine_height 8
-static uint8_t tile_mine_bits[] = {
-  0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, };
-#define tile_uncleared_width 8
-#define tile_uncleared_height 8
-static uint8_t tile_uncleared_bits[] = {
-  0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, };

BIN=BIN
minesweeper/assets/minesweeper.png


BIN=BIN
minesweeper/assets/mockup.png


+ 0 - 4
minesweeper/assets/tile_0.xbm

@@ -1,4 +0,0 @@
-#define tile_0_width 8
-#define tile_0_height 8
-static char tile_0_bits[] = {
-  0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, };

+ 0 - 0
minesweeper/assets/tile_0.png → minesweeper/assets/tile_0_8x8.png


+ 0 - 4
minesweeper/assets/tile_1.xbm

@@ -1,4 +0,0 @@
-#define tile_1_width 8
-#define tile_1_height 8
-static uint8_t tile_1_bits[] = {
-  0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, };

+ 0 - 0
minesweeper/assets/tile_1.png → minesweeper/assets/tile_1_8x8.png


+ 0 - 4
minesweeper/assets/tile_2.xbm

@@ -1,4 +0,0 @@
-#define tile_2_width 8
-#define tile_2_height 8
-static uint8_t tile_2_bits[] = {
-  0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, };

+ 0 - 0
minesweeper/assets/tile_2.png → minesweeper/assets/tile_2_8x8.png


+ 0 - 4
minesweeper/assets/tile_3.xbm

@@ -1,4 +0,0 @@
-#define tile_3_width 8
-#define tile_3_height 8
-static uint8_t tile_3_bits[] = {
-  0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, };

+ 0 - 0
minesweeper/assets/tile_3.png → minesweeper/assets/tile_3_8x8.png


+ 0 - 4
minesweeper/assets/tile_4.xbm

@@ -1,4 +0,0 @@
-#define tile_4_width 8
-#define tile_4_height 8
-static uint8_t tile_4_bits[] = {
-  0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, };

+ 0 - 0
minesweeper/assets/tile_4.png → minesweeper/assets/tile_4_8x8.png


+ 0 - 4
minesweeper/assets/tile_5.xbm

@@ -1,4 +0,0 @@
-#define tile_5_width 8
-#define tile_5_height 8
-static uint8_t tile_5_bits[] = {
-  0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, };

+ 0 - 0
minesweeper/assets/tile_5.png → minesweeper/assets/tile_5_8x8.png


+ 0 - 4
minesweeper/assets/tile_6.xbm

@@ -1,4 +0,0 @@
-#define tile_6_width 8
-#define tile_6_height 8
-static uint8_t tile_6_bits[] = {
-  0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, };

+ 0 - 0
minesweeper/assets/tile_6.png → minesweeper/assets/tile_6_8x8.png


+ 0 - 4
minesweeper/assets/tile_7.xbm

@@ -1,4 +0,0 @@
-#define tile_7_width 8
-#define tile_7_height 8
-static uint8_t tile_7_bits[] = {
-  0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, };

+ 0 - 0
minesweeper/assets/tile_7.png → minesweeper/assets/tile_7_8x8.png


+ 0 - 4
minesweeper/assets/tile_8.xbm

@@ -1,4 +0,0 @@
-#define tile_8_width 8
-#define tile_8_height 8
-static uint8_t tile_8_bits[] = {
-  0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, };

+ 0 - 0
minesweeper/assets/tile_8.png → minesweeper/assets/tile_8_8x8.png


+ 0 - 0
minesweeper/assets/tile_empty.png → minesweeper/assets/tile_empty_8x8.png


+ 0 - 4
minesweeper/assets/tile_flag.xbm

@@ -1,4 +0,0 @@
-#define tile_flag_width 8
-#define tile_flag_height 8
-static uint8_t tile_flag_bits[] = {
-  0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, };

+ 0 - 0
minesweeper/assets/tile_flag.png → minesweeper/assets/tile_flag_8x8.png


BIN=BIN
minesweeper/assets/tile_mine.png


+ 0 - 4
minesweeper/assets/tile_mine.xbm

@@ -1,4 +0,0 @@
-#define tile_mine_width 8
-#define tile_mine_height 8
-static uint8_t tile_mine_bits[] = {
-  0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, };

BIN=BIN
minesweeper/assets/tile_mine_8x8.png


+ 0 - 4
minesweeper/assets/tile_uncleared.xbm

@@ -1,4 +0,0 @@
-#define tile_uncleared_width 8
-#define tile_uncleared_height 8
-static uint8_t tile_uncleared_bits[] = {
-  0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, };

+ 0 - 0
minesweeper/assets/tile_uncleared.png → minesweeper/assets/tile_uncleared_8x8.png


+ 32 - 0
minesweeper/docs/changelog.md

@@ -0,0 +1,32 @@
+
+# Changelog
+## TODO:
+- Add settings options to toggle hardware feedback
+- Maybe take a look at the board verifier algo and try to make faster/multi-thread or anything to allow better maps
+
+## Version 1.1.0 - 1/11/2024
+
+Added haptic / led functionality
+
+## Added
+- Haptic feedback on all button presses.
+    - Out of bounds movement
+    - Ok to clear tiles
+    - Holding back for flags
+    - Different haptic feedback on win/loss
+- LED changes on win loss
+    - Initially LED is just reset
+    - Set to red on loss
+    - Set to blue on win
+- Sound on some presses
+
+## Version 1.0.0 - 1/10/2024
+
+Initial Full release for the game.
+
+## Added
+- Mine sweeper game with settings menu to choose variable board dimensions from 16x7 to 32x32.
+- Ability to set difficulty, width, and height for the game board in settings.
+- Ability to enable solvable boards only
+- The core game functionality is complete for the game with multiple types of button presses registered for different inputs.
+- The game will save your settings (besides "enable solvable") when you leave the game.

+ 50 - 0
minesweeper/helpers/mine_sweeper_haptic.c

@@ -0,0 +1,50 @@
+#include "mine_sweeper_haptic.h"
+#include "../minesweeper.h"
+
+
+void mine_sweeper_play_happy_bump(void* context) {
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_set_vibro_on);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
+    notification_message(app->notification, &sequence_reset_vibro);
+}
+
+void mine_sweeper_play_long_ok_bump(void* context) {
+    MineSweeperApp* app = context;
+
+    for (int i = 0; i < 2; i++) {
+        notification_message(app->notification, &sequence_set_vibro_on);
+        furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
+        notification_message(app->notification, &sequence_reset_vibro);
+        furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
+    }
+}
+
+void mine_sweeper_play_oob_bump(void* context) {
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_set_vibro_on);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
+    notification_message(app->notification, &sequence_reset_vibro);
+}
+
+void mine_sweeper_play_lose_bump(void* context) {
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_set_vibro_on);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
+    notification_message(app->notification, &sequence_reset_vibro);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 400);
+}
+
+void mine_sweeper_play_win_bump(void* context) {
+    MineSweeperApp* app = context;
+
+    for (int i = 0; i < 4; i++) {
+        notification_message(app->notification, &sequence_set_vibro_on);
+        furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
+        notification_message(app->notification, &sequence_reset_vibro);
+        furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
+    }
+}

+ 17 - 0
minesweeper/helpers/mine_sweeper_haptic.h

@@ -0,0 +1,17 @@
+#ifndef MINESWEEPER_HAPTIC_H
+#define MINESWEEPER_HAPTIC_H
+
+#include <notification/notification_messages.h>
+
+void mine_sweeper_play_happy_bump(void* context);
+
+void mine_sweeper_play_long_ok_bump(void* context);
+
+void mine_sweeper_play_oob_bump(void* context);
+
+void mine_sweeper_play_lose_bump(void* context);
+
+void mine_sweeper_play_win_bump(void* context);
+
+
+#endif

+ 61 - 0
minesweeper/helpers/mine_sweeper_led.c

@@ -0,0 +1,61 @@
+#include "mine_sweeper_led.h"
+#include "../minesweeper.h"
+
+
+
+void mine_sweeper_led_set_rgb(void* context, int red, int green, int blue) {
+    MineSweeperApp* app = context;
+
+    NotificationMessage notification_led_message_1;
+    notification_led_message_1.type = NotificationMessageTypeLedRed;
+    NotificationMessage notification_led_message_2;
+    notification_led_message_2.type = NotificationMessageTypeLedGreen;
+    NotificationMessage notification_led_message_3;
+    notification_led_message_3.type = NotificationMessageTypeLedBlue;
+
+    notification_led_message_1.data.led.value = red;
+    notification_led_message_2.data.led.value = green;
+    notification_led_message_3.data.led.value = blue;
+    const NotificationSequence notification_sequence = {
+        &notification_led_message_1,
+        &notification_led_message_2,
+        &notification_led_message_3,
+        &message_do_not_reset,
+        NULL,
+    };
+    notification_message(app->notification, &notification_sequence);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set    
+}
+
+void mine_sweeper_led_blink_red(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_blink_red_100);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set    
+}
+
+void mine_sweeper_led_blink_magenta(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_blink_magenta_100);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set    
+}
+
+void mine_sweeper_led_blink_cyan(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+
+    notification_message(app->notification, &sequence_blink_cyan_100);
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set    
+}
+
+void mine_sweeper_led_reset(void* context) {
+    MineSweeperApp* app = context;
+    notification_message(app->notification, &sequence_reset_red);
+    notification_message(app->notification, &sequence_reset_green);
+    notification_message(app->notification, &sequence_reset_blue);
+    
+    furi_thread_flags_wait(0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set    
+}

+ 15 - 0
minesweeper/helpers/mine_sweeper_led.h

@@ -0,0 +1,15 @@
+#ifndef MINESWEEPER_LED_H
+#define MINESWEEPER_LED_H
+
+void mine_sweeper_led_set_rgb(void* context, int red, int green, int blue);
+
+void mine_sweeper_led_blink_red(void* context);
+
+void mine_sweeper_led_blink_magenta(void* context);
+
+void mine_sweeper_led_blink_cyan(void* context);
+
+void mine_sweeper_led_reset(void* context);
+
+
+#endif

+ 64 - 0
minesweeper/helpers/mine_sweeper_speaker.c

@@ -0,0 +1,64 @@
+#include "mine_sweeper_speaker.h"
+#include "../minesweeper.h"
+
+static const float volume = 0.8f;
+
+void mine_sweeper_play_ok_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
+        furi_hal_speaker_start(NOTE_LOSE, volume);
+    }
+
+}
+
+void mine_sweeper_play_flag_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
+        furi_hal_speaker_start(NOTE_FLAG, volume);
+    }
+
+}
+
+void mine_sweeper_play_oob_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
+        furi_hal_speaker_start(NOTE_OOB, volume);
+    }
+
+}
+
+void mine_sweeper_play_win_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
+        furi_hal_speaker_start(NOTE_WIN, volume);
+    }
+
+}
+
+void mine_sweeper_play_lose_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
+        furi_hal_speaker_start(NOTE_LOSE, volume);
+    }
+
+}
+
+void mine_sweeper_stop_all_sound(void* context) {
+    MineSweeperApp* app = context;
+    UNUSED(app);
+
+    if(furi_hal_speaker_is_mine()) {
+        furi_hal_speaker_stop();
+        furi_hal_speaker_release();
+    }
+}

+ 18 - 0
minesweeper/helpers/mine_sweeper_speaker.h

@@ -0,0 +1,18 @@
+#ifndef MINESWEEPER_SPEAKER_H
+#define MINESWEEPER_SPEAKER_H
+
+#define NOTE_OK 3078.95f //G_4
+#define NOTE_FLAG 384.87f //G_4
+#define NOTE_OOB 342.88f  //F_4
+#define NOTE_WIN 432.00f  //Divine
+#define NOTE_LOSE 4170.00f //Cursed
+
+void mine_sweeper_play_ok_sound(void* context);
+void mine_sweeper_play_flag_sound(void* context);
+void mine_sweeper_play_oob_sound(void* context);
+void mine_sweeper_play_win_sound(void* context);
+void mine_sweeper_play_lose_sound(void* context);
+void mine_sweeper_stop_all_sound(void* context);
+
+
+#endif

+ 143 - 0
minesweeper/helpers/mine_sweeper_storage.c

@@ -0,0 +1,143 @@
+#include "mine_sweeper_storage.h"
+
+
+static Storage* mine_sweeper_open_storage() {
+    return furi_record_open(RECORD_STORAGE);
+}
+
+static void mine_sweeper_close_storage() {
+    furi_record_close(RECORD_STORAGE);
+}
+
+static void mine_sweeper_close_config_file(FlipperFormat* file) {
+    if (file == NULL) return;
+    flipper_format_file_close(file);
+    flipper_format_free(file);
+}
+
+void mine_sweeper_save_settings(void* context) {
+    MineSweeperApp* app = context;
+
+    Storage* storage = mine_sweeper_open_storage();
+    FlipperFormat* fff_file = flipper_format_file_alloc(storage);
+    
+    // Overwrite wont work, so delete first
+    if(storage_file_exists(storage, MINESWEEPER_SETTINGS_SAVE_PATH)) {
+        storage_simply_remove(storage, MINESWEEPER_SETTINGS_SAVE_PATH);
+    }
+
+    // Open File, create if not exists
+    if(!storage_common_stat(storage, MINESWEEPER_SETTINGS_SAVE_PATH, NULL) == FSE_OK) {
+        FURI_LOG_I(TAG, "Config file %s is not found. Will create new.", MINESWEEPER_SETTINGS_SAVE_PATH);
+        if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
+            FURI_LOG_I(
+                TAG,
+                "Directory %s doesn't exist. Will create new.",
+                CONFIG_FILE_DIRECTORY_PATH);
+            if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
+                FURI_LOG_E(TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
+            }
+        }
+    }
+
+    if(!flipper_format_file_open_new(fff_file, MINESWEEPER_SETTINGS_SAVE_PATH)) {
+        FURI_LOG_E(TAG, "Error creating new file %s", MINESWEEPER_SETTINGS_SAVE_PATH);
+        mine_sweeper_close_storage();
+        return;
+    }
+    
+    // Store Settings
+    flipper_format_write_header_cstr(
+        fff_file, MINESWEEPER_SETTINGS_HEADER, MINESWEEPER_SETTINGS_FILE_VERSION);
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_LED, &app->led, 1);
+
+    uint32_t w = app->settings_info.board_width, h = app->settings_info.board_height, d = app->settings_info.difficulty;
+
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_WIDTH, &w, 1);
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_HEIGHT, &h, 1);
+    flipper_format_write_uint32(
+        fff_file, MINESWEEPER_SETTINGS_KEY_DIFFICULTY, &d, 1);
+    
+    if(!flipper_format_rewind(fff_file)) {
+        FURI_LOG_E(TAG, "Rewind error");
+        mine_sweeper_close_config_file(fff_file);
+        mine_sweeper_close_storage();
+        return;
+    }
+
+    mine_sweeper_close_config_file(fff_file);
+    mine_sweeper_close_storage();
+    return;
+}
+
+bool mine_sweeper_read_settings(void* context) {
+    MineSweeperApp* app = context;
+
+    Storage* storage = mine_sweeper_open_storage();
+    FlipperFormat* fff_file = flipper_format_file_alloc(storage);
+
+    if(storage_common_stat(storage, MINESWEEPER_SETTINGS_SAVE_PATH, NULL) != FSE_OK) {
+        mine_sweeper_close_config_file(fff_file);
+        mine_sweeper_close_storage();
+        return false;
+    }
+
+    uint32_t file_version;
+    FuriString* temp_str = furi_string_alloc();
+
+    if (!flipper_format_file_open_existing(fff_file, MINESWEEPER_SETTINGS_SAVE_PATH)) {
+        FURI_LOG_E(TAG, "Cannot open file %s", MINESWEEPER_SETTINGS_SAVE_PATH);
+        mine_sweeper_close_config_file(fff_file);
+        mine_sweeper_close_storage();
+        return false;
+    }
+
+    if(!flipper_format_read_header(fff_file, temp_str, &file_version)) {
+        FURI_LOG_E(TAG, "Missing Header Data");
+        mine_sweeper_close_config_file(fff_file);
+        mine_sweeper_close_storage();
+        return false;
+    }
+
+    furi_string_free(temp_str);
+
+    if(file_version < MINESWEEPER_SETTINGS_FILE_VERSION) {
+        FURI_LOG_I(TAG, "old config version, will be removed.");
+        mine_sweeper_close_config_file(fff_file);
+        mine_sweeper_close_storage();
+        return false;
+    }
+
+    uint32_t w = 7, h = 16, d = 0;
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_WIDTH, &w, 1);
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_HEIGHT, &h, 1);
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_DIFFICULTY, &d, 1);
+
+    if (w > 146) {w = 146;}
+    if (w < 16 ) {w = 16;}
+    if (h > 64 ) {h = 64;}
+    if (h < 7  ) {h = 7;}
+    if (d > 2 ) {d = 2;}
+
+    app->settings_info.board_width = (uint8_t) w;
+    app->settings_info.board_height = (uint8_t) h;
+    app->settings_info.difficulty = (uint8_t) d;
+
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
+    flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_LED, &app->led, 1);
+
+    flipper_format_rewind(fff_file);
+
+    mine_sweeper_close_config_file(fff_file);
+    mine_sweeper_close_storage();
+
+    return true;
+}

+ 27 - 0
minesweeper/helpers/mine_sweeper_storage.h

@@ -0,0 +1,27 @@
+#ifndef MINESWEEPER_STORAGE_H
+#define MINESWEEPER_STORAGE_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <storage/storage.h>
+#include <flipper_format/flipper_format.h>
+#include "../minesweeper.h"
+
+#define MINESWEEPER_SETTINGS_FILE_VERSION 1
+#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/f0_mine_sweeper")
+#define MINESWEEPER_SETTINGS_SAVE_PATH CONFIG_FILE_DIRECTORY_PATH "/f0_mine_sweeper.conf"
+#define MINESWEEPER_SETTINGS_SAVE_PATH_TMP MINESWEEPER_SETTINGS_SAVE_PATH ".tmp"
+#define MINESWEEPER_SETTINGS_HEADER "Mine Sweeper Config File"
+
+#define MINESWEEPER_SETTINGS_KEY_WIDTH "BoardWidth"
+#define MINESWEEPER_SETTINGS_KEY_HEIGHT "BoardHeight"
+#define MINESWEEPER_SETTINGS_KEY_DIFFICULTY "BoardDifficulty"
+
+#define MINESWEEPER_SETTINGS_KEY_HAPTIC "Haptic"
+#define MINESWEEPER_SETTINGS_KEY_LED "Led"
+#define MINESWEEPER_SETTINGS_KEY_SPEAKER "Speaker"
+
+void mine_sweeper_save_settings(void* context);
+bool mine_sweeper_read_settings(void* context);
+
+#endif

BIN=BIN
minesweeper/img/1.png


BIN=BIN
minesweeper/img/2.png


+ 27 - 0
minesweeper/img/SIMPLEREADME.md

@@ -0,0 +1,27 @@
+# Minesweeper Implementation for the Flipper Zero.
+
+## Added features unique to this implementation:
+-	Enable board verifier for board generation to ensure unambiguous boards!
+-	Set board width and height
+-	Set difficulty
+-	A number of different button presses as shortcuts for game actions (see How To Play) 
+
+
+## How To Play
+1. Up/Down/Left/Right Buttons to move around
+	- These buttons can be held down to keep moving in a direction
+2. Center OK Button to attempt opening up a tile
+	- Press OK on a tile to open it up
+	- Hold OK on a cleared space with a number to clear all surrounding tiles (correct number of flags must be set around it)
+3. Hold Back Button on a tile to toggle marking it with a flag
+4. Hold Back Button on a cleared space to jump to one of the closest tiles (this can help find last tiles on a larger board)
+5. Press Back Button to access the settings menu where you can do the following:
+	- Change board width
+	- Change board height
+	- Change difficulty
+	- Ensure Solvable (**Important!**)- This option will enable the board verifier for board generation and can significantly increase wait times for generating a board. Currently this may lock up the view port on the loading animation, but it should eventually resolve and return to the game.
+
+## IMPORTANT NOTICE:
+The way I set the board up leaves the corners as safe starting positions!
+
+In addition to this, with the "Ensure Solvable" option set to true, the board will always be solvable from 0,0! Without Ensure Solvable enabled in the settings the mine placement for the board generation is randomized and there is no guarantee that the game with be solvable without any guesses.

BIN=BIN
minesweeper/img/github_images/MineSweeperGameplay.gif


BIN=BIN
minesweeper/img/github_images/StartScreenAnimationGif.gif


BIN=BIN
minesweeper/img/screenshot.png


BIN=BIN
minesweeper/img/screenshot1.png


BIN=BIN
minesweeper/img/screenshot2.png


BIN=BIN
minesweeper/img/screenshot3.png


BIN=BIN
minesweeper/img/screenshot4.png


BIN=BIN
minesweeper/img/screenshot5.png


+ 123 - 483
minesweeper/minesweeper.c

@@ -1,515 +1,155 @@
-#include <furi.h>
-#include <furi_hal.h>
-#include <gui/gui.h>
-#include <input/input.h>
-#include <stdlib.h>
-
-#include <notification/notification_messages.h>
-#include <dialogs/dialogs.h>
-
-#include <dolphin/dolphin.h>
-
-#include "assets.h"
-
-#define PLAYFIELD_WIDTH 16
-#define PLAYFIELD_HEIGHT 7
-#define TILE_WIDTH 8
-#define TILE_HEIGHT 8
-
-#define MINECOUNT 20
-
-typedef enum {
-    EventTypeTick,
-    EventTypeKey,
-} EventType;
-
-typedef struct {
-    EventType type;
-    InputEvent input;
-} PluginEvent;
-
-typedef enum {
-    TileType0, // this HAS to be in order, for hint assignment to be ez pz
-    TileType1,
-    TileType2,
-    TileType3,
-    TileType4,
-    TileType5,
-    TileType6,
-    TileType7,
-    TileType8,
-    TileTypeUncleared,
-    TileTypeFlag,
-    TileTypeMine
-} TileType;
-
-typedef enum { FieldEmpty, FieldMine } Field;
-
-typedef struct {
-    FuriMutex* mutex;
-    DialogsApp* dialogs;
-    NotificationApp* notifications;
-    Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
-    TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
-    int cursor_x;
-    int cursor_y;
-    int mines_left;
-    int fields_cleared;
-    int flags_set;
-    bool game_started;
-    uint32_t game_started_tick;
-} Minesweeper;
-
-static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
-    furi_assert(event_queue);
-
-    PluginEvent event = {.type = EventTypeKey, .input = *input_event};
-    furi_message_queue_put(event_queue, &event, FuriWaitForever);
-}
+#include "minesweeper.h"
+//#include <args.h>
 
-static void render_callback(Canvas* const canvas, void* ctx) {
-    furi_assert(ctx);
-    const Minesweeper* minesweeper_state = ctx;
-    furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-
-    FuriString* mineStr;
-    FuriString* timeStr;
-    mineStr = furi_string_alloc();
-    timeStr = furi_string_alloc();
-
-    furi_string_printf(mineStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set);
-    canvas_set_font(canvas, FontSecondary);
-    canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(mineStr));
-
-    int seconds = 0;
-    int minutes = 0;
-    if(minesweeper_state->game_started) {
-        uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick;
-        seconds = (int)ticks_elapsed / furi_kernel_get_tick_frequency();
-        minutes = (int)seconds / 60;
-        seconds = seconds % 60;
-    }
-    furi_string_printf(timeStr, "%01d:%02d", minutes, seconds);
-    canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(timeStr));
-
-    uint8_t* tile_to_draw;
-
-    for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
-        for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
-            if(x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
-                canvas_invert_color(canvas);
-            }
-            switch(minesweeper_state->playfield[x][y]) {
-            case TileType0:
-                tile_to_draw = tile_0_bits;
-                break;
-            case TileType1:
-                tile_to_draw = tile_1_bits;
-                break;
-            case TileType2:
-                tile_to_draw = tile_2_bits;
-                break;
-            case TileType3:
-                tile_to_draw = tile_3_bits;
-                break;
-            case TileType4:
-                tile_to_draw = tile_4_bits;
-                break;
-            case TileType5:
-                tile_to_draw = tile_5_bits;
-                break;
-            case TileType6:
-                tile_to_draw = tile_6_bits;
-                break;
-            case TileType7:
-                tile_to_draw = tile_7_bits;
-                break;
-            case TileType8:
-                tile_to_draw = tile_8_bits;
-                break;
-            case TileTypeFlag:
-                tile_to_draw = tile_flag_bits;
-                break;
-            case TileTypeUncleared:
-                tile_to_draw = tile_uncleared_bits;
-                break;
-            case TileTypeMine:
-                tile_to_draw = tile_mine_bits;
-                break;
-            default:
-                // this should never happen
-                tile_to_draw = tile_mine_bits;
-                break;
-            }
-            canvas_draw_xbm(
-                canvas,
-                x * TILE_HEIGHT, // x
-                8 + (y * TILE_WIDTH), // y
-                TILE_WIDTH,
-                TILE_HEIGHT,
-                tile_to_draw);
-            if(x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
-                canvas_invert_color(canvas);
-            }
-        }
-    }
+static bool minesweeper_custom_event_callback(void* context, uint32_t custom_event) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+    return scene_manager_handle_custom_event(app->scene_manager, custom_event);
+}
 
-    furi_string_free(mineStr);
-    furi_string_free(timeStr);
-    furi_mutex_release(minesweeper_state->mutex);
+static bool minesweeper_navigation_event_callback(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+    return scene_manager_handle_back_event(app->scene_manager);
 }
 
-static void setup_playfield(Minesweeper* minesweeper_state) {
-    int mines_left = MINECOUNT;
-    for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
-        for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
-            minesweeper_state->minefield[x][y] = FieldEmpty;
-            minesweeper_state->playfield[x][y] = TileTypeUncleared;
-        }
-    }
-    while(mines_left > 0) {
-        int rand_x = rand() % PLAYFIELD_WIDTH;
-        int rand_y = rand() % PLAYFIELD_HEIGHT;
-        // make sure first guess isn't a mine
-        if(minesweeper_state->minefield[rand_x][rand_y] == FieldEmpty &&
-           (minesweeper_state->cursor_x != rand_x || minesweeper_state->cursor_y != rand_y)) {
-            minesweeper_state->minefield[rand_x][rand_y] = FieldMine;
-            mines_left--;
-        }
-    }
-    minesweeper_state->mines_left = MINECOUNT;
-    minesweeper_state->fields_cleared = 0;
-    minesweeper_state->flags_set = 0;
-    minesweeper_state->game_started_tick = furi_get_tick();
-    minesweeper_state->game_started = false;
+static void minesweeper_tick_event_callback(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+    return scene_manager_handle_tick_event(app->scene_manager);
 }
 
-static void place_flag(Minesweeper* minesweeper_state) {
-    if(minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] ==
-       TileTypeUncleared) {
-        minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] =
-            TileTypeFlag;
-        minesweeper_state->flags_set++;
-    } else if(
-        minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] ==
-        TileTypeFlag) {
-        minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] =
-            TileTypeUncleared;
-        minesweeper_state->flags_set--;
+static MineSweeperApp* app_alloc() { 
+    MineSweeperApp* app = (MineSweeperApp*)malloc(sizeof(MineSweeperApp));
+    
+    // NotificationApp Service
+    app->notification = furi_record_open(RECORD_NOTIFICATION);
+
+    // Turn backlight on when app starts
+    notification_message(app->notification, &sequence_display_backlight_on);
+
+
+    // Alloc Scene Manager and set handlers for on_enter, on_event, on_exit 
+    app->scene_manager = scene_manager_alloc(&minesweeper_scene_handlers, app);
+    
+    // Alloc View Dispatcher and enable queue
+    app->view_dispatcher = view_dispatcher_alloc();
+    view_dispatcher_enable_queue(app->view_dispatcher);
+    // Set View Dispatcher event callback context and callbacks
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+    view_dispatcher_set_custom_event_callback(app->view_dispatcher, minesweeper_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(app->view_dispatcher, minesweeper_navigation_event_callback);
+    view_dispatcher_set_tick_event_callback(app->view_dispatcher, minesweeper_tick_event_callback, 500);
+
+    // Set setting info to default
+    app->settings_info.width_str = furi_string_alloc();
+    app->settings_info.height_str = furi_string_alloc();
+    memset(&app->t_settings_info, 0, sizeof(app->t_settings_info));
+    app->is_settings_changed = false;
+
+    // If we cannot read the save file set to default values
+    if (!(mine_sweeper_read_settings(app))) {
+        FURI_LOG_I(TAG, "Cannot read save file, loading defaults");
+        app->settings_info.board_width = 16;
+        app->settings_info.board_height = 7;
+        app->settings_info.difficulty = 0;
+        app->haptic = 1;
+        app->speaker = 1;
+        app->led = 1;
+
+        mine_sweeper_save_settings(app);
+    } else {
+        FURI_LOG_I(TAG, "Save file loaded sucessfully");
     }
-}
 
-static bool game_lost(Minesweeper* minesweeper_state) {
-    // returns true if the player wants to restart, otherwise false
-    DialogMessage* message = dialog_message_alloc();
+    // Alloc views and add to view dispatcher
+    app->start_screen = start_screen_alloc();
+    view_dispatcher_add_view(
+            app->view_dispatcher,
+            MineSweeperStartScreenView,
+            start_screen_get_view(app->start_screen));
 
-    dialog_message_set_header(message, "Game Over", 64, 3, AlignCenter, AlignTop);
-    dialog_message_set_text(message, "You hit a mine!", 64, 32, AlignCenter, AlignCenter);
-    dialog_message_set_buttons(message, NULL, "Play again", NULL);
+    app->loading = loading_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, MineSweeperLoadingView, loading_get_view(app->loading));
 
-    // Set cursor to initial position
-    minesweeper_state->cursor_x = 0;
-    minesweeper_state->cursor_y = 0;
+    app->game_screen = mine_sweeper_game_screen_alloc(
+            app->settings_info.board_width,
+            app->settings_info.board_height,
+            app->settings_info.difficulty,
+            false);
 
-    notification_message(minesweeper_state->notifications, &sequence_single_vibro);
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        MineSweeperGameScreenView,
+        mine_sweeper_game_screen_get_view(app->game_screen));
 
-    DialogMessageButton choice = dialog_message_show(minesweeper_state->dialogs, message);
-    dialog_message_free(message);
+    app->menu_screen = dialog_ex_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, MineSweeperMenuView, dialog_ex_get_view(app->menu_screen));
 
-    return choice == DialogMessageButtonCenter;
-}
+    app->settings_screen = variable_item_list_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, MineSweeperSettingsView, variable_item_list_get_view(app->settings_screen));
 
-static bool game_won(Minesweeper* minesweeper_state) {
-    FuriString* tempStr;
-    tempStr = furi_string_alloc();
-
-    int seconds = 0;
-    int minutes = 0;
-    uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick;
-    seconds = (int)ticks_elapsed / furi_kernel_get_tick_frequency();
-    minutes = (int)seconds / 60;
-    seconds = seconds % 60;
-
-    DialogMessage* message = dialog_message_alloc();
-    const char* header_text = "Game won!";
-    furi_string_cat_printf(tempStr, "Minefield cleared in %01d:%02d", minutes, seconds);
-    dialog_message_set_header(message, header_text, 64, 3, AlignCenter, AlignTop);
-    dialog_message_set_text(
-        message, furi_string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter);
-    dialog_message_set_buttons(message, NULL, "Play again", NULL);
-
-    // Call dolphin deed when we win the game
-    dolphin_deed(DolphinDeedPluginGameWin);
-
-    DialogMessageButton choice = dialog_message_show(minesweeper_state->dialogs, message);
-    dialog_message_free(message);
-    furi_string_free(tempStr);
-    return choice == DialogMessageButtonCenter;
-}
+    app->confirmation_screen = dialog_ex_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, MineSweeperConfirmationView, dialog_ex_get_view(app->confirmation_screen));
 
-// returns false if the move loses the game - otherwise true
-static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) {
-    if(minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
-        // we're on a flagged field, do nothing
-        return true;
-    }
-    if(minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
-        // player loses - draw mine
-        minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
-        return false;
-    }
+    app->info_screen = text_box_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, MineSweeperInfoView, text_box_get_view(app->info_screen));
 
-    if(minesweeper_state->playfield[cursor_x][cursor_y] >= TileType1 &&
-       minesweeper_state->playfield[cursor_x][cursor_y] <= TileType8) {
-        // click on a cleared cell with a number
-        // count the flags around
-        int flags = 0;
-        for(int y = cursor_y - 1; y <= cursor_y + 1; y++) {
-            for(int x = cursor_x - 1; x <= cursor_x + 1; x++) {
-                if(x == cursor_x && y == cursor_y) {
-                    // we're on the cell the user selected, so ignore.
-                    continue;
-                }
-                // make sure we don't go OOB
-                if(x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
-                    if(minesweeper_state->playfield[x][y] == TileTypeFlag) {
-                        flags++;
-                    }
-                }
-            }
-        }
-        int mines = minesweeper_state->playfield[cursor_x][cursor_y]; // ¯\_(ツ)_/¯
-        if(flags == mines) {
-            // auto uncover all non-flags around (to win faster ;)
-            for(int auto_y = cursor_y - 1; auto_y <= cursor_y + 1; auto_y++) {
-                for(int auto_x = cursor_x - 1; auto_x <= cursor_x + 1; auto_x++) {
-                    if(auto_x == cursor_x && auto_y == cursor_y) {
-                        continue;
-                    }
-                    if(auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 &&
-                       auto_y < PLAYFIELD_HEIGHT) {
-                        if(minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
-                            if(!play_move(minesweeper_state, auto_x, auto_y)) {
-                                // flags were wrong, we got a mine!
-                                return false;
-                            }
-                        }
-                    }
-                }
-            }
-            // we're done without hitting a mine - so return
-            return true;
-        }
-    }
+    Gui* gui = furi_record_open(RECORD_GUI);
 
-    // calculate number of surrounding mines.
-    int hint = 0;
-    for(int y = cursor_y - 1; y <= cursor_y + 1; y++) {
-        for(int x = cursor_x - 1; x <= cursor_x + 1; x++) {
-            if(x == cursor_x && y == cursor_y) {
-                // we're on the cell the user selected, so ignore.
-                continue;
-            }
-            // make sure we don't go OOB
-            if(x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
-                if(minesweeper_state->minefield[x][y] == FieldMine) {
-                    hint++;
-                }
-            }
-        }
-    }
-    // 〜( ̄▽ ̄〜) don't judge me (〜 ̄▽ ̄)〜
-    minesweeper_state->playfield[cursor_x][cursor_y] = hint;
-    minesweeper_state->fields_cleared++;
-    FURI_LOG_D("Minesweeper", "Setting %d,%d to %d", cursor_x, cursor_y, hint);
-    if(hint == 0) {
-        // the field is "empty"
-        // auto open surrounding fields.
-        for(int auto_y = cursor_y - 1; auto_y <= cursor_y + 1; auto_y++) {
-            for(int auto_x = cursor_x - 1; auto_x <= cursor_x + 1; auto_x++) {
-                if(auto_x == cursor_x && auto_y == cursor_y) {
-                    continue;
-                }
-                if(auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 &&
-                   auto_y < PLAYFIELD_HEIGHT) {
-                    if(minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
-                        play_move(minesweeper_state, auto_x, auto_y);
-                    }
-                }
-            }
-        }
-    }
-    return true;
+    view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
+    
+    furi_record_close(RECORD_GUI);
+
+    return app;
 }
 
-static void minesweeper_state_init(Minesweeper* const minesweeper_state) {
-    minesweeper_state->cursor_x = minesweeper_state->cursor_y = 0;
-    minesweeper_state->game_started = false;
-    for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
-        for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
-            minesweeper_state->playfield[x][y] = TileTypeUncleared;
-        }
+static void app_free(MineSweeperApp* app) {
+    furi_assert(app);
+    
+    // Remove each view from View Dispatcher
+    for (MineSweeperView minesweeper_view = (MineSweeperView)0; minesweeper_view < MineSweeperViewCount; minesweeper_view++) {
+
+        view_dispatcher_remove_view(app->view_dispatcher, minesweeper_view);
     }
-}
 
-int32_t minesweeper_app(void* p) {
-    UNUSED(p);
-    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
+    // Free View Dispatcher and Scene Manager
+    scene_manager_free(app->scene_manager);
+    view_dispatcher_free(app->view_dispatcher);
 
-    Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper));
-    // setup
-    minesweeper_state_init(minesweeper_state);
+    // Free views
+    loading_free(app->loading);
+    start_screen_free(app->start_screen);
+    mine_sweeper_game_screen_free(app->game_screen);  
+    dialog_ex_free(app->menu_screen);
+    variable_item_list_free(app->settings_screen);
+    dialog_ex_free(app->confirmation_screen);
+    text_box_free(app->info_screen);
 
-    minesweeper_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
-    if(!minesweeper_state->mutex) {
-        FURI_LOG_E("Minesweeper", "cannot create mutex\r\n");
-        free(minesweeper_state);
-        return 255;
-    }
-    // BEGIN IMPLEMENTATION
 
-    minesweeper_state->dialogs = furi_record_open(RECORD_DIALOGS);
-    minesweeper_state->notifications = furi_record_open(RECORD_NOTIFICATION);
+    furi_string_free(app->settings_info.width_str);
+    furi_string_free(app->settings_info.height_str);
+
+    furi_record_close(RECORD_NOTIFICATION);
+
+    // Free app structure
+    free(app);
 
-    DialogMessage* message = dialog_message_alloc();
+}
 
-    dialog_message_set_header(message, "Minesweeper", 64, 3, AlignCenter, AlignTop);
-    dialog_message_set_text(
-        message,
-        "Hold OK pressed to toggle flags.\ngithub.com/panki27",
-        64,
-        32,
-        AlignCenter,
-        AlignCenter);
-    dialog_message_set_buttons(message, NULL, "Play", NULL);
+int32_t minesweeper_app(void* p) {
+    UNUSED(p);
 
-    dialog_message_show(minesweeper_state->dialogs, message);
-    dialog_message_free(message);
+    MineSweeperApp* app = app_alloc();
+    FURI_LOG_D(TAG, "Mine Sweeper app allocated with size : %d", sizeof(*app));
 
-    // Set system callbacks
-    ViewPort* view_port = view_port_alloc();
-    view_port_draw_callback_set(view_port, render_callback, minesweeper_state);
-    view_port_input_callback_set(view_port, input_callback, event_queue);
+    // This will be the initial scene on app startup
+    scene_manager_next_scene(app->scene_manager, MineSweeperSceneStartScreen);
 
-    // Open GUI and register view_port
-    Gui* gui = furi_record_open(RECORD_GUI);
-    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
-
-    // Call dolphin deed on game start
-    dolphin_deed(DolphinDeedPluginGameStart);
-
-    PluginEvent event;
-    for(bool processing = true; processing;) {
-        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
-        if(event_status == FuriStatusOk) {
-            // press events
-            if(event.type == EventTypeKey) {
-                if(event.input.type == InputTypeShort) {
-                    switch(event.input.key) {
-                    case InputKeyUp:
-                        furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-                        minesweeper_state->cursor_y--;
-                        if(minesweeper_state->cursor_y < 0) {
-                            minesweeper_state->cursor_y = PLAYFIELD_HEIGHT - 1;
-                        }
-                        furi_mutex_release(minesweeper_state->mutex);
-                        break;
-                    case InputKeyDown:
-                        furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-                        minesweeper_state->cursor_y++;
-                        if(minesweeper_state->cursor_y >= PLAYFIELD_HEIGHT) {
-                            minesweeper_state->cursor_y = 0;
-                        }
-                        furi_mutex_release(minesweeper_state->mutex);
-                        break;
-                    case InputKeyRight:
-                        furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-                        minesweeper_state->cursor_x++;
-                        if(minesweeper_state->cursor_x >= PLAYFIELD_WIDTH) {
-                            minesweeper_state->cursor_x = 0;
-                        }
-                        furi_mutex_release(minesweeper_state->mutex);
-                        break;
-                    case InputKeyLeft:
-                        furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-                        minesweeper_state->cursor_x--;
-                        if(minesweeper_state->cursor_x < 0) {
-                            minesweeper_state->cursor_x = PLAYFIELD_WIDTH - 1;
-                        }
-                        furi_mutex_release(minesweeper_state->mutex);
-                        break;
-                    case InputKeyOk:
-                        if(!minesweeper_state->game_started) {
-                            setup_playfield(minesweeper_state);
-                            minesweeper_state->game_started = true;
-                        }
-                        if(!play_move(
-                               minesweeper_state,
-                               minesweeper_state->cursor_x,
-                               minesweeper_state->cursor_y)) {
-                            // ooops. looks like we hit a mine!
-                            if(game_lost(minesweeper_state)) {
-                                // player wants to restart.
-                                setup_playfield(minesweeper_state);
-                            } else {
-                                // player wants to exit :(
-                                processing = false;
-                            }
-                        } else {
-                            // check win condition.
-                            if(minesweeper_state->fields_cleared ==
-                               (PLAYFIELD_HEIGHT * PLAYFIELD_WIDTH) - MINECOUNT) {
-                                if(game_won(minesweeper_state)) {
-                                    //player wants to restart
-                                    setup_playfield(minesweeper_state);
-                                } else {
-                                    processing = false;
-                                }
-                            }
-                        }
-                        break;
-                    case InputKeyBack:
-                        // Exit the plugin
-                        processing = false;
-                        break;
-                    default:
-                        break;
-                    }
-                } else if(event.input.type == InputTypeLong) {
-                    // hold events
-                    FURI_LOG_D("Minesweeper", "Got a long press!");
-                    switch(event.input.key) {
-                    case InputKeyUp:
-                    case InputKeyDown:
-                    case InputKeyRight:
-                    case InputKeyLeft:
-                        break;
-                    case InputKeyOk:
-                        FURI_LOG_D("Minesweeper", "Toggling flag");
-                        furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
-                        place_flag(minesweeper_state);
-                        furi_mutex_release(minesweeper_state->mutex);
-                        break;
-                    case InputKeyBack:
-                        processing = false;
-                        break;
-                    default:
-                        break;
-                    }
-                }
-            }
-        }
-        view_port_update(view_port);
-    }
-    view_port_enabled_set(view_port, false);
-    gui_remove_view_port(gui, view_port);
-    furi_record_close(RECORD_GUI);
-    furi_record_close(RECORD_DIALOGS);
-    furi_record_close(RECORD_NOTIFICATION);
-    view_port_free(view_port);
-    furi_message_queue_free(event_queue);
-    furi_mutex_free(minesweeper_state->mutex);
-    free(minesweeper_state);
+    view_dispatcher_run(app->view_dispatcher);
+
+    app_free(app);
+    FURI_LOG_D(TAG, "Mine Sweeper app freed");
 
     return 0;
 }

+ 96 - 0
minesweeper/minesweeper.h

@@ -0,0 +1,96 @@
+#ifndef MINESWEEPER_H
+#define MINESWEEPER_H
+
+#include <string.h> // memset
+#include <inttypes.h> // PRIu8 & SCNu8
+
+#include <furi.h>
+#include <furi_hal.h>
+#include <input/input.h>
+
+#include <notification/notification_messages.h>
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/loading.h>
+#include <gui/modules/dialog_ex.h>
+#include <gui/modules/variable_item_list.h>
+#include <gui/modules/text_box.h>
+
+#include "scenes/minesweeper_scene.h"
+#include "views/start_screen.h"
+#include "views/minesweeper_game_screen.h"
+#include "helpers/mine_sweeper_storage.h"
+#include "minesweeper_redux_icons.h"
+
+#define TAG "Mine Sweeper Application"
+
+// This is a helper struct for the settings view/scene
+typedef struct {
+    uint8_t board_width, board_height, difficulty;
+    bool ensure_solvable_board;
+    FuriString* width_str;
+    FuriString* height_str;
+    VariableItem* difficulty_item;
+    VariableItem* width_item;
+    VariableItem* height_item;
+    VariableItem* solvable_item;
+} MineSweeperAppSettings;
+
+// Main MineSweeperApp
+typedef struct MineSweeperApp {
+    SceneManager* scene_manager;
+    ViewDispatcher* view_dispatcher;
+    
+    NotificationApp* notification;
+
+    StartScreen* start_screen;
+    Loading* loading;
+    MineSweeperGameScreen* game_screen;
+    DialogEx* menu_screen;
+    VariableItemList* settings_screen;
+    DialogEx* confirmation_screen;
+    TextBox* info_screen;
+
+    MineSweeperAppSettings settings_info;
+    MineSweeperAppSettings t_settings_info;
+
+    bool is_settings_changed;
+    bool ensure_map_solvable;
+
+    uint32_t haptic;
+    uint32_t speaker;
+    uint32_t led;
+} MineSweeperApp;
+
+// View Id Enumeration
+typedef enum {
+    MineSweeperStartScreenView,
+    MineSweeperLoadingView,
+    MineSweeperGameScreenView,
+    MineSweeperMenuView,
+    MineSweeperSettingsView,
+    MineSweeperConfirmationView,
+    MineSweeperInfoView,
+    MineSweeperViewCount,
+} MineSweeperView;
+
+// Enumerations for hardware states
+// Will be used in later implementation
+typedef enum {
+    MineSweeperHapticOff,
+    MineSweeperHapticOn,
+} MineSweeperHapticState;
+
+typedef enum {
+    MineSweeperSpeakerOff,
+    MineSweeperSpeakerOn,
+} MineSweeperSpeakerState;
+
+typedef enum {
+    MineSweeperLedOff,
+    MineSweeperLedOn,
+} MineSweeperLedState;
+
+#endif

BIN=BIN
minesweeper/minesweeper_icon.png


+ 12 - 0
minesweeper/scenes/README.md

@@ -0,0 +1,12 @@
+# IMPORTANT INFO
+
+This scene directory has 3 important files in addition to other scene specific files:
+
+1. [minesweeper_scene.c](https://github.com/squee72564/F0_Minesweeper_Fap/blob/main/scenes/minesweeper_scene.c)
+	- File generates on_enter/exit/event handler fp arrays for Scene Manager and Initializes Scene Handlers configuration structure
+2. [minesweeper_scene.h](https://github.com/squee72564/F0_Minesweeper_Fap/blob/main/scenes/minesweeper_scene.h)
+	- File generates on_enter/exit/event handler function declarations for all scenes
+	- Generates Enum for all scenes 
+3. [minesweeper_scene_config.h](https://github.com/squee72564/F0_Minesweeper_Fap/blob/main/scenes/minesweeper_scene_config.h)
+	- Macro definition of ADD_SCENE() for each scene used.
+		- When adding new scenes you need to add a new macro definition to this file, along with the appropriate .c file for the definitions of the on_event/enter/exit functions for the scene.

+ 103 - 0
minesweeper/scenes/confirmation_scene.c

@@ -0,0 +1,103 @@
+#include "../minesweeper.h"
+
+static void confirmation_scene_dialog_callback(DialogExResult result, void* context) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, result);
+}
+
+void minesweeper_scene_confirmation_screen_on_enter(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView);
+    
+    dialog_ex_set_context(app->confirmation_screen, app);
+
+    dialog_ex_set_header(app->confirmation_screen, "Save Settings?", 128/2, 4, AlignCenter, AlignTop);
+
+    dialog_ex_set_text(app->confirmation_screen, "Warning: Saving will reset\nthe game with the\nselected settings.", 128/2, 64/2, AlignCenter, AlignCenter);
+
+    dialog_ex_set_left_button_text(app->confirmation_screen, "Back");
+
+    dialog_ex_set_center_button_text(app->confirmation_screen, "Cancel");
+
+    dialog_ex_set_right_button_text(app->confirmation_screen, "Save");
+
+    dialog_ex_set_result_callback(app->confirmation_screen, confirmation_scene_dialog_callback);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperConfirmationView);
+}
+
+bool minesweeper_scene_confirmation_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context; 
+    bool consumed = false;
+    
+    if (event.type == SceneManagerEventTypeCustom) {
+        switch (event.event) {
+
+            case DialogExResultLeft :
+                if (!scene_manager_search_and_switch_to_previous_scene(
+                        app->scene_manager, MineSweeperSceneSettingsScreen)) {
+
+                    scene_manager_stop(app->scene_manager);
+                    view_dispatcher_stop(app->view_dispatcher);
+                }
+                break;
+
+            case DialogExResultRight : 
+
+                view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView);
+
+                // Commit changes to actual buffer for settings data
+                app->settings_info.board_width  = app->t_settings_info.board_width;
+                app->settings_info.board_height = app->t_settings_info.board_height;
+                app->settings_info.difficulty   = app->t_settings_info.difficulty;
+                app->settings_info.ensure_solvable_board = app->t_settings_info.ensure_solvable_board;
+
+                mine_sweeper_save_settings(app);
+
+                // This is used to let the settings view know it can save the main settings_info
+                // to the temp one on the next on enter
+                app->is_settings_changed = false;
+
+                // Reset the game board
+                mine_sweeper_game_screen_reset(
+                        app->game_screen,
+                        app->settings_info.board_width,
+                        app->settings_info.board_height,
+                        app->settings_info.difficulty,
+                        app->settings_info.ensure_solvable_board);
+
+                // Go to reset game view
+                scene_manager_search_and_switch_to_another_scene(app->scene_manager, MineSweeperSceneGameScreen); 
+                break;
+
+            case DialogExResultCenter :
+                // Do not commit changes to actual buffer on cancel
+
+                app->is_settings_changed = false;
+
+                // we want to just switch back to the game screen without resetting 
+                scene_manager_search_and_switch_to_another_scene(app->scene_manager, MineSweeperSceneGameScreen); 
+
+                break;
+
+            default :
+                break;
+        }
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_confirmation_screen_on_exit(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    dialog_ex_reset(app->confirmation_screen);
+}

+ 40 - 0
minesweeper/scenes/game_screen_scene.c

@@ -0,0 +1,40 @@
+#include "../minesweeper.h"
+#include "../views/minesweeper_game_screen.h"
+
+#include <input/input.h>
+
+void minesweeper_scene_game_screen_on_enter(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+    
+    furi_assert(app->game_screen);
+
+    mine_sweeper_game_screen_set_context(app->game_screen, app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperGameScreenView);
+}
+
+bool minesweeper_scene_game_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    bool consumed = false;
+
+    // No custom scene events from mine sweeper view
+    // Just check for back button to route to next screen
+    if (event.type == SceneManagerEventTypeBack) {
+        scene_manager_next_scene(app->scene_manager, MineSweeperSceneMenuScreen);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_game_screen_on_exit(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+    
+    // Do not call reset function for mine sweeper module
+    //unless you want to reset the state of the board
+    UNUSED(app);
+}

+ 72 - 0
minesweeper/scenes/info_scene.c

@@ -0,0 +1,72 @@
+#include "../minesweeper.h"
+static const char* info_string= "GAME INFO BELOW\n\n"
+                                "1. Press OK to clear a tile.\n\n"
+                                "2. Hold OK on a numbered tile\n"
+                                "to clear all surrounding\n"
+                                "tiles if the correct amount\n"
+                                "of flags are set.\n\n"
+                                "3. Hold Back on a tile to\n"
+                                "mark it with a flag.\n\n"
+                                "4. Hold back on a cleared\n"
+                                "tile to jump to the\n"
+                                "closest tile.\n\n"
+                                "SETTINGS INFO\n\n"
+                                "Difficulty and map\n"
+                                "dimensions can be changed\n"
+                                "in the settings with a\n"
+                                "max map size of 1024\n"
+                                "tiles (32x32).\n\n"
+                                "ENSURE SOLVABLE\n"
+                                "This is a setting that\n"
+                                "enables a board verifier\n"
+                                "when generating a new\n"
+                                "board.\n\n"
+                                "-- WARNING --\n"
+                                "This setting will introduce\n"
+                                "a variable amount of\n"
+                                "overhead when generating\n"
+                                "a new map. It can take\n"
+                                "several seconds for a\n"
+                                "valid map to generate. The\n"
+                                "UI may hang and stop for a\n"
+                                "while but it should resolve\n"
+                                "in a few seconds.\n\n"
+                                "Enjoy the game and if you\n"
+                                "want to reach out about an\n"
+                                "issue go to the git hub repo\n"
+                                "for this app:\n\n"
+                                "'github.com/squee72564/\n"
+                                "F0_Minesweeper_Fap'\n\n"
+                                "Thanks and enjoy!";
+
+
+void minesweeper_scene_info_screen_on_enter(void* context) {
+    furi_assert(context);
+
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    text_box_set_text(app->info_screen, info_string);
+    text_box_set_font(app->info_screen, TextBoxFontText);
+    text_box_set_focus(app->info_screen, TextBoxFocusStart);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperInfoView);
+}
+
+bool minesweeper_scene_info_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    UNUSED(event);
+    UNUSED(app);
+
+    bool consumed = false;
+    
+    return consumed;
+}
+
+void minesweeper_scene_info_screen_on_exit(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    text_box_reset(app->info_screen);
+}

+ 103 - 0
minesweeper/scenes/menu_scene.c

@@ -0,0 +1,103 @@
+#include "../minesweeper.h"
+
+static const char* farewellPrompts[] = {
+    "Leaving so\n   soon?",
+    "Will you\n   stay?",
+    "Don't swim\n   away.",
+    "Feeling\n   farewell?",
+    "Sad to part\n   ways.",
+    "Ocean of\n   goodbyes.",
+    "Dolphin tears,\n   why?",
+    "Lonely without\n   you.",
+    "End of our\n   wave?",
+    "Will you\n   return?",
+    "Drowning in\n   goodbye.",
+    "Farewell\n   ripples.",
+    "Flipper's\n   frown.",
+    "Sea of\n   solitude.",
+    "Parting\n   currents.",
+    "Goodbye, old\n   friend.",
+    "Will tide\n  bring back?",
+    "Echoes of\n  departure.",
+    "Dolphin's last\n   dance.",
+    "Ocean misses\n   you."
+};
+
+static void minesweeper_menu_scene_dialog_callback(DialogExResult result, void* context) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, result);
+}
+
+void minesweeper_scene_menu_screen_on_enter(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView);
+    
+    dialog_ex_set_context(app->menu_screen, app);
+
+    dialog_ex_set_header(app->menu_screen, "Exit Game?", (128*3)/4, 4, AlignCenter, AlignTop);
+
+    uint32_t prompt_index = furi_hal_random_get() % sizeof(farewellPrompts) / sizeof(char*);
+
+    dialog_ex_set_text(app->menu_screen, farewellPrompts[prompt_index], 65, 20, AlignLeft, AlignTop);
+
+    dialog_ex_set_icon(app->menu_screen, 11, 0, &I_Cry_dolph_55x52);
+
+    dialog_ex_set_left_button_text(app->menu_screen, "Back");
+
+    dialog_ex_set_center_button_text(app->menu_screen, "Settings");
+
+    dialog_ex_set_right_button_text(app->menu_screen, "Exit");
+
+    dialog_ex_set_result_callback(app->menu_screen, minesweeper_menu_scene_dialog_callback);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperMenuView);
+}
+
+bool minesweeper_scene_menu_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context; 
+    bool consumed = false;
+    
+    if (event.type == SceneManagerEventTypeCustom) {
+        switch (event.event) {
+
+            case DialogExResultLeft :
+                if (!scene_manager_search_and_switch_to_previous_scene(
+                        app->scene_manager, MineSweeperSceneGameScreen)) {
+
+                    scene_manager_stop(app->scene_manager);
+                    view_dispatcher_stop(app->view_dispatcher);
+                }
+
+                consumed = true;
+                break;
+
+            case DialogExResultRight : 
+                scene_manager_stop(app->scene_manager);
+                view_dispatcher_stop(app->view_dispatcher);
+                consumed = true;
+                break;
+
+            case DialogExResultCenter :
+                scene_manager_next_scene(app->scene_manager, MineSweeperSceneSettingsScreen);
+                break;
+
+            default :
+                break;
+        }
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_menu_screen_on_exit(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+
+    dialog_ex_reset(app->menu_screen);
+}

+ 30 - 0
minesweeper/scenes/minesweeper_scene.c

@@ -0,0 +1,30 @@
+#include "minesweeper_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const minesweeper_on_enter_handlers[])(void*) = {
+#include "minesweeper_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const minesweeper_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "minesweeper_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const minesweeper_on_exit_handlers[])(void* context) = {
+#include "minesweeper_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers minesweeper_scene_handlers = {
+    .on_enter_handlers = minesweeper_on_enter_handlers,
+    .on_event_handlers = minesweeper_on_event_handlers,
+    .on_exit_handlers = minesweeper_on_exit_handlers,
+    .scene_num = MineSweeperSceneNum,
+};

+ 32 - 0
minesweeper/scenes/minesweeper_scene.h

@@ -0,0 +1,32 @@
+#ifndef MINESWEEPER_SCENE_H
+#define MINESWEEPER_SCENE_H
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) MineSweeperScene##id,
+typedef enum {
+#include "minesweeper_scene_config.h"
+        MineSweeperSceneNum
+} MineSweeperScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers minesweeper_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "minesweeper_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "minesweeper_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "minesweeper_scene_config.h"
+#undef ADD_SCENE
+
+#endif

+ 6 - 0
minesweeper/scenes/minesweeper_scene_config.h

@@ -0,0 +1,6 @@
+ADD_SCENE(minesweeper, start_screen, StartScreen)
+ADD_SCENE(minesweeper, game_screen, GameScreen)
+ADD_SCENE(minesweeper, menu_screen, MenuScreen)
+ADD_SCENE(minesweeper, settings_screen, SettingsScreen)
+ADD_SCENE(minesweeper, confirmation_screen, ConfirmationScreen)
+ADD_SCENE(minesweeper, info_screen, InfoScreen)

+ 363 - 0
minesweeper/scenes/settings_scene.c

@@ -0,0 +1,363 @@
+#include "../minesweeper.h"
+#include "../views/minesweeper_game_screen.h"
+
+typedef enum {
+    MineSweeperSettingsScreenDifficultyTypeEasy,
+    MineSweeperSettingsScreenDifficultyTypeMedium,
+    MineSweeperSettingsScreenDifficultyTypeHard,
+    MineSweeperSettingsScreenDifficultyTypeNum,
+} MineSweeperSettingsScreenDifficultyType;
+
+typedef enum {
+    MineSweeperSettingsScreenIndexDifficulty,
+    MineSweeperSettingsScreenIndexWidth,
+    MineSweeperSettingsScreenIndexHeight,
+    MineSweeperSettingsScreenIndexNum,
+} MineSweeperSettingsScreenIndex;
+
+typedef enum {
+    MineSweeperSettingsScreenEventDifficultyChange,
+    MineSweeperSettingsScreenEventWidthChange,
+    MineSweeperSettingsScreenEventHeightChange,
+    MineSweeperSettingsScreenEventSolvableChange,
+    MineSweeperSettingsScreenEventInfoChange,
+} MineSweeperSettingsScreenEvent;
+
+static const char* settings_screen_difficulty_text[MineSweeperSettingsScreenDifficultyTypeNum] = {
+    "Easy",
+    "Medium",
+    "Hard",
+};
+
+static const char* settings_screen_verifier_text[2] = {
+    "False",
+    "True",
+};
+
+static void minesweeper_scene_settings_screen_set_difficulty(VariableItem* item) {
+    furi_assert(item);
+
+    MineSweeperApp* app = variable_item_get_context(item);
+    app->t_settings_info.difficulty_item = item;
+
+    uint8_t index = variable_item_get_current_value_index(app->t_settings_info.difficulty_item);
+    
+    app->t_settings_info.difficulty = index;
+
+    variable_item_set_current_value_text(
+            app->t_settings_info.difficulty_item,
+            settings_screen_difficulty_text[index]);
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, MineSweeperSettingsScreenEventDifficultyChange);
+}
+
+static void minesweeper_scene_settings_screen_set_width(VariableItem* item) {
+
+    char source[5];
+    uint8_t index = 0;
+    uint8_t curr_board_height = 7;
+    bool is_over_max_tiles = false;
+
+    furi_assert(item);
+
+    MineSweeperApp* app = variable_item_get_context(item);
+    app->t_settings_info.width_item = item;
+
+    index = variable_item_get_current_value_index(app->t_settings_info.width_item);
+    app->t_settings_info.board_width = index+16;
+
+    curr_board_height = app->t_settings_info.board_height;
+
+    is_over_max_tiles = (app->t_settings_info.board_width * curr_board_height) > MINESWEEPER_BOARD_MAX_TILES;
+    if (is_over_max_tiles) {
+
+        do {
+            is_over_max_tiles = (app->t_settings_info.board_width * --curr_board_height) > MINESWEEPER_BOARD_MAX_TILES;
+        } while (is_over_max_tiles);
+
+        app->t_settings_info.board_height = curr_board_height;
+
+        snprintf(source, 5, "%" PRIu8, curr_board_height);
+        source[4] = '\0';
+
+        furi_string_set_strn(app->t_settings_info.height_str, source, 5);
+
+        variable_item_set_current_value_index(
+                app->t_settings_info.height_item,
+                app->t_settings_info.board_height-7);
+
+        variable_item_set_current_value_text(app->t_settings_info.height_item, furi_string_get_cstr(app->t_settings_info.height_str));
+    }
+
+    snprintf(source, 5, "%" PRIu8, index+16);
+    source[4] = '\0';
+    
+    furi_string_set_strn(app->t_settings_info.width_str, source, 5);
+
+    variable_item_set_current_value_text(app->t_settings_info.width_item, furi_string_get_cstr(app->t_settings_info.width_str));
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, MineSweeperSettingsScreenEventHeightChange);
+}
+
+static void minesweeper_scene_settings_screen_set_height(VariableItem* item) {
+
+    char source[5];
+    uint8_t index = 0;
+    uint8_t curr_board_width = 16;
+    bool is_over_max_tiles = false;
+
+    furi_assert(item);
+
+    MineSweeperApp* app = variable_item_get_context(item);
+    app->t_settings_info.height_item = item;
+
+    index = variable_item_get_current_value_index(app->t_settings_info.height_item);
+    app->t_settings_info.board_height = index+7;
+
+    curr_board_width = app->t_settings_info.board_width;
+
+    is_over_max_tiles = (app->t_settings_info.board_height * curr_board_width) > MINESWEEPER_BOARD_MAX_TILES;
+    if (is_over_max_tiles) {
+
+        do {
+            is_over_max_tiles = (app->t_settings_info.board_height * --curr_board_width) > MINESWEEPER_BOARD_MAX_TILES;
+        } while (is_over_max_tiles);
+
+        app->t_settings_info.board_width = curr_board_width;
+
+        snprintf(source, 5, "%" PRIu8, curr_board_width);
+        source[4] = '\0';
+
+        furi_string_set_strn(app->t_settings_info.width_str, source, 5);
+
+        variable_item_set_current_value_index(
+                app->t_settings_info.width_item,
+                app->t_settings_info.board_width-16);
+
+        variable_item_set_current_value_text(app->t_settings_info.width_item, furi_string_get_cstr(app->t_settings_info.width_str));
+    }
+
+    snprintf(source, 5, "%" PRIu8, index+7);
+    source[4] = '\0';
+
+    furi_string_set_strn(app->t_settings_info.height_str, source, 5);
+
+    variable_item_set_current_value_text(app->t_settings_info.height_item, furi_string_get_cstr(app->t_settings_info.height_str));
+
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, MineSweeperSettingsScreenEventWidthChange);
+}
+
+static void minesweeper_scene_settings_screen_set_solvable(VariableItem* item) {
+    furi_assert(item);
+
+    MineSweeperApp* app = variable_item_get_context(item);
+
+    uint8_t index = variable_item_get_current_value_index(app->t_settings_info.solvable_item);
+
+    app->t_settings_info.ensure_solvable_board = (index == 1) ? true : false;
+
+    variable_item_set_current_value_text(item, settings_screen_verifier_text[index]);
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, MineSweeperSettingsScreenEventSolvableChange);
+    
+}
+
+static void minesweeper_scene_settings_screen_set_info(VariableItem* item) {
+    furi_assert(item);
+
+    MineSweeperApp* app = variable_item_get_context(item);
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, MineSweeperSettingsScreenEventInfoChange);
+}
+
+void minesweeper_scene_settings_screen_on_enter(void* context) {
+    furi_assert(context);
+
+
+    MineSweeperApp* app = (MineSweeperApp*)context;
+    VariableItemList* va = app->settings_screen;
+    VariableItem* item;
+
+    // If we are accessing the scene and have not changed the settings
+    if (!app->is_settings_changed) {
+        // Set temp setting buffer to current state
+        app->t_settings_info = app->settings_info;
+    }
+
+    // Set Difficulty Item
+    item = variable_item_list_add(
+        va,
+        "Difficulty",
+        MineSweeperSettingsScreenDifficultyTypeNum,
+        minesweeper_scene_settings_screen_set_difficulty,
+        app);
+
+    app->t_settings_info.difficulty_item = item;
+
+    variable_item_set_current_value_index(
+            item,
+            app->t_settings_info.difficulty);
+
+    variable_item_set_current_value_text(
+            item,
+            settings_screen_difficulty_text[app->t_settings_info.difficulty]);
+
+    // Set Width Item
+    item = variable_item_list_add(
+           va,
+           "Board Width",
+           33-16,
+           minesweeper_scene_settings_screen_set_width,
+           app);
+
+    app->t_settings_info.width_item = item;
+
+    variable_item_set_current_value_index(
+            item,
+            app->t_settings_info.board_width-16);
+
+    char source[5];
+    snprintf(source, 5, "%" PRIu8, app->t_settings_info.board_width);
+    source[4] = '\0';
+    furi_string_set_strn(app->t_settings_info.width_str, source, 5);
+    
+    variable_item_set_current_value_text(
+            item,
+            furi_string_get_cstr(app->t_settings_info.width_str));
+
+    // Set Height Item
+    item = variable_item_list_add(
+           va,
+           "Board Height",
+           33-7,
+           minesweeper_scene_settings_screen_set_height,
+           app);
+
+    app->t_settings_info.height_item = item;
+
+    variable_item_set_current_value_index(
+            item,
+            app->t_settings_info.board_height-7);
+
+    snprintf(source, 5, "%" PRIu8, app->t_settings_info.board_height);
+    source[4] = '\0';
+    furi_string_set_strn(app->t_settings_info.height_str, source, 5);
+
+    variable_item_set_current_value_text(
+            item,
+            furi_string_get_cstr(app->t_settings_info.height_str));
+
+    // Set solvable item
+    item = variable_item_list_add(
+            va,
+            "Ensure Solvable",
+            2,
+            minesweeper_scene_settings_screen_set_solvable,
+            app);
+
+    app->t_settings_info.solvable_item = item;
+
+    uint8_t idx = (app->t_settings_info.ensure_solvable_board) ? 1 : 0;
+
+    variable_item_set_current_value_index(
+            item,
+            idx);
+
+    variable_item_set_current_value_text(
+            item,
+            settings_screen_verifier_text[idx]);
+    
+    // Set info item
+    item = variable_item_list_add(
+            va,
+            "Right For Info",
+            2,
+            minesweeper_scene_settings_screen_set_info,
+            app);
+
+    variable_item_set_current_value_index(
+            item,
+            0);
+
+    variable_item_set_current_value_text(
+            item,
+            "-------");
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperSettingsView);
+}
+
+bool minesweeper_scene_settings_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context; 
+    bool consumed = false;
+    
+    if (event.type == SceneManagerEventTypeCustom) {
+
+        app->is_settings_changed = (app->settings_info.board_width != app->t_settings_info.board_width  ||
+                                   app->settings_info.board_height != app->t_settings_info.board_height ||
+                                   app->settings_info.difficulty != app->t_settings_info.difficulty     ||
+                                   app->settings_info.ensure_solvable_board != app->t_settings_info.ensure_solvable_board);
+
+        switch (event.event) {
+
+            case MineSweeperSettingsScreenEventDifficultyChange :
+
+                break;
+            
+            case MineSweeperSettingsScreenEventWidthChange : 
+
+                break;
+            
+            case MineSweeperSettingsScreenEventHeightChange :
+
+                break;
+
+            case MineSweeperSettingsScreenEventSolvableChange :
+
+                break;
+
+            case MineSweeperSettingsScreenEventInfoChange :
+
+                scene_manager_next_scene(app->scene_manager, MineSweeperSceneInfoScreen);
+                break;
+
+            default :
+                break;
+        };
+        consumed = true;
+
+    } else if (event.type == SceneManagerEventTypeBack) {
+
+        // If there are changes in the width, height, or difficulty go to confirmation scren
+        if (app->is_settings_changed) { 
+
+            scene_manager_next_scene(app->scene_manager, MineSweeperSceneConfirmationScreen);
+        } else {
+
+            memset(&app->t_settings_info, 0, sizeof(app->t_settings_info));
+
+            if (!scene_manager_search_and_switch_to_previous_scene(
+                        app->scene_manager, MineSweeperSceneMenuScreen)) {
+
+                scene_manager_stop(app->scene_manager);
+                view_dispatcher_stop(app->view_dispatcher);
+
+            }
+
+        }
+
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_settings_screen_on_exit(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = (MineSweeperApp*)context;
+    VariableItemList* va = app->settings_screen;
+
+    variable_item_list_reset(va);
+}

+ 84 - 0
minesweeper/scenes/start_screen_scene.c

@@ -0,0 +1,84 @@
+#include "../minesweeper.h"
+
+typedef enum {
+    MineSweeperSceneStartScreenExitEvent,
+    MineSweeperSceneStartScreenContinueEvent,
+} MineSweeperSceneStartScreenEvent;
+
+bool minesweeper_scene_start_screen_input_callback(InputEvent* event, void* context) {
+    furi_assert(event);
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    bool consumed = false;
+
+    // Right now we continue if back is not pressed
+    if (event->key == InputKeyBack) {
+        consumed = scene_manager_handle_custom_event(
+                        app->scene_manager,
+                        MineSweeperSceneStartScreenExitEvent); 
+    } else {
+        consumed = scene_manager_handle_custom_event(
+                        app->scene_manager,
+                        MineSweeperSceneStartScreenContinueEvent); 
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_start_screen_secondary_draw_callback(Canvas* canvas, void* _model) {
+    furi_assert(canvas);
+    furi_assert(_model);
+    UNUSED(_model);
+    UNUSED(canvas);
+}
+
+void minesweeper_scene_start_screen_on_enter(void* context) {
+    furi_assert(context);
+    MineSweeperApp* app = context;
+    
+    furi_assert(app->start_screen);
+
+    start_screen_set_context(app->start_screen, app);
+
+    start_screen_set_input_callback(
+            app->start_screen,
+            minesweeper_scene_start_screen_input_callback);
+
+    start_screen_set_secondary_draw_callback(
+            app->start_screen,
+            minesweeper_scene_start_screen_secondary_draw_callback);
+    
+    start_screen_set_icon_animation(app->start_screen, 0, 0, &A_StartScreen_128x64);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperStartScreenView);
+}
+
+bool minesweeper_scene_start_screen_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    bool consumed = false;
+
+    if (event.type == SceneManagerEventTypeCustom) {
+        if (event.event == MineSweeperSceneStartScreenContinueEvent) {
+            mine_sweeper_game_screen_reset_clock(app->game_screen);
+            scene_manager_next_scene(app->scene_manager, MineSweeperSceneGameScreen); 
+            consumed = true;
+        } else if (event.event == MineSweeperSceneStartScreenExitEvent) {
+            // Exit app
+            scene_manager_stop(app->scene_manager);
+            view_dispatcher_stop(app->view_dispatcher);
+            consumed = true;
+        }
+    }
+
+    return consumed;
+}
+
+void minesweeper_scene_start_screen_on_exit(void* context) {
+    furi_assert(context);
+
+    MineSweeperApp* app = context;
+    start_screen_reset(app->start_screen);
+}

+ 1761 - 0
minesweeper/views/minesweeper_game_screen.c

@@ -0,0 +1,1761 @@
+#include "minesweeper_game_screen.h"
+#include "minesweeper_redux_icons.h"
+
+#include <gui/elements.h>
+#include <gui/icon_animation.h>
+#include <input/input.h>
+
+#include <furi.h>
+#include <furi_hal.h>
+
+static const Icon* tile_icons[13] = {
+    &I_tile_empty_8x8,
+    &I_tile_0_8x8,
+    &I_tile_1_8x8,
+    &I_tile_2_8x8,
+    &I_tile_3_8x8,
+    &I_tile_4_8x8,
+    &I_tile_5_8x8,
+    &I_tile_6_8x8,
+    &I_tile_7_8x8,
+    &I_tile_8_8x8,
+    &I_tile_mine_8x8,
+    &I_tile_flag_8x8,
+    &I_tile_uncleared_8x8,
+};
+
+// They way this enum is set up allows us to index the Icon* array above for some mine types
+typedef enum {
+    MineSweeperGameScreenTileNone = 0,
+    MineSweeperGameScreenTileZero,
+    MineSweeperGameScreenTileOne,
+    MineSweeperGameScreenTileTwo,
+    MineSweeperGameScreenTileThree,
+    MineSweeperGameScreenTileFour,
+    MineSweeperGameScreenTileFive,
+    MineSweeperGameScreenTileSix,
+    MineSweeperGameScreenTileSeven,
+    MineSweeperGameScreenTileEight,
+    MineSweeperGameScreenTileMine,
+    MineSweeperGameScreenTileTypeCount,
+} MineSweeperGameScreenTileType;
+
+typedef enum {
+    MineSweeperGameScreenTileStateFlagged,
+    MineSweeperGameScreenTileStateUncleared,
+    MineSweeperGameScreenTileStateCleared,
+} MineSweeperGameScreenTileState;
+
+struct MineSweeperGameScreen {
+    View* view;
+    void* context;
+    GameScreenInputCallback input_callback;
+};
+
+typedef struct {
+    int16_t x_abs, y_abs;
+} CurrentPosition;
+
+typedef struct {
+    uint16_t x_abs, y_abs;
+    const Icon* icon;
+} IconElement;
+
+typedef struct {
+    IconElement icon_element;
+    MineSweeperGameScreenTileState tile_state;
+    MineSweeperGameScreenTileType tile_type;
+} MineSweeperTile;
+
+typedef struct {
+    MineSweeperTile board[ MINESWEEPER_BOARD_MAX_TILES ];
+    CurrentPosition curr_pos;
+    uint8_t right_boundary, bottom_boundary,
+            board_width, board_height, board_difficulty;
+    uint16_t mines_left;
+    uint16_t flags_left;
+    uint16_t tiles_left;
+    uint32_t start_tick;
+    FuriString* info_str;
+    bool ensure_solvable_board;
+    bool is_win_triggered;
+    bool is_holding_down_button;
+} MineSweeperGameScreenModel;
+
+// Multipliers for ratio of mines to tiles
+static const float difficulty_multiplier[3] = {
+    0.15f,
+    0.17f,
+    0.19f,
+};
+
+// Offsets array used consistently when checking surrounding tiles
+static const int8_t offsets[8][2] = {
+    {-1,1},
+    {0,1},
+    {1,1},
+    {1,0},
+    {1,-1},
+    {0,-1},
+    {-1,-1},
+    {-1,0},
+};
+
+static MineSweeperTile board_t[MINESWEEPER_BOARD_MAX_TILES];
+
+/****************************************************************
+ * Function declarations
+ *
+ * Non public function declarations
+ ***************************************************************/
+
+// Static helper functions
+
+static void setup_board(MineSweeperGameScreen* instance);
+
+static bool check_board_with_verifier(
+        MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        uint16_t total_mines);
+
+static inline void bfs_tile_clear_verifier(
+        MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        const uint16_t x,
+        const uint16_t y,
+        point_deq_t* edges,
+        point_set_t* visited);
+
+static uint16_t bfs_tile_clear(MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        const uint16_t x,
+        const uint16_t y);
+
+static void mine_sweeper_game_screen_set_board_information(
+        MineSweeperGameScreen* instance,
+        const uint8_t width,
+        const uint8_t height,
+        const uint8_t difficulty,
+        bool is_solvable);
+
+static bool try_clear_surrounding_tiles(MineSweeperGameScreenModel* model);
+
+static Point bfs_to_closest_tile(MineSweeperGameScreenModel* model);
+
+// Currently not using enter/exit callback
+static void mine_sweeper_game_screen_view_enter(void* context);
+static void mine_sweeper_game_screen_view_exit(void* context);
+
+// Different input/draw callbacks for play/win/lose state
+static void mine_sweeper_game_screen_view_win_draw_callback(Canvas* canvas, void* _model);
+static void mine_sweeper_game_screen_view_lose_draw_callback(Canvas* canvas, void* _model);
+static void mine_sweeper_game_screen_view_play_draw_callback(Canvas* canvas, void* _model);
+
+// These consolidate the function calls for led/haptic/sound for specific events
+static void mine_sweeper_long_ok_effect(void* context);
+static void mine_sweeper_short_ok_effect(void* context);
+static void mine_sweeper_flag_effect(void* context);
+static void mine_sweeper_move_effect(void* context);
+static void mine_sweeper_oob_effect(void* context);
+static void mine_sweeper_lose_effect(void* context);
+static void mine_sweeper_win_effect(void* context);
+
+static bool mine_sweeper_game_screen_view_end_input_callback(InputEvent* event, void* context);
+static bool mine_sweeper_game_screen_view_play_input_callback(InputEvent* event, void* context);
+
+
+/**************************************************************
+ * Function definitions
+ *************************************************************/
+
+/**
+ * This function is called on alloc, reset, and win/lose condition.
+ * It sets up a random board to be checked by the verifier
+ */
+static void setup_board(MineSweeperGameScreen* instance) {
+    furi_assert(instance);
+
+    uint16_t board_tile_count = 0;
+    uint8_t board_width = 0, board_height = 0, board_difficulty = 0;
+
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            board_width = model->board_width;
+            board_height = model->board_height;
+            board_tile_count =  (model->board_width*model->board_height);
+            board_difficulty = model->board_difficulty;
+        },
+        false
+    );
+
+    uint16_t num_mines = board_tile_count * difficulty_multiplier[ board_difficulty ];
+
+    /** We can use a temporary buffer to set the tile types initially
+     * and manipulate then save to actual model
+     */
+    MineSweeperGameScreenTileType tiles[MINESWEEPER_BOARD_MAX_TILES];
+    memset(&tiles, MineSweeperGameScreenTileNone, sizeof(tiles));
+
+    // Randomly place tiles except in the corners to help guarantee solvability
+    for (uint16_t i = 0; i < num_mines; i++) {
+
+        uint16_t rand_pos;
+        uint16_t x;
+        uint16_t y;
+        bool is_invalid_position;
+        do {
+
+            rand_pos = furi_hal_random_get() % board_tile_count;
+            x = rand_pos / board_width;
+            y = rand_pos % board_width;
+
+            is_invalid_position = ((rand_pos == 0)                      ||
+                                         (x==0 && y==1)                 ||
+                                         (x==1 && y==0)                 ||
+                                         rand_pos == board_tile_count-1 ||
+                                         (x==0 && y==board_width-1)     ||
+                                         (x==board_height-1 && y==0));
+
+
+        } while (tiles[rand_pos] == MineSweeperGameScreenTileMine || is_invalid_position);
+
+        tiles[rand_pos] = MineSweeperGameScreenTileMine;
+    }
+
+    /** All mines are set so we look at each tile for surrounding mines */
+    for (uint16_t i = 0; i < board_tile_count; i++) {
+        MineSweeperGameScreenTileType tile_type = tiles[i];
+
+        if (tile_type == MineSweeperGameScreenTileMine) {
+            continue;
+        }
+
+        uint16_t mine_count = 0;
+
+        uint16_t x = i / board_width;
+        uint16_t y = i % board_width;
+
+        for (uint8_t j = 0; j < 8; j++) {
+            int16_t dx = x + (int16_t)offsets[j][0];
+            int16_t dy = y + (int16_t)offsets[j][1];
+
+            if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                continue;
+            }
+
+            uint16_t pos = dx * board_width + dy;
+            if (tiles[pos] == MineSweeperGameScreenTileMine) {
+                mine_count++;
+            }
+
+        }
+
+        tiles[i] = (MineSweeperGameScreenTileType) mine_count+1;
+
+    }
+
+    // Save tiles to view model
+    // Because of way tile enum and tile_icons array is set up we can
+    // index tile_icons with the enum type to get the correct Icon*
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            for (uint16_t i = 0; i < board_tile_count; i++) {
+                model->board[i].tile_type = tiles[i];
+                model->board[i].tile_state = MineSweeperGameScreenTileStateUncleared;
+                model->board[i].icon_element.icon = tile_icons[ tiles[i] ];
+                model->board[i].icon_element.x_abs = (i/model->board_width);
+                model->board[i].icon_element.y_abs = (i%model->board_width);
+            }
+
+            model->mines_left = num_mines;
+            model->flags_left = num_mines;
+            model->tiles_left = (model->board_width * model->board_height) - model->mines_left;
+            model->curr_pos.x_abs = 0;
+            model->curr_pos.y_abs = 0;
+            model->right_boundary = MINESWEEPER_SCREEN_TILE_WIDTH;
+            model->bottom_boundary = MINESWEEPER_SCREEN_TILE_HEIGHT;
+            model->is_win_triggered = false;         
+        },
+        true
+    );
+
+}
+
+/**
+ *  This function serves as the verifier for a board to check whether it has to be solved ambiguously or not
+ *
+ *  Returns true if it is unambiguously solvable.
+ */
+static bool check_board_with_verifier(
+        MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        uint16_t total_mines) {
+
+    furi_assert(board);
+
+    // Double ended queue used to track edges.
+    point_deq_t deq;
+    point_set_t visited;
+    
+    // Ordered Set for visited points
+    point_deq_init(deq);
+    point_set_init(visited);
+
+    bool is_solvable = false;
+
+    // Point_t pos will be used to keep track of the current point
+    Point_t pos;
+    pointobj_init(pos);
+
+    // Starting position is 0,0
+    Point start_pos = (Point){.x = 0, .y = 0};
+    pointobj_set_point(pos, start_pos);
+
+    // Initially bfs clear from 0,0 as it is safe. We should push all 'edges' found
+    // into the deq and this will be where we start off from
+    bfs_tile_clear_verifier(board, board_width, board_height, 0, 0, &deq, &visited);
+                                                             
+    //While we have valid edges to check and have not solved the board
+    while (!is_solvable && point_deq_size(deq) > 0) {
+
+        bool is_stuck = true; // This variable will track if any flag was placed for any edge to see if we are stuck
+                              
+        uint16_t deq_size = point_deq_size(deq);
+
+        // Iterate through all edge tiles and push new ones on
+        while (deq_size-- > 0) {
+
+            // Pop point and get 1d position in buffer
+            point_deq_pop_front(&pos, deq);
+            Point curr_pos = pointobj_get_point(pos);
+            uint16_t curr_pos_1d = curr_pos.x * board_width + curr_pos.y;
+
+            // Get tile at 1d position
+            MineSweeperTile tile = board[curr_pos_1d];
+            uint8_t tile_num = tile.tile_type - 1;
+            
+            // Track total surrounding tiles and flagged tiles
+            uint8_t num_surrounding_tiles = 0;
+            uint8_t num_flagged_tiles = 0;
+
+            for (uint8_t j = 0; j < 8; j++) {
+                int16_t dx = curr_pos.x + (int16_t)offsets[j][0];
+                int16_t dy = curr_pos.y + (int16_t)offsets[j][1];
+
+                if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                    continue;
+                }
+
+                uint16_t pos = dx * board_width + dy;
+                if (board[pos].tile_state == MineSweeperGameScreenTileStateUncleared) {
+                    num_surrounding_tiles++;
+                } else if (board[pos].tile_state == MineSweeperGameScreenTileStateFlagged) {
+                    num_surrounding_tiles++;
+                    num_flagged_tiles++;
+                }
+
+            }
+            
+            if (num_flagged_tiles == tile_num) {
+                
+                // If the tile has the same number of surrounding flags as its type we bfs clear the uncleared surrounding tiles
+                // pushing new unvisited edges on deq
+
+                for (uint8_t j = 0; j < 8; j++) {
+                    int16_t dx = curr_pos.x + (int16_t)offsets[j][0];
+                    int16_t dy = curr_pos.y + (int16_t)offsets[j][1];
+
+                    if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                        continue;
+                    }
+
+                    uint16_t pos = dx * board_width + dy;
+                    if (board[pos].tile_state == MineSweeperGameScreenTileStateUncleared) {
+                        bfs_tile_clear_verifier(board, board_width, board_height, dx, dy, &deq, &visited);
+                    }
+
+                }
+
+                is_stuck = false;
+
+            } else if (num_surrounding_tiles == tile_num) {
+
+                // If the number of surrounding tiles is the tile num it is unambiguous so we place a flag on those tiles,
+                // decrement the mine count appropriately and check win condition, and then mark stuck as false
+
+                for (uint8_t j = 0; j < 8; j++) {
+                    int16_t dx = curr_pos.x + (int16_t)offsets[j][0];
+                    int16_t dy = curr_pos.y + (int16_t)offsets[j][1];
+
+                    if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                        continue;
+                    }
+
+                    uint16_t pos = dx * board_width + dy;
+                    if (board[pos].tile_state == MineSweeperGameScreenTileStateUncleared) {
+                        board[pos].tile_state = MineSweeperGameScreenTileStateFlagged;
+                    }
+                }
+
+                total_mines -= (num_surrounding_tiles - num_flagged_tiles);
+
+                if (total_mines == 0) is_solvable = true;
+                 
+                is_stuck = false;
+
+            } else if (num_surrounding_tiles != 0) {
+
+                // If we have tiles around this position but the number of flagged tiles != tile num
+                // and the surrounding tiles != tile num this means the tile is ambiguous. We can push
+                // it back on the deq to be reprocessed with any other new edges
+                
+                point_deq_push_back(deq, pos);
+
+            }
+        }
+        
+        // If we are stuck we break as it is an ambiguous map generation
+        if (is_stuck) {
+            break;
+        }
+    }
+
+    point_set_clear(visited);
+    point_deq_clear(deq);
+
+    return is_solvable;
+
+}
+
+/**
+ * This is a bfs_tile clear used by the verifier which performs the normal tile clear
+ * but also pushes new edges to the deq passed in. There is a separate function used
+ * for the bfs_tile_clear used on the user click
+ */
+static inline void bfs_tile_clear_verifier(
+        MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        const uint16_t x,
+        const uint16_t y,
+        point_deq_t* edges,
+        point_set_t* visited) {
+
+    furi_assert(board);
+    furi_assert(edges);
+    furi_assert(visited);
+    
+    // Init both the set and dequeue
+    point_deq_t deq;
+    point_set_t set;
+
+    point_deq_init(deq);
+    point_set_init(set);
+
+    // Point_t pos will be used to keep track of the current point
+    Point_t pos;
+    pointobj_init(pos);
+
+    // Starting position is current pos
+    Point start_pos = (Point){.x = x, .y = y};
+    pointobj_set_point(pos, start_pos);
+
+    point_deq_push_back(deq, pos);
+    
+    while (point_deq_size(deq) > 0) {
+
+        point_deq_pop_front(&pos, deq);
+        Point curr_pos = pointobj_get_point(pos);
+        uint16_t curr_pos_1d = curr_pos.x * board_width + curr_pos.y;
+        
+        // If in visited set
+        if (point_set_cget(set, pos) != NULL || point_set_cget(*visited, pos) != NULL) {
+        } 
+        
+        // If it is cleared continue
+        if (board[curr_pos_1d].tile_state == MineSweeperGameScreenTileStateCleared) {
+            continue;
+        }
+        
+        // Else set tile to cleared
+        board[curr_pos_1d].tile_state = MineSweeperGameScreenTileStateCleared;
+        
+        // Add point to visited set
+        point_set_push(set, pos);
+
+        //When we hit a potential edge
+        if (board[curr_pos_1d].tile_type != MineSweeperGameScreenTileZero) {
+
+            // We can push this edge into edges if it is not in visited, as it is a new edge
+            // and also add to the visited set
+            if (point_set_cget(*visited, pos) == NULL) {
+                point_deq_push_back(*edges, pos);
+                point_set_push(*visited, pos);
+            }
+
+            // Continue processing next point for bfs tile clear
+            continue;
+        }
+
+        // Process all surrounding neighbors and add valid to dequeue
+        for (uint8_t i = 0; i < 8; i++) {
+            int16_t dx = curr_pos.x + (int16_t)offsets[i][0];
+            int16_t dy = curr_pos.y + (int16_t)offsets[i][1];
+
+            if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                continue;
+            }
+            
+            Point neighbor = (Point) {.x = dx, .y = dy};
+            pointobj_set_point(pos, neighbor);
+
+            if (point_set_cget(set, pos) != NULL || point_set_cget(*visited, pos) != NULL) continue;
+
+            point_deq_push_back(deq, pos);
+        }
+    }
+
+    point_set_clear(set);
+    point_deq_clear(deq);
+}
+
+/**
+ * This is a bfs_tile clear used in the input callbacks to clear the board on user input
+ */
+static inline uint16_t bfs_tile_clear(
+        MineSweeperTile* board,
+        const uint8_t board_width,
+        const uint8_t board_height,
+        const uint16_t x,
+        const uint16_t y) {
+
+    furi_assert(board);
+
+    // We will return this number as the number of tiles cleared
+    uint16_t ret = 0;
+    
+    // Init both the set and dequeue
+    point_deq_t deq;
+    point_set_t set;
+
+    point_deq_init(deq);
+    point_set_init(set);
+
+    // Point_t pos will be used to keep track of the current point
+    Point_t pos;
+    pointobj_init(pos);
+
+    // Starting position is current pos
+    Point start_pos = (Point){.x = x, .y = y};
+    pointobj_set_point(pos, start_pos);
+
+    point_deq_push_back(deq, pos);
+    
+    while (point_deq_size(deq) > 0) {
+
+        point_deq_pop_front(&pos, deq);
+        Point curr_pos = pointobj_get_point(pos);
+        uint16_t curr_pos_1d = curr_pos.x * board_width + curr_pos.y;
+        
+        // If in visited set
+        if (point_set_cget(set, pos) != NULL) {
+            continue;
+        } 
+        
+        // If it is not uncleared continue
+        if (board[curr_pos_1d].tile_state != MineSweeperGameScreenTileStateUncleared) {
+            continue;
+        }
+        
+        // Else set tile to cleared
+        board[curr_pos_1d].tile_state = MineSweeperGameScreenTileStateCleared;
+        
+        // Increment total number of cleared tiles
+        ret++;
+
+        // Add point to visited set
+        point_set_push(set, pos);
+
+        // If it is not a zero tile continue
+        if (board[curr_pos_1d].tile_type != MineSweeperGameScreenTileZero) {
+            continue;
+        }
+
+        // Process all surrounding neighbors and add valid to dequeue
+        for (uint8_t i = 0; i < 8; i++) {
+            int16_t dx = curr_pos.x + (int16_t)offsets[i][0];
+            int16_t dy = curr_pos.y + (int16_t)offsets[i][1];
+
+            if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                continue;
+            }
+            
+            Point neighbor = (Point) {.x = dx, .y = dy};
+            pointobj_set_point(pos, neighbor);
+
+            if (point_set_cget(set, pos) != NULL) continue;
+
+            point_deq_push_back(deq, pos);
+        }
+    }
+
+    point_set_clear(set);
+    point_deq_clear(deq);
+    
+    return ret;
+}
+
+static void mine_sweeper_game_screen_set_board_information(
+        MineSweeperGameScreen* instance,
+        uint8_t width,
+        uint8_t height,
+        uint8_t difficulty,
+        bool is_solvable) {
+
+    furi_assert(instance);
+
+    // These are the min/max values that can actually be set
+    if (width  > 146) {width = 146;}
+    if (width  < 16 ) {width = 16;}
+    if (height > 64 ) {height = 64;}
+    if (height < 7  ) {height = 7;}
+    if (difficulty > 2 ) {difficulty = 2;}
+    
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            model->board_width = width;
+            model->board_height = height;
+            model->board_difficulty = difficulty;
+            model->ensure_solvable_board = is_solvable;
+        },
+        true
+    );
+}
+
+// THIS FUNCTION CAN TRIGGER THE LOSE CONDITION
+static bool try_clear_surrounding_tiles(MineSweeperGameScreenModel* model) {
+    furi_assert(model);
+
+
+    uint8_t curr_x = model->curr_pos.x_abs;
+    uint8_t curr_y = model->curr_pos.y_abs;
+    uint8_t board_width = model->board_width;
+    uint8_t board_height = model->board_height;
+    uint16_t curr_pos_1d = curr_x * board_width + curr_y;
+
+    MineSweeperTile tile = model->board[curr_pos_1d];
+
+    // Return true if tile is zero tile or not cleared
+    if (tile.tile_state != MineSweeperGameScreenTileStateCleared || tile.tile_type == MineSweeperGameScreenTileZero) {
+        return false;
+    }
+
+    uint8_t num_surrounding_flagged = 0;
+    bool was_mine_found = false;
+    bool is_lose_condition_triggered = false;
+
+    for (uint8_t j = 0; j < 8; j++) {
+        int16_t dx = curr_x + (int16_t)offsets[j][0];
+        int16_t dy = curr_y + (int16_t)offsets[j][1];
+
+        if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+            continue;
+        }
+
+        uint16_t pos = dx * board_width + dy;
+        if (model->board[pos].tile_state == MineSweeperGameScreenTileStateFlagged) {
+            num_surrounding_flagged++;
+        } else if (!was_mine_found && model->board[pos].tile_type == MineSweeperGameScreenTileMine
+                && model->board[pos].tile_state != MineSweeperGameScreenTileStateFlagged) {
+            was_mine_found = true;
+        }
+
+    }
+
+    // We clear surrounding tile
+    if (num_surrounding_flagged >= tile.tile_type-1) {
+        if (was_mine_found) is_lose_condition_triggered = true;
+
+
+        for (uint8_t j = 0; j < 8; j++) {
+            int16_t dx = curr_x + (int16_t)offsets[j][0];
+            int16_t dy = curr_y + (int16_t)offsets[j][1];
+
+            if (dx < 0 || dy < 0 || dx >= board_height || dy >= board_width) {
+                continue;
+            }
+
+            uint16_t pos = dx * board_width + dy;
+            if (model->board[pos].tile_state == MineSweeperGameScreenTileStateUncleared) {
+                // Decrement tiles left by the amount cleared
+                uint16_t tiles_cleared = bfs_tile_clear(model->board, model->board_width, model->board_height, dx, dy);
+                model->tiles_left -= tiles_cleared;
+            }
+
+        }
+    }
+
+    return is_lose_condition_triggered;
+
+}
+
+/**
+ * Function is used on a long backpress on a cleared tile and returns the position
+ * of the first found uncleared tile using a bfs search
+ */
+static inline Point bfs_to_closest_tile(MineSweeperGameScreenModel* model) {
+    furi_assert(model);
+
+    // Init both the set and dequeue
+    point_deq_t deq;
+    point_set_t set;
+
+    point_deq_init(deq);
+    point_set_init(set);
+
+    // Return the value in this point
+    Point result;
+
+    // Point_t pos will be used to keep track of the current point
+    Point_t pos;
+    pointobj_init(pos);
+
+    // Starting position is current pos
+    Point start_pos = (Point){.x = model->curr_pos.x_abs, .y = model->curr_pos.y_abs};
+    pointobj_set_point(pos, start_pos);
+
+    point_deq_push_back(deq, pos);
+
+    while (point_deq_size(deq) > 0) {
+        point_deq_pop_front(&pos, deq);
+        Point curr_pos = pointobj_get_point(pos);
+        uint16_t curr_pos_1d = curr_pos.x * model->board_width + curr_pos.y;
+
+        // If the current tile is uncleared and not start pos we save result
+        // to this position and break 
+        if (model->board[curr_pos_1d].tile_state == MineSweeperGameScreenTileStateUncleared &&
+                !(start_pos.x ==  curr_pos.x && start_pos.y == curr_pos.y)) {
+
+            result = curr_pos;
+            break;
+        }
+        
+        // If in visited set continue
+        if (point_set_cget(set, pos) != NULL) {
+            continue;
+        } 
+        
+        // Add point to visited set
+        point_set_push(set, pos);
+
+
+        // Process all surrounding neighbors and add valid to dequeue
+        for (uint8_t i = 0; i < 8; i++) {
+            int16_t dx = curr_pos.x + (int16_t)offsets[i][0];
+            int16_t dy = curr_pos.y + (int16_t)offsets[i][1];
+
+            if (dx < 0 || dy < 0 || dx >= model->board_height || dy >= model->board_width) {
+                continue;
+            }
+                
+            Point neighbor = (Point) {.x = dx, .y = dy};
+            pointobj_set_point(pos, neighbor);
+            point_deq_push_back(deq, pos);
+        }
+    }
+
+    point_set_clear(set);
+    point_deq_clear(deq);
+
+    return result;
+}
+
+static void mine_sweeper_game_screen_view_enter(void* context) {
+    furi_assert(context);
+    UNUSED(context);
+}
+
+static void mine_sweeper_game_screen_view_exit(void* context) {
+    furi_assert(context);
+    UNUSED(context);
+}
+
+static void mine_sweeper_game_screen_view_win_draw_callback(Canvas* canvas, void* _model) {
+    furi_assert(canvas);
+    furi_assert(_model);
+    MineSweeperGameScreenModel* model = _model;
+
+    canvas_clear(canvas);
+
+    canvas_set_color(canvas, ColorBlack);
+    
+    uint16_t cursor_pos_1d = model->curr_pos.x_abs * model->board_width + model->curr_pos.y_abs;
+    
+    for (uint8_t x_rel = 0; x_rel < MINESWEEPER_SCREEN_TILE_HEIGHT; x_rel++) {
+        uint16_t x_abs = (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) + x_rel;
+        
+        for (uint8_t y_rel = 0; y_rel < MINESWEEPER_SCREEN_TILE_WIDTH; y_rel++) {
+            uint16_t y_abs = (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) + y_rel;
+
+            uint16_t curr_rendering_tile_pos_1d = x_abs * model->board_width + y_abs;
+            MineSweeperTile tile = model->board[curr_rendering_tile_pos_1d];
+
+            if (cursor_pos_1d == curr_rendering_tile_pos_1d) {
+                canvas_set_color(canvas, ColorWhite);
+            } else {
+                canvas_set_color(canvas, ColorBlack);
+            }
+
+            canvas_draw_icon(
+                canvas,
+                y_rel * icon_get_width(tile.icon_element.icon),
+                x_rel * icon_get_height(tile.icon_element.icon),
+                tile.icon_element.icon);
+
+        }
+    }
+
+    canvas_set_color(canvas, ColorBlack);
+    // If any borders are at the limits of the game board we draw a border line
+    
+    // Right border 
+    if (model->right_boundary == model->board_width) {
+        canvas_draw_line(canvas, 127,0,127,63-8);
+    }
+
+    // Left border
+    if ((model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) == 0) {
+        canvas_draw_line(canvas, 0,0,0,63-8);
+    }
+
+    // Bottom border
+    if (model->bottom_boundary == model->board_height) {
+        canvas_draw_line(canvas, 0,63-8,127,63-8);
+    }
+
+    // Top border
+    if ((model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) == 0) {
+        canvas_draw_line(canvas, 0,0,127,0);
+    }
+
+
+    // Draw win text
+    furi_string_printf(
+            model->info_str,
+            "YOU WIN!");
+
+    canvas_draw_str_aligned(
+            canvas,
+            0,
+            64-7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+    // Draw time text
+    uint32_t ticks_elapsed = furi_get_tick() - model->start_tick;
+    uint32_t sec = ticks_elapsed / furi_kernel_get_tick_frequency();
+    uint32_t minutes = sec / 60;
+    sec = sec % 60;
+
+    furi_string_printf(
+             model->info_str,
+             "%02ld:%02ld",
+             minutes,
+             sec);
+
+    canvas_draw_str_aligned(
+            canvas,
+            126 - canvas_string_width(canvas, furi_string_get_cstr(model->info_str)),
+            64 - 7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+}
+
+static void mine_sweeper_game_screen_view_lose_draw_callback(Canvas* canvas, void* _model) {
+    furi_assert(canvas);
+    furi_assert(_model);
+    MineSweeperGameScreenModel* model = _model;
+
+    canvas_clear(canvas);
+
+    uint16_t cursor_pos_1d = model->curr_pos.x_abs * model->board_width + model->curr_pos.y_abs;
+    
+    for (uint8_t x_rel = 0; x_rel < MINESWEEPER_SCREEN_TILE_HEIGHT; x_rel++) {
+        uint16_t x_abs = (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) + x_rel;
+        
+        for (uint8_t y_rel = 0; y_rel < MINESWEEPER_SCREEN_TILE_WIDTH; y_rel++) {
+            uint16_t y_abs = (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) + y_rel;
+
+            uint16_t curr_rendering_tile_pos_1d = x_abs * model->board_width + y_abs;
+            MineSweeperTile tile = model->board[curr_rendering_tile_pos_1d];
+
+            if (cursor_pos_1d == curr_rendering_tile_pos_1d) {
+                canvas_set_color(canvas, ColorWhite);
+            } else {
+                canvas_set_color(canvas, ColorBlack);
+            }
+
+            canvas_draw_icon(
+                canvas,
+                y_rel * icon_get_width(tile.icon_element.icon),
+                x_rel * icon_get_height(tile.icon_element.icon),
+                tile.icon_element.icon);
+
+        }
+    }
+
+    canvas_set_color(canvas, ColorBlack);
+    // If any borders are at the limits of the game board we draw a border line
+    
+    // Right border 
+    if (model->right_boundary == model->board_width) {
+        canvas_draw_line(canvas, 127,0,127,63-8);
+    }
+
+    // Left border
+    if ((model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) == 0) {
+        canvas_draw_line(canvas, 0,0,0,63-8);
+    }
+
+    // Bottom border
+    if (model->bottom_boundary == model->board_height) {
+        canvas_draw_line(canvas, 0,63-8,127,63-8);
+    }
+
+    // Top border
+    if ((model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) == 0) {
+        canvas_draw_line(canvas, 0,0,127,0);
+    }
+
+    // Draw lose text
+    furi_string_printf(
+            model->info_str,
+            "YOU LOSE!");
+
+    canvas_draw_str_aligned(
+            canvas,
+            0,
+            64-7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+    // Draw time text
+    uint32_t ticks_elapsed = furi_get_tick() - model->start_tick;
+    uint32_t sec = ticks_elapsed / furi_kernel_get_tick_frequency();
+    uint32_t minutes = sec / 60;
+    sec = sec % 60;
+
+    furi_string_printf(
+             model->info_str,
+             "%02ld:%02ld",
+             minutes,
+             sec);
+
+    canvas_draw_str_aligned(
+            canvas,
+            126 - canvas_string_width(canvas, furi_string_get_cstr(model->info_str)),
+            64 - 7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+}
+
+static void mine_sweeper_game_screen_view_play_draw_callback(Canvas* canvas, void* _model) {
+    furi_assert(canvas);
+    furi_assert(_model);
+
+    MineSweeperGameScreenModel* model = _model;
+
+    canvas_clear(canvas);
+
+    
+    uint16_t cursor_pos_1d = model->curr_pos.x_abs * model->board_width + model->curr_pos.y_abs;
+    
+    for (uint8_t x_rel = 0; x_rel < MINESWEEPER_SCREEN_TILE_HEIGHT; x_rel++) {
+        uint16_t x_abs = (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) + x_rel;
+        
+        for (uint8_t y_rel = 0; y_rel < MINESWEEPER_SCREEN_TILE_WIDTH; y_rel++) {
+            uint16_t y_abs = (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) + y_rel;
+
+            uint16_t curr_rendering_tile_pos_1d = x_abs * model->board_width + y_abs;
+            MineSweeperTile tile = model->board[curr_rendering_tile_pos_1d];
+
+            if (cursor_pos_1d == curr_rendering_tile_pos_1d) {
+                canvas_set_color(canvas, ColorWhite);
+            } else {
+                canvas_set_color(canvas, ColorBlack);
+            }
+
+            switch (tile.tile_state) {
+
+                case MineSweeperGameScreenTileStateFlagged :
+                    canvas_draw_icon(
+                        canvas,
+                        y_rel * icon_get_width(tile.icon_element.icon),
+                        x_rel * icon_get_height(tile.icon_element.icon),
+                        tile_icons[11]);
+
+                    break;
+                case MineSweeperGameScreenTileStateUncleared :
+                    canvas_draw_icon(
+                        canvas,
+                        y_rel * icon_get_width(tile.icon_element.icon),
+                        x_rel * icon_get_height(tile.icon_element.icon),
+                        tile_icons[12]);
+
+                    break;
+                case MineSweeperGameScreenTileStateCleared :
+                    canvas_draw_icon(
+                        canvas,
+                        y_rel * icon_get_width(tile.icon_element.icon),
+                        x_rel * icon_get_height(tile.icon_element.icon),
+                        tile.icon_element.icon);
+                    break;
+                default:
+                    break;
+            }
+
+        }
+    }
+
+    canvas_set_color(canvas, ColorBlack);
+    // If any borders are at the limits of the game board we draw a border line
+    
+    // Right border 
+    if (model->right_boundary == model->board_width) {
+        canvas_draw_line(canvas, 127,0,127,63-8);
+    }
+
+    // Left border
+    if ((model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH) == 0) {
+        canvas_draw_line(canvas, 0,0,0,63-8);
+    }
+
+    // Bottom border
+    if (model->bottom_boundary == model->board_height) {
+        canvas_draw_line(canvas, 0,63-8,127,63-8);
+    }
+
+    // Top border
+    if ((model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT) == 0) {
+        canvas_draw_line(canvas, 0,0,127,0);
+    }
+
+    // Draw X Position Text 
+    furi_string_printf(
+            model->info_str,
+            "X:%03hhd",
+            model->curr_pos.x_abs);
+
+    canvas_draw_str_aligned(
+            canvas,
+            0,
+            64-7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+    // Draw Y Position Text 
+    furi_string_printf(
+            model->info_str,
+            "Y:%03hhd",
+            model->curr_pos.y_abs);
+
+    canvas_draw_str_aligned(
+            canvas,
+            33,
+            64-7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+    // Draw flag text
+    furi_string_printf(
+            model->info_str,
+            "F:%03hd",
+            model->flags_left);
+
+    canvas_draw_str_aligned(
+            canvas,
+            66,
+            64 - 7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+    // Draw time text
+    uint32_t ticks_elapsed = furi_get_tick() - model->start_tick;
+    uint32_t sec = ticks_elapsed / furi_kernel_get_tick_frequency();
+    uint32_t minutes = sec / 60;
+    sec = sec % 60;
+
+    furi_string_printf(
+             model->info_str,
+             "%02ld:%02ld",
+             minutes,
+             sec);
+
+    canvas_draw_str_aligned(
+            canvas,
+            126 - canvas_string_width(canvas, furi_string_get_cstr(model->info_str)),
+            64 - 7,
+            AlignLeft,
+            AlignTop,
+            furi_string_get_cstr(model->info_str));
+
+}
+
+static void mine_sweeper_short_ok_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+
+    mine_sweeper_led_blink_magenta(instance->context);
+    mine_sweeper_play_ok_sound(instance->context);
+    mine_sweeper_play_happy_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+}
+
+static void mine_sweeper_long_ok_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+
+    mine_sweeper_led_blink_magenta(instance->context);
+    mine_sweeper_play_ok_sound(instance->context);
+    mine_sweeper_play_long_ok_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+}
+
+static void mine_sweeper_flag_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+
+    mine_sweeper_led_blink_cyan(instance->context);
+    mine_sweeper_play_flag_sound(instance->context);
+    mine_sweeper_play_happy_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+}
+
+static void mine_sweeper_move_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+    
+    mine_sweeper_play_happy_bump(instance->context);
+}
+
+static void mine_sweeper_oob_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+    
+    mine_sweeper_led_blink_red(instance->context);
+    mine_sweeper_play_flag_sound(instance->context);
+    mine_sweeper_play_oob_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+
+}
+
+static void mine_sweeper_lose_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+
+    mine_sweeper_led_set_rgb(instance->context, 255, 0, 000);
+    mine_sweeper_play_lose_sound(instance->context);
+    mine_sweeper_play_lose_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+
+}
+
+static void mine_sweeper_win_effect(void* context) {
+    furi_assert(context);
+    MineSweeperGameScreen* instance = context;
+
+    mine_sweeper_led_set_rgb(instance->context, 0, 0, 255);
+    mine_sweeper_play_win_sound(instance->context);
+    mine_sweeper_play_win_bump(instance->context);
+    mine_sweeper_stop_all_sound(instance->context);
+
+}
+
+static bool mine_sweeper_game_screen_view_end_input_callback(InputEvent* event, void* context) {
+    furi_assert(context);
+    furi_assert(event);
+
+    MineSweeperGameScreen* instance = context;
+    bool consumed = false;
+
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            if (event->type == InputTypeRelease) {
+
+                model->is_holding_down_button = false;
+                consumed = true;
+
+            } else if (!model->is_holding_down_button && (event->type == InputTypePress || event->type == InputTypeRepeat)) {
+
+                bool is_outside_boundary;
+                switch (event->key) {
+
+                    case InputKeyUp :
+                        model->curr_pos.x_abs = (model->curr_pos.x_abs-1 < 0) ? 0 : model->curr_pos.x_abs-1;
+
+                        is_outside_boundary = model->curr_pos.x_abs <
+                            (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT);
+                        
+                        if (is_outside_boundary) {
+                            model->bottom_boundary--;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyDown :
+                        model->curr_pos.x_abs = (model->curr_pos.x_abs+1 >= model->board_height) ?
+                            model->board_height-1 : model->curr_pos.x_abs+1;
+
+                        is_outside_boundary = model->curr_pos.x_abs >= model->bottom_boundary;
+
+                        if (is_outside_boundary) {
+                            model->bottom_boundary++;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyLeft :
+                        model->curr_pos.y_abs = (model->curr_pos.y_abs-1 < 0) ? 0 : model->curr_pos.y_abs-1;
+
+                        is_outside_boundary = model->curr_pos.y_abs <
+                            (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH);
+                        
+                        if (is_outside_boundary) {
+                            model->right_boundary--;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyRight :
+                        model->curr_pos.y_abs = (model->curr_pos.y_abs+1 >= model->board_width) ?
+                            model->board_width-1 : model->curr_pos.y_abs+1;
+
+                        is_outside_boundary = model->curr_pos.y_abs >= model->right_boundary;
+
+                        if (is_outside_boundary) {
+                            model->right_boundary++;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    default: // Anything other than movement around the screen should restart game
+                        mine_sweeper_led_reset(instance->context);
+
+                        mine_sweeper_game_screen_reset_clock(instance);
+                        view_set_draw_callback(
+                                instance->view,
+                                mine_sweeper_game_screen_view_play_draw_callback);
+                        view_set_input_callback(
+                                instance->view,
+                                mine_sweeper_game_screen_view_play_input_callback);
+
+                        // Here we are going to generate a valid map for the player 
+                        bool is_valid_board = false;
+
+                        size_t memsz = sizeof(MineSweeperTile) * MINESWEEPER_BOARD_MAX_TILES;
+
+                        do {
+                            setup_board(instance);
+
+                            memset(board_t, 0, memsz);
+                            memcpy(board_t, model->board, sizeof(MineSweeperTile) * (model->board_width * model->board_height));
+
+                            is_valid_board = check_board_with_verifier(
+                                                            board_t,
+                                                            model->board_width,
+                                                            model->board_height,
+                                                            model->mines_left);
+                        
+
+                        } while (model->ensure_solvable_board && !is_valid_board);
+
+                        consumed = true;
+                        break;
+                    }
+
+                    consumed = true; 
+
+                }
+
+            },
+        false
+    );
+
+    return consumed;
+}
+
+static bool mine_sweeper_game_screen_view_play_input_callback(InputEvent* event, void* context) {
+    furi_assert(context);
+    furi_assert(event);
+
+    MineSweeperGameScreen* instance = context;
+    bool consumed = false;
+
+
+    // Checking button types
+
+    if (event->type == InputTypeRelease) {
+        with_view_model(
+            instance->view,
+            MineSweeperGameScreenModel * model,
+            {
+                model->is_holding_down_button = false;
+                consumed = true;
+            },
+            true);
+    }
+
+    if (!consumed && event->key == InputKeyOk) { // Attempt to Clear Space !! THIS CAN BE A LOSE CONDITION
+
+        bool is_lose_condition_triggered = false;
+        bool is_win_condition_triggered = false;
+
+        with_view_model(
+            instance->view,
+            MineSweeperGameScreenModel * model,
+            {   
+                uint16_t curr_pos_1d = model->curr_pos.x_abs * model->board_width + model->curr_pos.y_abs;
+
+                if (!model->is_holding_down_button && event->type == InputTypePress) { 
+                    
+                    MineSweeperGameScreenTileState state = model->board[curr_pos_1d].tile_state;
+                    MineSweeperGameScreenTileType type = model->board[curr_pos_1d].tile_type;
+
+                    // LOSE/WIN CONDITION OR TILE CLEAR
+                    if (state == MineSweeperGameScreenTileStateUncleared && type == MineSweeperGameScreenTileMine) {
+
+                        is_lose_condition_triggered = true;
+                        model->board[curr_pos_1d].tile_state = MineSweeperGameScreenTileStateCleared;
+
+                    } else if (state == MineSweeperGameScreenTileStateUncleared) {
+
+                        uint16_t tiles_cleared = bfs_tile_clear(
+                                                    model->board,
+                                                    model->board_width,
+                                                    model->board_height,
+                                                    (uint16_t)model->curr_pos.x_abs,
+                                                    (uint16_t)model->curr_pos.y_abs);
+
+                        model->tiles_left -= tiles_cleared;
+
+                        // Check win condition
+                        if (model->mines_left == 0 && model->flags_left == 0 && model->tiles_left == 0) {
+                            is_win_condition_triggered = true;
+                        } else {
+                            // if not met play ok effect
+                            mine_sweeper_short_ok_effect(instance);
+                        }
+                    }
+
+                // LOSE/WIN CONDITION OR CLEAR SURROUNDING
+                } else if (!model->is_holding_down_button && event->type == InputTypeLong) {
+                    
+                    // Try to clear surrounding tiles if correct number is flagged.
+                    is_lose_condition_triggered = try_clear_surrounding_tiles(model);
+                    model->is_holding_down_button = true;
+
+                    // Check win condition
+                    if (model->mines_left == 0 && model->flags_left == 0 && model->tiles_left == 0) {
+                        is_win_condition_triggered = true;
+                    }
+
+                    // We need to check if it is ok to play this or else we conflict
+                    // with the lose effect and crash
+                    if (!is_win_condition_triggered && !is_lose_condition_triggered &&
+                        model->board[curr_pos_1d].tile_type != MineSweeperGameScreenTileZero) {
+                        mine_sweeper_long_ok_effect(instance);
+                    }
+
+                } 
+
+            },
+            true
+        );
+        
+        // Check  if win or lose condition was triggered on OK press
+        if (is_lose_condition_triggered) {
+            mine_sweeper_lose_effect(instance);
+            view_set_draw_callback(instance->view, mine_sweeper_game_screen_view_lose_draw_callback);
+            view_set_input_callback(instance->view, mine_sweeper_game_screen_view_end_input_callback);
+        } else if (is_win_condition_triggered) {
+            mine_sweeper_win_effect(instance);
+            view_set_draw_callback(instance->view, mine_sweeper_game_screen_view_win_draw_callback);
+            view_set_input_callback(instance->view, mine_sweeper_game_screen_view_end_input_callback);
+        }
+
+
+        consumed = true;
+
+    }
+
+    if (!consumed && (event->key == InputKeyBack)) { // We can use holding the back button for either
+                                                   // Setting a flag on a covered tile, or moving to
+                                                   // the next closest covered tile on when on a uncovered
+                                                   // tile
+
+        if (event->type == InputTypeLong || event->type == InputTypeRepeat) {    // Only process longer back keys;
+                                                                                        // short presses should take
+                                                                                        // us to the menu
+            with_view_model(
+                instance->view,
+                MineSweeperGameScreenModel * model,
+                {
+                    uint16_t curr_pos_1d = model->curr_pos.x_abs * model->board_width + model->curr_pos.y_abs;
+                    
+                    MineSweeperGameScreenTileState state = model->board[curr_pos_1d].tile_state;
+
+                    if (state == MineSweeperGameScreenTileStateCleared) {
+
+                        // BFS to closest uncovered position
+                        Point res = bfs_to_closest_tile(model);
+
+                        // Save cursor to new closest tile position
+                        // If the cursor moves outisde of the model boundaries we need to
+                        // move the boundary appropriately
+                        
+                        model->curr_pos.x_abs = res.x;
+                        model->curr_pos.y_abs = res.y;
+
+                        bool is_outside_top_boundary = model->curr_pos.x_abs <
+                            (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT);
+
+                        bool is_outside_bottom_boundary = model->curr_pos.x_abs >=
+                            model->bottom_boundary;
+
+                        bool is_outside_left_boundary = model->curr_pos.y_abs <
+                            (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH);
+
+                        bool is_outside_right_boundary = model->curr_pos.y_abs >=
+                            model->right_boundary;
+
+                        if (is_outside_top_boundary) {
+                            model->bottom_boundary = model->curr_pos.x_abs + MINESWEEPER_SCREEN_TILE_HEIGHT;
+                        } else if (is_outside_bottom_boundary) {
+                            model->bottom_boundary = model->curr_pos.x_abs+1;
+                        }
+
+                        if (is_outside_right_boundary) {
+                            model->right_boundary = model->curr_pos.y_abs+1;
+                        } else if (is_outside_left_boundary) {
+                            model->right_boundary = model->curr_pos.y_abs + MINESWEEPER_SCREEN_TILE_WIDTH;
+                        }
+                        
+                        mine_sweeper_play_happy_bump(instance->context);
+                        model->is_holding_down_button = true;
+
+                    // Flag or Unflag tile and check win condition 
+                    } else if (!model->is_holding_down_button &&
+                        (state == MineSweeperGameScreenTileStateUncleared || state == MineSweeperGameScreenTileStateFlagged)) { 
+
+
+                        if (state == MineSweeperGameScreenTileStateFlagged) {
+                            if (model->board[curr_pos_1d].tile_type == MineSweeperGameScreenTileMine) model->mines_left++;
+                            model->board[curr_pos_1d].tile_state = MineSweeperGameScreenTileStateUncleared;
+                            model->flags_left++;
+                            model->is_holding_down_button = true;
+                        
+                        } else if (model->flags_left > 0) {
+                            if (model->board[curr_pos_1d].tile_type == MineSweeperGameScreenTileMine) model->mines_left--;
+                            model->board[curr_pos_1d].tile_state = MineSweeperGameScreenTileStateFlagged;
+                            model->flags_left--;
+                            model->is_holding_down_button = true;
+                        }
+
+                        // WIN CONDITION
+                        // This can be a win condition where the non-mine tiles are cleared and they place the last flag
+                        if (model->flags_left == 0 && model->mines_left == 0 && model->tiles_left == 0) {
+                            //mine_sweeper_play_long_bump(instance->context);
+                            
+                            mine_sweeper_win_effect(instance);
+                            mine_sweeper_led_set_rgb(instance->context, 0, 0, 255);
+
+                            view_set_draw_callback(instance->view, mine_sweeper_game_screen_view_win_draw_callback);
+                            view_set_input_callback(instance->view, mine_sweeper_game_screen_view_end_input_callback);
+                        } else {
+                            // Making sure that win and flag effect are not played together
+                            mine_sweeper_flag_effect(instance);
+                        }
+
+                    }
+                },
+                false
+            );
+
+            consumed = true;
+
+        }
+    }
+
+    if (!consumed && (event->type == InputTypePress || event->type == InputTypeRepeat)) { // Finally handle move
+
+        with_view_model(
+            instance->view,
+            MineSweeperGameScreenModel * model,
+            {
+                bool is_outside_boundary;
+                switch (event->key) {
+
+                    case InputKeyUp :
+                        (model->curr_pos.x_abs-1 < 0)  ? mine_sweeper_oob_effect(instance) :
+                                mine_sweeper_move_effect(instance);
+                        
+                        model->curr_pos.x_abs = (model->curr_pos.x_abs-1 < 0) ? 0 : model->curr_pos.x_abs-1;
+
+                        is_outside_boundary = model->curr_pos.x_abs <
+                            (model->bottom_boundary - MINESWEEPER_SCREEN_TILE_HEIGHT);
+                        
+                        if (is_outside_boundary) {
+                            model->bottom_boundary--;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyDown :
+
+                        (model->curr_pos.x_abs+1 >= model->board_height)  ? mine_sweeper_oob_effect(instance) :
+                                mine_sweeper_move_effect(instance);
+
+                        model->curr_pos.x_abs = (model->curr_pos.x_abs+1 >= model->board_height) ?
+                            model->board_height-1 : model->curr_pos.x_abs+1;
+
+                        is_outside_boundary = model->curr_pos.x_abs >= model->bottom_boundary;
+
+                        if (is_outside_boundary) {
+                            model->bottom_boundary++;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyLeft :
+                        (model->curr_pos.y_abs-1 < 0)  ? mine_sweeper_oob_effect(instance) :
+                                mine_sweeper_move_effect(instance);
+
+                        model->curr_pos.y_abs = (model->curr_pos.y_abs-1 < 0) ? 0 : model->curr_pos.y_abs-1;
+
+                        is_outside_boundary = model->curr_pos.y_abs <
+                            (model->right_boundary - MINESWEEPER_SCREEN_TILE_WIDTH);
+                        
+                        if (is_outside_boundary) {
+                            model->right_boundary--;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    case InputKeyRight :
+                        (model->curr_pos.y_abs+1 >= model->board_width)  ? mine_sweeper_oob_effect(instance) :
+                                mine_sweeper_move_effect(instance);
+
+                        model->curr_pos.y_abs = (model->curr_pos.y_abs+1 >= model->board_width) ?
+                            model->board_width-1 : model->curr_pos.y_abs+1;
+
+                        is_outside_boundary = model->curr_pos.y_abs >= model->right_boundary;
+
+                        if (is_outside_boundary) {
+                            model->right_boundary++;
+                        }
+
+                        consumed = true;
+                        break;
+
+                    default:
+                        consumed = true;
+                        break;
+                }
+            },
+            true
+        );
+    }
+    
+
+    if (!consumed && instance->input_callback != NULL) {
+        consumed = instance->input_callback(event, instance->context);
+    }
+
+    return consumed;
+}
+
+MineSweeperGameScreen* mine_sweeper_game_screen_alloc(uint8_t width, uint8_t height, uint8_t difficulty, bool ensure_solvable) {
+    MineSweeperGameScreen* mine_sweeper_game_screen = (MineSweeperGameScreen*)malloc(sizeof(MineSweeperGameScreen));
+    
+    mine_sweeper_game_screen->view = view_alloc();
+
+    view_set_context(mine_sweeper_game_screen->view, mine_sweeper_game_screen);
+    view_allocate_model(mine_sweeper_game_screen->view, ViewModelTypeLocking, sizeof(MineSweeperGameScreenModel));
+
+    view_set_draw_callback(mine_sweeper_game_screen->view, mine_sweeper_game_screen_view_play_draw_callback);
+    view_set_input_callback(mine_sweeper_game_screen->view, mine_sweeper_game_screen_view_play_input_callback);
+    
+    // This are currently unused
+    view_set_enter_callback(mine_sweeper_game_screen->view, mine_sweeper_game_screen_view_enter);
+    view_set_exit_callback(mine_sweeper_game_screen->view, mine_sweeper_game_screen_view_exit);
+
+    // Not being used
+    mine_sweeper_game_screen->input_callback = NULL;
+
+    // Allocate strings in model
+    with_view_model(
+        mine_sweeper_game_screen->view,
+        MineSweeperGameScreenModel * model,
+        {
+            model->info_str = furi_string_alloc();
+            model->is_holding_down_button = false;
+        },
+        true
+    );
+
+    // Reset the clock - This will set the start time at the allocation of the game screen
+    // but this is a public api as well and can be called in a scene for more accurate start times
+    mine_sweeper_game_screen_reset_clock(mine_sweeper_game_screen);
+
+    // We need to initize board width and height before setup
+    mine_sweeper_game_screen_set_board_information(mine_sweeper_game_screen, width, height, difficulty, ensure_solvable);
+
+    // Here we are going to generate a valid map for the player 
+    bool is_valid_board = false;
+    size_t memsz = sizeof(MineSweeperTile) * MINESWEEPER_BOARD_MAX_TILES;
+
+    do {
+        setup_board(mine_sweeper_game_screen);
+
+        uint16_t num_mines = 1;
+
+        uint16_t board_width = 16; //default values
+        uint16_t board_height = 7; //default values
+
+        with_view_model(
+            mine_sweeper_game_screen->view,
+            MineSweeperGameScreenModel * model,
+            {
+                num_mines = model->mines_left;
+                board_width = model->board_width;
+                board_height = model->board_height;
+
+                memset(board_t, 0, memsz);
+                memcpy(board_t, model->board, sizeof(MineSweeperTile) * (board_width * board_height));
+            },
+            true
+        );
+    
+        is_valid_board = check_board_with_verifier(board_t, board_width, board_height, num_mines);
+
+    } while (ensure_solvable && !is_valid_board);
+
+    return mine_sweeper_game_screen;
+}
+
+void mine_sweeper_game_screen_free(MineSweeperGameScreen* instance) {
+    furi_assert(instance);
+
+    // Dealloc strings in model
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            furi_string_free(model->info_str);
+        },
+        false
+    );
+
+    // Free view and any dynamically allocated members in main struct
+    view_free(instance->view);
+    free(instance);
+}
+
+// This function should be called whenever you want to reset the game state
+// This should NOT be called in the on_exit in the game scene
+void mine_sweeper_game_screen_reset(MineSweeperGameScreen* instance, uint8_t width, uint8_t height, uint8_t difficulty, bool ensure_solvable) {
+    furi_assert(instance);
+    
+    instance->input_callback = NULL;
+    
+    // Reset led
+    mine_sweeper_led_reset(instance->context);
+    
+    // We need to initize board width and height before setup
+    mine_sweeper_game_screen_set_board_information(instance, width, height, difficulty, ensure_solvable);
+
+    mine_sweeper_game_screen_reset_clock(instance);
+
+    // Here we are going to generate a valid map for the player 
+    bool is_valid_board = false;
+    size_t memsz = sizeof(MineSweeperTile) * MINESWEEPER_BOARD_MAX_TILES;
+
+    do {
+        setup_board(instance);
+
+        uint16_t num_mines = 1;
+
+        uint16_t board_width = 16; //default values
+        uint16_t board_height = 7; //default values
+
+        with_view_model(
+            instance->view,
+            MineSweeperGameScreenModel * model,
+            {
+                num_mines = model->mines_left;
+                board_width = model->board_width;
+                board_height = model->board_height;
+
+                memset(board_t, 0, memsz);
+                memcpy(board_t, model->board, sizeof(MineSweeperTile) * (board_width * board_height));
+            },
+            true
+        );
+    
+        is_valid_board = check_board_with_verifier(board_t, board_width, board_height, num_mines);
+
+    } while (ensure_solvable && !is_valid_board);
+
+}
+
+// This function should be called when you want to reset the game clock
+// Already called in reset and alloc function for game, but can be called from
+// other scenes that need it like a start scene that plays after alloc
+void mine_sweeper_game_screen_reset_clock(MineSweeperGameScreen* instance) {
+    furi_assert(instance);
+
+    with_view_model(
+        instance->view,
+        MineSweeperGameScreenModel * model,
+        {
+            model->start_tick = furi_get_tick();
+        },
+        true
+    );
+}
+
+View* mine_sweeper_game_screen_get_view(MineSweeperGameScreen* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void mine_sweeper_game_screen_set_context(MineSweeperGameScreen* instance, void* context) {
+    furi_assert(instance);
+    instance->context = context;
+}

+ 103 - 0
minesweeper/views/minesweeper_game_screen.h

@@ -0,0 +1,103 @@
+/**
+ * @file minesweeper_game_screen_screen.h
+ * GUI: Start Screen view module API
+ */
+
+#ifndef MINEWEEPER_GAME_SCREEN_H
+#define MINEWEEPER_GAME_SCREEN_H
+
+#include <gui/view.h>
+
+#include "minesweeper_game_screen_i.h"
+#include "../helpers/mine_sweeper_haptic.h"
+#include "../helpers/mine_sweeper_led.h"
+#include "../helpers/mine_sweeper_speaker.h"
+
+// MAX TILES ALLOWED
+#define MINESWEEPER_BOARD_MAX_TILES  (1<<10)
+
+// These defines represent how many tiles
+// can be visually representen on the screen 
+// due to icon sizes
+#define MINESWEEPER_SCREEN_TILE_HEIGHT 7
+#define MINESWEEPER_SCREEN_TILE_WIDTH 16
+
+#define MS_DEBUG_TAG  "Mine Sweeper Module/View"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** MineSweeperGameScreen anonymous structure */
+typedef struct MineSweeperGameScreen MineSweeperGameScreen;
+
+/** StartScreen callback types
+ * @warning     comes from GUI thread
+ */
+typedef bool (*GameScreenInputCallback)(InputEvent* event, void* context);
+
+/** Allocate and initalize
+ *
+ * This view is used as the game screen of an application.
+ *
+ * @param       width       uint8_t width for board
+ * @param       height      uint8_t height for board
+ * @param       difficulty  uint8_t difficulty for board
+ *
+ * @return      MineSweeperGameScreen* instance 
+ */
+MineSweeperGameScreen* mine_sweeper_game_screen_alloc(uint8_t width, uint8_t height, uint8_t difficulty, bool ensure_solvable);
+
+/** Deinitialize and free Start Screen view
+ *
+ * @param       instsance   MineSweeperGameScreen instance
+ */
+void mine_sweeper_game_screen_free(MineSweeperGameScreen* instance);
+
+/** Reset MineSweeperGameScreen
+ *
+ * @param       instance    MineSweeperGameScreen* instance
+ * @param       width       uint8_t width for board
+ * @param       height      uint8_t height for board
+ * @param       difficulty  uint8_t difficulty for board
+ */
+void mine_sweeper_game_screen_reset(
+        MineSweeperGameScreen* instance,
+        uint8_t width,
+        uint8_t height,
+        uint8_t difficulty,
+        bool ensure_solvable);
+
+/** Reset MineSweeperGameScreen clock 
+ *
+ * @param       instance    MineSweeperGameScreen* instance
+ */
+void mine_sweeper_game_screen_reset_clock(MineSweeperGameScreen* instance);
+
+/** Get MineSweeperGameScreen view
+ *
+ * @param       instance    MineSweeperGameScreen instance
+ *
+ * @return      View* instance that can be used for embedding
+ */
+View* mine_sweeper_game_screen_get_view(MineSweeperGameScreen* instance);
+
+/** Set MineSweeperGameScreen context 
+ *
+ * @param       instance    MineSweeperGameScreen* instance
+ * @param       context     void* context for MineSweeperGameScreen instance 
+ */
+void mine_sweeper_game_screen_set_context(MineSweeperGameScreen* instance, void* context);
+
+#define inverted_canvas_white_to_black(canvas, code)      \
+    {                                           \
+        canvas_set_color(canvas, ColorWhite);   \
+        {code};                                 \
+        canvas_set_color(canvas, ColorBlack);   \
+    }                           
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 125 - 0
minesweeper/views/minesweeper_game_screen_i.h

@@ -0,0 +1,125 @@
+#ifndef MINESWEEPERGAMESCREEN_I_H
+#define MINESWEEPERGAMESCREEN_I_H
+
+#include "m-rbtree.h"
+#include "m-deque.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+		
+/** We can use this Point struct for the 2d position for the minesweeper game.
+  * We define the necessary functions needed for this user defined type
+  * so that we can make use of M*LIB's Red Black Tree and Double Ended
+  * Queue for DFS and other algorithms for our MineSweeper game
+  */
+
+typedef struct {
+    uint8_t x,y;
+} Point;
+
+typedef struct {
+    bool allocated;
+	Point p;
+} Point_t[1];
+
+static inline void pointobj_init(Point_t dest) {
+    dest->p = (Point) {.x = 0, .y = 0};
+    dest->allocated = true;
+}
+
+static inline void pointobj_clear(Point_t dest) {
+    assert(dest->allocated);
+    dest->allocated = false;
+}
+
+static inline void pointobj_init_set(Point_t dest, const Point_t source) {
+    dest->p = source->p;
+    dest->allocated = true;
+}
+
+static inline void pointobj_set(Point_t dest, const Point_t source) {
+    if (dest != source) {
+        pointobj_clear(dest);
+        pointobj_init_set(dest, source); 
+    }
+}
+
+static inline void pointobj_set_point(Point_t dest, Point value) {
+    dest->p = value;
+}
+
+static inline void pointobj_init_set_point(Point_t dest, Point val) {
+    pointobj_init(dest);
+    pointobj_set_point(dest, val);
+}
+
+static inline bool pointobj_equal_p(const Point_t a, const Point_t b) {
+
+    return (a->p.x == b->p.x && a->p.y == b->p.y) ? true : false;
+}
+
+static inline int pointobj_cmp(const Point_t a, const Point_t b) {
+    if (a->p.x != b->p.x) return (a->p.x < b->p.x) ? -1 : 1;
+    if (a->p.y != b->p.y) return (a->p.y < b->p.y) ? -1 : 1; 
+    return 0;
+}
+
+// This is the oplist needed to define the rb tree and dequeue and uses the/
+// above functions.
+#define POINT_OPLIST (                      \
+            TYPE(Point_t),                  \
+            INIT(pointobj_init),            \
+            INIT_SET(pointobj_init_set),    \
+            SET(pointobj_set),              \
+            CLEAR(pointobj_clear),          \
+            EQUAL(pointobj_equal_p),        \
+            CMP(pointobj_cmp)               \
+        )
+
+// Use this to get rid of -Wunused-parameter errors for this macro only
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
+// Example Macro defining the RBTREE for Point that will be used as an ordered set
+RBTREE_DEF(point_set, Point_t, POINT_OPLIST)
+
+#pragma GCC diagnostic pop
+
+// Example Macro defining the DEQ for Point that will be used as a double ended queue
+DEQUE_DEF (point_deq, Point_t, POINT_OPLIST)
+
+// Helper to convert the Point_t type to Point
+static inline Point pointobj_get_point(const Point_t z) {
+    return z->p;
+}
+
+// Printing deq to debug
+static inline void print_deq_to_debug(point_deq_t* deq) {
+
+    point_deq_it_t it;
+
+    for(point_deq_it(it, *deq); !point_deq_end_p(it); point_deq_next(it)) {
+        Point ref = pointobj_get_point(*point_deq_ref(it));
+		
+        FURI_LOG_D("DEQ DEBUG:", "(%hd,%hd), ", ref.x, ref.y);
+    }
+}
+
+// Printing ordered set to debug
+static inline void print_ordered_set_to_debug(point_set_t* tree) {
+
+    point_set_it_t it;
+
+    for(point_set_it(it, *tree); !point_set_end_p(it); point_set_next(it)) {
+        Point ref = pointobj_get_point(*point_set_ref(it));
+		
+        FURI_LOG_D("SET DEBUG:", "(%hd,%hd), ", ref.x, ref.y);
+    }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 321 - 0
minesweeper/views/start_screen.c

@@ -0,0 +1,321 @@
+#include "start_screen.h"
+#include <gui/elements.h>
+#include <gui/icon_animation.h>
+#include <input/input.h>
+
+#include <furi.h>
+
+struct StartScreen {
+    View* view;
+    void* context;
+    StartScreenInputCallback input_callback;
+    StartScreenDrawCallback secondary_draw_callback;
+};
+
+typedef struct {
+    const char* text;
+    Font font;
+    uint8_t x, y;
+    Align horizontal, vertical;
+} TextElement;
+
+typedef struct {
+    IconAnimation* animation;
+    uint8_t x, y;
+} IconElement;
+
+typedef struct {
+    TextElement text1;
+    TextElement text2;
+    TextElement text3;
+    IconElement icon;
+} StartScreenModel;
+
+void start_screen_view_enter(void* context) {
+    furi_assert(context);
+    StartScreen* start_screen = context;
+
+    with_view_model(
+        start_screen->view,
+        StartScreenModel * model,
+        {
+            if (model->icon.animation != NULL)
+                icon_animation_start(model->icon.animation);
+        },
+        true);
+}
+
+void start_screen_view_exit(void* context) {
+    furi_assert(context);
+    StartScreen* start_screen = context;
+
+    with_view_model(
+        start_screen->view,
+        StartScreenModel * model,
+        {
+            if (model->icon.animation != NULL)
+                icon_animation_stop(model->icon.animation);
+        },
+        true);
+}
+
+void start_screen_view_draw_callback(Canvas* canvas, void* _model) {
+    furi_assert(canvas);
+    furi_assert(_model);
+    StartScreenModel* model = _model;
+
+    canvas_clear(canvas);
+
+    canvas_set_color(canvas, ColorWhite);
+    canvas_draw_box(canvas, 0, 0, canvas_width(canvas), canvas_height(canvas));
+    canvas_set_color(canvas, ColorBlack);
+
+    if (model->icon.animation != NULL) {
+        canvas_draw_icon_animation(canvas, model->icon.x, model->icon.y, model->icon.animation);
+    }
+
+    if (model->text1.text != NULL) {
+        canvas_set_font(canvas, model->text1.font);
+        elements_multiline_text_aligned(
+            canvas,
+            model->text1.x,
+            model->text1.y,
+            model->text1.horizontal,
+            model->text1.vertical,
+            model->text1.text);
+    }
+
+    if (model->text2.text != NULL) {
+        canvas_set_font(canvas, model->text2.font);
+        elements_multiline_text_aligned(
+            canvas,
+            model->text2.x,
+            model->text2.y,
+            model->text2.horizontal,
+            model->text2.vertical,
+            model->text2.text);
+    }
+
+    if (model->text3.text != NULL) {
+        canvas_set_font(canvas, model->text3.font);
+        elements_multiline_text_aligned(
+            canvas,
+            model->text3.x,
+            model->text3.y,
+            model->text3.horizontal,
+            model->text3.vertical,
+            model->text3.text);
+    }
+
+}
+
+bool start_screen_view_input_callback(InputEvent* event, void* context) {
+    StartScreen* start_screen = context;
+    bool consumed = false;
+
+    // If custom input callback is defined pass event to it 
+    if (start_screen->input_callback != NULL) {
+        consumed = start_screen->input_callback(event, start_screen->context); 
+    } else {
+        // You can add default functionality here
+    }
+
+    return consumed;
+}
+
+StartScreen* start_screen_alloc() {
+    StartScreen* start_screen = (StartScreen*)malloc(sizeof(StartScreen));
+    
+    start_screen->view = view_alloc();
+
+    start_screen->input_callback = NULL;
+
+    view_set_context(start_screen->view, start_screen);
+    view_allocate_model(start_screen->view, ViewModelTypeLocking, sizeof(StartScreenModel));
+
+    with_view_model(
+        start_screen->view,
+        StartScreenModel * model,
+        {
+            model->text1.x = 0;
+            model->text1.y = 0;
+            model->text1.text = NULL;
+            model->text1.font = FontSecondary;
+            model->text1.horizontal = AlignLeft;
+            model->text1.vertical = AlignBottom;
+
+            model->text2.x = 0;
+            model->text2.y = 0;
+            model->text2.text = NULL;
+            model->text2.font = FontSecondary;
+            model->text2.horizontal = AlignLeft;
+            model->text2.vertical = AlignBottom;
+
+            model->text3.x = 0;
+            model->text3.y = 0;
+            model->text3.text = NULL;
+            model->text3.font = FontSecondary;
+            model->text3.horizontal = AlignLeft;
+            model->text3.vertical = AlignBottom;
+
+            model->icon.x = 0;
+            model->icon.y = 0;
+            model->icon.animation = NULL;
+        },
+        true);
+
+    view_set_draw_callback(start_screen->view, start_screen_view_draw_callback);
+    view_set_input_callback(start_screen->view, start_screen_view_input_callback);
+    
+    // Right now these enter/exit callbacks are being used to start/stop animations
+    view_set_enter_callback(start_screen->view, start_screen_view_enter);
+    view_set_exit_callback(start_screen->view, start_screen_view_exit);
+    
+    return start_screen;
+}
+
+void start_screen_free(StartScreen* instance) {
+    furi_assert(instance);
+
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            if (model->icon.animation != NULL)
+                icon_animation_free(model->icon.animation);
+
+            model->icon.animation = NULL;
+        },
+        false);
+
+    view_free(instance->view);
+    free(instance);
+}
+
+void start_screen_reset(StartScreen* instance) {
+    furi_assert(instance);
+
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            memset(&model->text1, 0, sizeof(model->text1));
+            memset(&model->text2, 0, sizeof(model->text2));
+            memset(&model->text3, 0, sizeof(model->text3));
+        },
+        false);
+    instance->input_callback = NULL;
+    instance->secondary_draw_callback = NULL;
+}
+
+View* start_screen_get_view(StartScreen* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void start_screen_set_input_callback(StartScreen* instance, StartScreenInputCallback callback) {
+    furi_assert(instance);
+    instance->input_callback = callback;
+}
+
+void start_screen_set_secondary_draw_callback(StartScreen* instance, StartScreenDrawCallback callback) {
+    furi_assert(instance);
+    instance->secondary_draw_callback = callback;
+}
+
+void start_screen_set_context(StartScreen* instance, void* context) {
+    furi_assert(instance);
+    instance->context = context;
+}
+
+void start_screen_set_text1(
+    StartScreen* instance,
+    uint8_t x,
+    uint8_t y,
+    Align horizontal,
+    Align vertical,
+    Font font,
+    const char* text) {
+
+    furi_assert(instance);
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            model->text1.x = x;
+            model->text1.y = y;
+            model->text1.horizontal = horizontal;
+            model->text1.vertical = vertical;
+            model->text1.font = font;
+            model->text1.text = text;
+        },
+        true);
+}
+
+void start_screen_set_text2(
+    StartScreen* instance,
+    uint8_t x,
+    uint8_t y,
+    Align horizontal,
+    Align vertical,
+    Font font,
+    const char* text) {
+
+    furi_assert(instance);
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            model->text1.x = x;
+            model->text1.y = y;
+            model->text1.horizontal = horizontal;
+            model->text1.vertical = vertical;
+            model->text1.font = font;
+            model->text1.text = text;
+        },
+        true);
+}
+
+void start_screen_set_text3(
+    StartScreen* instance,
+    uint8_t x,
+    uint8_t y,
+    Align horizontal,
+    Align vertical,
+    Font font,
+    const char* text) {
+
+    furi_assert(instance);
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            model->text1.x = x;
+            model->text1.y = y;
+            model->text1.horizontal = horizontal;
+            model->text1.vertical = vertical;
+            model->text1.font = font;
+            model->text1.text = text;
+        },
+        true);
+}
+
+void start_screen_set_icon_animation(
+    StartScreen* instance,
+    uint8_t x,
+    uint8_t y,
+    const Icon* animation) {
+
+    furi_assert(instance);
+    with_view_model(
+        instance->view,
+        StartScreenModel * model,
+        {
+            model->icon.x = x;
+            model->icon.y = y;
+            model->icon.animation = icon_animation_alloc(animation);
+            view_tie_icon_animation(instance->view, model->icon.animation);
+        },
+        true);
+}
+

+ 156 - 0
minesweeper/views/start_screen.h

@@ -0,0 +1,156 @@
+/**
+ * @file start_screen.h
+ * GUI: Start Screen view module API
+ */
+
+#ifndef START_SCREEN_H
+#define START_SCREEN_H
+
+#include <gui/view.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** StartScreen anonymous structure */
+typedef struct StartScreen StartScreen;
+
+/** StartScreen callback types
+ * @warning     comes from GUI thread
+ */
+typedef void (*StartScreenTimerCallback)(void* context);
+typedef bool (*StartScreenInputCallback)(InputEvent* event, void* context);
+typedef void (*StartScreenDrawCallback)(Canvas* canvas, void* _model);
+
+/** Allocate and initalize
+ *
+ * This view is used as the starting screen of an application.
+ *
+ * @return      StartScreen view instance 
+ */
+StartScreen* start_screen_alloc();
+
+/** Deinitialize and free Start Screen view
+ *
+ * @param       instsance StartScreen instance
+ */
+void start_screen_free(StartScreen* instance);
+
+/** Reset StartScreen
+ *
+ * @param       instance StartScreen instance
+ */
+void start_screen_reset(StartScreen* instance);
+
+/** Get StartScreen view
+ *
+ * @param       instance StartScreen instance
+ *
+ * @return      view instance that can be used for embedding
+ */
+View* start_screen_get_view(StartScreen* instance);
+
+/** Set StartScreen input callback 
+ *
+ * @param       instance StartScreen instance
+ * @param       callback StartScreenInputCallback callback
+ */
+void start_screen_set_input_callback(
+        StartScreen* instance,
+        StartScreenInputCallback callback);
+
+/** Set Additional draw callback 
+ * 
+ * Use this as a secondary callback to draw on the canvas.
+ * This callback function will happen after drawing of the established
+ * GUI elements in the view such as the icons, text, frame, ect.
+ *
+ * @param       instance StartScreen instance
+ * @param callback StartScreenDrawCallback callback
+ */
+void start_screen_set_secondary_draw_callback(
+        StartScreen* instance,
+        StartScreenDrawCallback callback);
+
+/** Set StartScreen context 
+ *
+ * @param       instance StartScreen instance
+ * @param       context context pointer, will be passed to callback 
+ */
+void start_screen_set_context(StartScreen* instance, void* context);
+
+// Maybe have it function similar to widget where you can attach string elements ect
+// Right now we will just have a Header, text, and icon similar to popup
+
+/** Set Text1 Element
+ *
+ * @param      instance StartScreen instance
+ * @param      x           x coordinate
+ * @param      y           y coordinate
+ * @param      horizontal  Align instance
+ * @param      vertical    Align instance
+ * @param      font        Font instance
+ * @param[in]  text        The text
+ */
+void start_screen_set_text1(
+        StartScreen* instance,
+        uint8_t x,
+        uint8_t y,
+        Align horizontal,
+        Align vertical,
+        Font font,
+        const char* text);
+
+/** Set Text2 Element
+ *
+ * @param      instance StartScreen instance
+ * @param      x           x coordinate
+ * @param      y           y coordinate
+ * @param      horizontal  Align instance
+ * @param      vertical    Align instance
+ * @param      font        Font instance
+ * @param[in]  text        The text
+ */
+void start_screen_set_text2(
+        StartScreen* instance,
+        uint8_t x,
+        uint8_t y,
+        Align horizontal,
+        Align vertical,
+        Font font,
+        const char* text);
+        
+/** Set Text3 Element
+ *
+ * @param      instance StartScreen instance
+ * @param      x           x coordinate
+ * @param      y           y coordinate
+ * @param      horizontal  Align instance
+ * @param      vertical    Align instance
+ * @param      font        Font instance
+ * @param[in]  text        The text
+ */
+void start_screen_set_text3(
+        StartScreen* instance,
+        uint8_t x,
+        uint8_t y,
+        Align horizontal,
+        Align vertical,
+        Font font,
+        const char* text);
+
+/** Set Icon Animation Element
+ *
+ * @param      instance StartScreen instance
+ * @param      x       top left x coordinate
+ * @param      y       top left y coordinate
+ * @param      animation    IconAnimation instance
+ */
+void start_screen_set_icon_animation(StartScreen* instance, uint8_t x, uint8_t y, const Icon* animation);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif