Commit Graph

152 Commits

Author SHA1 Message Date
Sergey Bugaev
4f06cda8f8 2048: Tweak default window size
As requested by @nico
2020-08-18 17:19:52 +02:00
Sergey Bugaev
7861ebaad7 2048: Generate more "2" tiles
This is how the original game does it.
2020-08-18 17:19:52 +02:00
Sergey Bugaev
8dd5b0af4e 2048: Move score to a status bar
See how straightforward this was? That's because, thanks to the separation
between the model and the view, we can tweak the view without modifying the
model in any way.
2020-08-18 17:19:52 +02:00
Sergey Bugaev
05ea144961 2048: Separate game logic from the view :^)
Look Ali, it's simple:

* The *model* (in many cases, an instance of GUI::Model, but it doesn't have to
  be) should implement the "business logic" (in this case, game logic) and
  should not concern itself with how the data/state is displayed to the user.

* The *view*, conversely, should interact with the user (display data/state,
  accept input) and should not concern itself with the logic. As an example, a
  GUI::Button can display some text and accept clicks -- it doesn't know or care
  what that text *means*, or how that click affects the app state. All it does
  is it gets its text from *somebody* and notifies *somebody* of clicks.

* The *controller* connects the model to the view, and acts as "glue" between
  them.

You could connect *several different* views to one model (see FileManager), or
use identical views with different models (e.g. a table view can display pretty
much anything, depending on what model you connect to it).

In this case, the model is the Game class, which maintains a board and
implements the rules of 2048, including tracking the score. It does not display
anything, and it does not concern itself with undo management. The view is the
BoardView class, which displays a board and accepts keyboard input, but doesn't
know how exactly the tiles move or merge -- all it gets is a board state, ready
to be displayed. The controller is our main(), which connects the two classes
and bridges between their APIs. It also implements undo management, by basically
making straight-up copies of the game.

Isn't this lovely?
2020-08-18 17:19:52 +02:00
Sergey Bugaev
99efc01b2e 2048: Automatically pick an appropriate font size 2020-08-18 17:19:52 +02:00
Sergey Bugaev
50d81f1e14 2048: Use the original colors 2020-08-18 17:19:52 +02:00
Sergey Bugaev
70356429ae 2048: Tweak cell metrics
This makes the game look closer to the original.

It also fixes a weird thing where cells were displayed in a wrong order (as if
mirrored or something), and to accommodate for that keyboard actions were also
mixed up. Now it's all working as intended.
2020-08-18 17:19:52 +02:00
Tibor Nagy
fbc3b8e3c8 Solitaire: Rename "Restart game" menu item to "New game"
Also adding a shortcut (F2) to make it consistent with other games.
2020-08-17 17:39:56 +02:00
Tibor Nagy
e3d1ea34ff Games: Add missing separators to the application menus 2020-08-17 17:39:56 +02:00
Abu Sakib
1ec0f54de1 Chess: Add Help menuitem 2020-08-17 12:12:19 +02:00
Brian Gianforcaro
eed9f2bac3 Chess: Uninitialized member in PromotionalDialog, found by Coverity 2020-08-17 09:17:57 +02:00
Peter Elliott
d90f8abe9d Chess: Add new ways to draw.
new ways:
Insufficent material
Threefold/Fivefold repitition
50 move/75 move rule
2020-08-15 20:54:02 +02:00
Peter Elliott
abd1f7e563 Chess: Add pawn promotion to any piece 2020-08-15 20:54:02 +02:00
Peter Elliott
9d40472721 Chess: Add En-passant 2020-08-15 20:54:02 +02:00
Peter Elliott
e91542a3cf Chess: Add menu options for setting board theme and piece set 2020-08-15 20:54:02 +02:00
Peter Elliott
7b71f4759f Chess: Highlight last move 2020-08-15 20:54:02 +02:00
Peter Elliott
f2c1782d86 Chess: Add win/draw conditions, and display them. 2020-08-15 20:54:02 +02:00
Peter Elliott
e05372cee2 Chess: Add legal move checking 2020-08-15 20:54:02 +02:00
Peter Elliott
7333916252 Chess: Add basic ChessWidget and ugly piece set 2020-08-15 20:54:02 +02:00
Linus Groh
2e5c434e22 Misc: Use automatic window positioning in more applications
This is a follow up to #2936 / d3e3b4ae56aa79d9bde12ca1f143dcf116f89a4c.

Affected programs:
- Applications: Browser (Download, View source, Inspect DOM tree, JS
  console), Terminal (Settings)
- Demos: Cube, Eyes, Fire, HelloWorld, LibGfxDemo, WebView,
  WidgetGallery
- DevTools: HackStudio, Inspector, Profiler
- Games: 2048, Minesweeper, Snake, Solitaire
- Userland: test-web

A few have been left out where manual positioning is done on purpose,
e.g. ClipboardManager (to be close to the menu bar) or VisualBuilder (to
preserve alignment of the multiple application windows).
2020-08-15 17:38:19 +02:00
AnotherTest
2336c62901 2048: Move out the 'undo' action to the app menu/action 2020-08-14 15:10:31 +02:00
AnotherTest
d97025567a 2048: Make the scoring system less 'lame' 2020-08-14 15:10:31 +02:00
AnotherTest
872834320a Games: Add a 2048 game 2020-08-09 21:11:50 +02:00
Andreas Kling
299824de73 LibGUI: Rename GUI::Image => GUI::ImageWidget
"Image" was a bit too vague, "ImageWidget" is obviously a widget of
some sort.
2020-07-23 17:31:08 +02:00
Andreas Kling
ca93c22ae2 LibGUI: Turn GUI::Application::the() into a pointer
During app teardown, the Application object may be destroyed before
something else, and so having Application::the() return a reference was
obscuring the truth about its lifetime.

This patch makes the API more honest by returning a pointer. While
this makes call sites look a bit more sketchy, do note that the global
Application pointer only becomes null during app teardown.
2020-07-04 16:54:55 +02:00
Andreas Kling
1dd1595043 LibGUI: Make GUI::Application a Core::Object
Having this on the stack makes whole-program teardown iffy. Turning it
into a Core::Object allows anyone who needs it to extends its lifetime.
2020-07-04 14:05:57 +02:00
Hüseyin ASLITÜRK
d0411f3756 Minesweeper: Replace Label with Image component to show flag and timer 2020-06-18 16:35:57 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Andreas Kling
977863ea07 LibGUI: Include keyboard modifier state with button on_click calls
This will allow you us to implement special behavior when Ctrl+clicking
a button.
2020-05-12 20:31:16 +02:00
Andreas Kling
705cee528a LibGUI: Make it easier to create checkable GUI::Actions
This patch adds GUI::Action::create_checkable() helpers that work just
like the existing create() helpers, but the actions become checkable(!)

Clients are no longer required to manage the checked state of their
actions manually, but instead they will be checked/unchecked as needed
by GUI::Action itself before the activation hook is fired.
2020-04-21 17:21:28 +02:00
Andreas Kling
52a250cb61 LibGUI: Make MenuBar a Core::Object
This makes it show up in Inspector with all the menus inside it. :^)
2020-04-21 16:19:18 +02:00
Andreas Kling
8311b24620 Solitaire: Use a pre-scaled buggie image for the back of cards
Instead of scaling on the fly, which is not super aesthetic yet.
2020-04-20 15:24:59 +02:00
Andreas Kling
228ace854c LibGfx: Don't allow creating bitmaps whose sizes would overflow
If the area or size_in_bytes calculation for a Gfx::Bitmap would
overflow, we now refuse to create such a bitmap and return nullptr.

Thanks to @itamar8910 for finding this! :^)
2020-04-15 12:28:49 +02:00
Andreas Kling
26eeaef0a8 LibGUI: Add MenuBar::add_menu(name)
This allows us to construct menus in a more natural way:

    auto& file_menu = menubar->add_menu("File");
    file_menu.add_action(...);

Instead of the old way:

    auto file_menu = GUI::Menu::construct();
    file_menu->add_action(...);
    menubar->add_menu(file_menu);
2020-04-04 12:58:05 +02:00
Tibor Nagy
cfd1e783a5 Solitaire: Set parent window for AboutDialog 2020-03-30 10:52:09 +02:00
Tibor Nagy
809490dcb6 Solitaire: Use dark green for empty stack outlines
Looks nicer than using dark gray. Derived from the background color.
2020-03-19 22:52:18 +01:00
Tibor Nagy
f347dd5c5e Applications: Use "Document - AppName" window title format
Fixes #1444
2020-03-13 23:30:12 +01:00
Till Mayer
de6f697eba Solitaire: Fix automatic moving of cards
A previous change trying to fix an assertion error completely broke
the automatic moving of cards, this commit will fix this problem
2020-03-13 10:40:45 +01:00
Till Mayer
3e25c58755 Solitaire: Minor tweaks to animation x_velocity and bouncyness 2020-03-13 10:40:45 +01:00
Till Mayer
62422eecdc Solitaire: Add about dialog and 32x32 icon 2020-03-13 10:40:45 +01:00
Till Mayer
2af94bbf48 Solitaire: Remove redundant check and fix formatting mistakes 2020-03-11 10:06:00 +01:00
Till Mayer
629036edfe Solitaire: Make sure to not add card twice to m_focused_cards
There is a possibility that the same card gets added twice to
m_focused_cards when first mousedown_event fires and then
doubleclick_event, without the cards redrawing first. This would cause
mouseup_event to try to pop too many cards from the stack, causing an
assertion to fail.

When the system is laggy there is also a high possibility that
mousedown_event would fire twice without redrawing the cards first,
causing another assertion to fail. Addditional mousedown_events will
just be ignored now.
2020-03-11 10:06:00 +01:00
Till Mayer
fe5cc7ce68 Games: Added solitaire
Added a solitaire game. Currently there are graphics missing on some
of the cards, but the game is fully functional.

Press F12 to show the game-over animation manually.
2020-03-09 21:36:59 +01:00
Shannon Booth
6a3b12664a LibGUI: Move Icon and FontDatabase into the GUI namespace
We also clean up some old references to the old G prefixed GUI classes

This also fixes a potential bug with using: C_OBJECT_ABSTRACT(GAbstractButton)
instead of C_OBJECT_ABSTRACT(AbstractButton)
2020-03-07 01:33:53 +01:00
Andreas Kling
028c011760 LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can
simply vend a ChildType&. This allows us to use "." instead of "->"
at the call site, which is quite nice. :^)
2020-03-04 21:04:06 +01:00
Andreas Kling
0f3e57a6fb LibGUI: Use GUI::Window::set_main_widget<WidgetType>() in clients 2020-03-04 14:26:16 +01:00
Andreas Kling
4697195645 LibGUI: Use set_layout<LayoutType>() in lots of client code 2020-03-04 13:49:48 +01:00
Andreas Kling
a26b63a958 LibGUI: Remove Button& parameter from Button::on_click hook
There was but a single user of this parameter and it's a bit tedious
to write it out every time, so let's get rid of it.
2020-03-03 17:02:38 +01:00