Commit Graph

367 Commits

Author SHA1 Message Date
Luke Wilde
fd51a3cf15 FlappyBug: Remove wpath and cpath pledges
With the move to LibConfig, these are no longer needed.
2021-08-28 12:22:16 +04:30
Luke Wilde
5d6fccc52b GameOfLife: Add pledge and unveil 2021-08-28 12:22:16 +04:30
Luke Wilde
7a0fbb94b6 Pong: Remove wpath and cpath pledges
With the move to LibConfig, these are no longer needed.
2021-08-28 12:22:16 +04:30
Luke Wilde
efe0a3d415 Snake: Remove wpath and cpath pledges
With the move to LibConfig, these are no longer needed.
2021-08-28 12:22:16 +04:30
Luke Wilde
9d428a65d1 Minesweeper: Remove wpath and cpath pledges
With the move to LibConfig, these are no longer needed.
2021-08-28 12:22:16 +04:30
Mustafa Quraish
17299db61a Hearts: Remove wpath and cpath priviliges
There are no longer needed since the config file is not being
modified by the application directly.
2021-08-27 23:17:05 +02:00
Mustafa Quraish
0af3855fb9 Hearts: Use LibConfig instead of Core::ConfigFile 2021-08-27 23:17:05 +02:00
Mustafa Quraish
4bd9ac1f66 Pong: Remove unused Core::ConfigFile imports
This application was including, opening and unveiling the path for
a config file, however it never actually reads or saves anything
from the configuration file.

Since it's easy enough to add it back later if needed, probably
makes sense to remove the unused code right now?
2021-08-27 12:45:50 +02:00
Mustafa Quraish
998d3a98ec Spider: Use LibConfig instead of Core::ConfigFile
There was a lot of error handling here previously when writing to
a config file failed, but this was removed since we have no way of
conveying a `Config::write` failure from the ConfigServer.
2021-08-27 12:45:50 +02:00
Mustafa Quraish
458471cc37 Snake: Use LibConfig instead of Core::ConfigFile 2021-08-27 12:45:50 +02:00
Ralf Donau
a6fc80f069 Games: Remove unveiling /tmp/portal/config
Config::pledge_domains is applied before, hence /tmp/portal/config
can and should be veiled.
2021-08-26 21:40:39 +02:00
Ralf Donau
5a0be07cf0 FlappyBug: Use LibConfig instead of Core::ConfigFile 2021-08-26 19:54:50 +02:00
Thitat Auareesuksakul
f119c5580a Solitaire: Use LibConfig instead of Core::ConfigFile 2021-08-26 16:39:22 +02:00
Thitat Auareesuksakul
573d14b7b5 Chess: Use LibConfig instead of Core::ConfigFile 2021-08-26 16:39:22 +02:00
Thitat Auareesuksakul
666397e1a7 2048: Use LibConfig instead of Core::ConfigFile 2021-08-26 16:39:22 +02:00
Andreas Kling
827bf5232e Minesweeper: Use LibConfig instead of Core::ConfigFile 2021-08-26 00:54:28 +02:00
Ralf Donau
9bef96748d Games: Make cpath appear once in the pledge promises 2021-08-22 23:39:41 +02:00
networkException
acde7d12b0 Everywhere: Rename get in ConfigFile::get_for_{lib,app,system} to open
This patch brings the ConfigFile helpers for opening lib, app and system
configs more inline with the regular ConfigFile::open functions.
2021-08-22 01:32:25 +02:00
networkException
938051feb8 Everywhere: Use Core::ConfigFile::AllowWriting::Yes to allow writing 2021-08-22 01:32:25 +02:00
Mitchel Humpherys
2fb26299bb FlappyBug: Flap less aggressively
The current flap strength makes the game a lot more difficult than
other flappy games. Decrease the flap strength to make it a little
easier to get higher scores.

Before this change I could only get past 3 or 4 obstacles, now I can
get 15 or 20 in, which seems more on par with other flappy games.
2021-08-21 00:25:43 +02:00
sin-ack
e11d177618 Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:

- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
  and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
  the top margin, the second argument to the left and right margins,
  and the third argument to the bottom margin.
2021-08-18 10:30:50 +02:00
sin-ack
9c9a5c55cb Userland+LibGUI: Make Margins arguments match CSS ordering
Previously the argument order for Margins was (left, top, right,
bottom). To make it more familiar and closer to how CSS does it, the
argument order is now (top, right, bottom, left).
2021-08-18 10:30:50 +02:00
thisSyntaxSucksAndYouKnowIt
f583cddaf7 Solitaire: Don't allow the player to draw cards while mouse is down 2021-08-07 16:59:46 +02:00
Jamie Mansfield
705e91d332 Spider: Use YesNo dialog for user confirmation when closing
Cancel was superflous, and provided no difference to No.
2021-08-06 01:12:32 +02:00
Jamie Mansfield
c3c1a9ca1d Solitaire: Get user confirmation to close when there is a active game 2021-08-06 01:12:32 +02:00
Jamie Mansfield
506363c08d Solitaire: Clear selection when starting new game
Fixes #9218.
2021-08-05 12:52:33 +02:00
Jamie Mansfield
22aeec1218 Spider: Clear selection when starting new game
Fixes #9217.
2021-08-05 12:52:33 +02:00
LuK1337
4b81b9718d Breakout: Add menus before showing the window
Otherwise, space is reserved but menus aren't shown.
2021-07-31 08:08:31 +02:00
LuK1337
7f99497378 Pong: Add menus before showing the window
Otherwise, space is reserved but menus aren't shown.
2021-07-31 08:08:31 +02:00
Jamie Mansfield
28ee513bdf Spider: Make statusbar high score display configurable
You can now choose what statistic (currently only high score or best
time) to display in the statusbar.
2021-07-27 16:53:56 +02:00
Jamie Mansfield
821af6a6ef Spider: Start game if first move is to draw cards
This fixes a bug where the game wouldn't consider it had started.
2021-07-27 16:53:56 +02:00
Jamie Mansfield
26cb559d37 Spider: Track win and loss counts
Again, this isn't exposed anywhere yet.
2021-07-27 16:53:56 +02:00
Jamie Mansfield
f7eb6772ce Spider: Get user confirmation to close when there is a active game 2021-07-27 16:53:56 +02:00
Jamie Mansfield
4df9d05f91 Spider: Track quickest game time
This isn't exposed in the game anywhere yet.
2021-07-27 16:53:56 +02:00
Jamie Mansfield
29f15cfbae Spider: Standardise fetching the mode identifier
This eliminates some code duplication, and will be helpful for future
commits introducing further statistic tracking.
2021-07-27 16:53:56 +02:00
Gunnar Beutner
3c1797c42d Solitaire: Use AK::get_random_uniform() instead of rand()/srand() 2021-07-24 01:40:51 +02:00
Gunnar Beutner
58d1e46628 Spider: Use AK::get_random_uniform() instead of rand()/srand()
This also has the added benefit that after a restart we don't get the
same random numbers all the time because we forgot to initialize the
RNG with srand().
2021-07-24 01:40:51 +02:00
Gunnar Beutner
807b79d89e Spider: Avoid reallocations for Vectors when possible 2021-07-24 01:40:51 +02:00
Gunnar Beutner
d76b42599e Hearts: Avoid reallocations for Vectors when possible 2021-07-24 01:40:51 +02:00
Gunnar Beutner
5201c17d9b Hearts: Use AK::get_random_uniform() instead of rand()/srand() 2021-07-24 01:40:51 +02:00
Gunnar Beutner
59007bba84 Hearts: Avoid redrawing the UI unnecessarily 2021-07-23 02:34:59 +02:00
Andreas Kling
687a12d7fb Userland: Add GUI::Window::add_menu() and use it everywhere
Applications previously had to create a GUI::Menubar object, add menus
to it, and then call GUI::Window::set_menubar().

This patch introduces GUI::Window::add_menu() which creates the menubar
automatically and adds items to it. Application code becomes slightly
simpler as a result. :^)
2021-07-21 21:24:26 +02:00
Andreas Kling
c7d891765c LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
2021-07-21 18:02:15 +02:00
Karol Kosek
fd5bc36fc1 Pong: Disable resizing the window
The game doesn't handle resize events.

It's a pretty lazy fix.  The proper way would be to actually allow
the game to be resized, with some scaling trickery, but most games
here don't do that anyway, so I guess that's good enough.
2021-07-20 01:51:11 +02:00
Hendiadyoin1
ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Jamie Mansfield
0150ae4bbd Solitaire: Reduce overdraw when drawing initial cards 2021-07-15 21:47:36 +02:00
Jamie Mansfield
882b4dc848 Spider: Reduce overdraw when playing 2021-07-15 20:11:22 +02:00
Jamie Mansfield
0f9873475b Spider: Reduce overdraw when drawing initial cards 2021-07-15 20:11:22 +02:00
Jamie Mansfield
c0bc884295 Spider: Automatically reveal top cards
This matches basically all other Spider implementations I've played,
and makes playing much easier :)

I have left click-to-reveal in place, but mostly incase there is a
condition I've forgotten about.
2021-07-15 19:52:14 +02:00
Karol Kosek
67e3daa679 Breakout: Only paint areas that needs to be updated 2021-07-12 12:26:15 +02:00
Karol Kosek
a90c484d4b Pong: Only paint areas that needs to be updated 2021-07-11 14:11:26 +02:00
Timothy Flynn
dd65f52331 FlappyBug: Only paint areas which need to be painted
Drawing the entire PNG background is rather expensive. Instead, only
draw the rects that are updating.
2021-07-10 23:28:20 +02:00
networkException
39a3f42534 GameOfLife: Properly switch between play and pause icon
The play and pause icon were previously set on the toggle Action
and not on the Button of the Action that is part of the Toolbar
2021-07-07 15:29:37 +01:00
Jamie Mansfield
3f8857cd21 Games: Add Spider
Scoring is designed to mimic Microsoft's implementation - starting at
500, decreasing by 1 every move, and increasing by 100 for every full
stack.

Fixes GH-5319.
2021-06-24 10:32:53 +02:00
Sam Atkins
f2d6cac692
Solitaire: Maybe fix rare crash from completing a game with TAB (#8217)
The crash happens very rarely and is hard to reproduce so it is
hard to know for certain, but I am confident this fixes it.

I previously delayed the start of the game-over animation by one
frame, but neglected to check m_start_game_over_animation_next_frame
wasn't set. This means multiple calls to start_game_over_animation()
on the same frame (or rather, before the first timer_event) would
each call Object::start_timer(). Now that we do check the flag,
that should no longer be possible.

Fixes #8122.
2021-06-24 09:25:01 +02:00
Timothy Flynn
675b8ba995 FlappyBug: Standardize on "high score" rather than "highscore"
"High score" should be two words, and this matches other games in the
system.
2021-06-22 23:05:10 +02:00
Timothy Flynn
1a2053781f FlappyBug: Persist high score to disk
Previously, the high score was only in-memory, so only persisted for as
long as the FlappyBug window was open.
2021-06-22 23:05:10 +02:00
Timothy Flynn
25c53e35e7 FlappyBug: Convert the main game widget to a GUI::Frame 2021-06-22 23:05:10 +02:00
Linus Groh
ade85d980b FlappyBug: Add missing component declaration
The PR for this pre-dates the concept of components, so it was forgotten
to add one.
2021-06-20 11:13:30 +01:00
Mim Hufford
ddc855ffcd FlappyBug: Add cloud and sky graphics
We now have a nice sunset sky and some random cloud graphics.
The obstacles will get graphics at some point too :)
2021-06-20 10:54:27 +01:00
Mim Hufford
28e08f08c2 FlappyBug: Add new graphics and tweak colors
This adds some actual graphics to the game, and tweaks the obstacle and
sky colors. Eventually there will be graphics for those elements too.
2021-06-20 10:54:27 +01:00
Mim Hufford
f50003bdd2 FlappyBug: Add an input cooldown after game over
This makes sure the player doesn't accidentally start a new game after
they bump into an obstacle.
2021-06-20 10:54:27 +01:00
Mim Hufford
018344bb07 FlappyBug: Keep track of score and highscore
Better information is now shown to the player. Instructions are shown
when first loading the program, and any available scores are shown on
the game over screen.
2021-06-20 10:54:27 +01:00
Mim Hufford
3f603ab082 FlappyBug: Start obstacles off the screen
Previously obstacles were respawning fully on-screen which caused a
discontinuous look. Now they smoothly move into view from off-screen.
2021-06-20 10:54:27 +01:00
Mim Hufford
444fcfd0d2 FlappyBug: Make the obstacle gap position random
The position of the gap in the obstacle is now randomly generated each
time it spawns. The game is more fun to play now :)
2021-06-20 10:54:27 +01:00
Mim Hufford
811d9722f9 FlappyBug: Introduce a new Flappy Bug game
This introduces a Flappy Bug game. It's pretty simple currently, but is
playable.
2021-06-20 10:54:27 +01:00
Gunnar Beutner
631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Sam Atkins
364d728e66 Solitaire: Disable filling with background color during end animation
This fixes #7792.

The visual glitches with card corners, and the screen-clear when
opening a menu, were both caused by the widgets having
`fill_with_background_color` set. We need that set most of the time,
so we just disable it for the duration of the game-over animation.

Also resove a FIXME that no longer applies. :^)
2021-06-13 19:29:52 +01:00
Sam Atkins
679f831451 Solitaire: Only start timer when a move happens
Previously, the timer started if you clicked within the game area,
whether that was on a card or not. Now, we only start when you click
on a card or otherwise attempt a move.

As a bonus, we now immediately update the status bar time indicator
on game start, instead of having to wait until 1 second has elapsed.
2021-06-13 19:29:52 +01:00
Sam Atkins
8ee447b718 Solitaire: Prevent undo when the game is over 2021-06-13 19:29:52 +01:00
Sam Atkins
cf504ccc6a Solitaire: Allow automatic moves to end the game and animate
Previously, if a tab-move moved all the remaining cards to the
foundations, the game would not notice until you moved a card
away and then back again.

I had to add a 1-frame delay to starting the animation, so that it
would have time to re-paint the foundation in that case.
2021-06-13 19:29:52 +01:00
Dmitrii Ubskii
f11000b176
2048: Fix move success detection
Whether or not tiles moved used to be determined by comparing new_tiles
with m_tiles. This is no longer possible since the slide is done
in-place.

This fix makes the game look through the m_sliding_tiles, which contains
previous and current position for each tile on the board, to determine
whether any tile moved at all. If not, the move is deemed unsuccessful.

Fixes #8008.
2021-06-12 00:46:11 +01:00
Dmitrii Ubskii
242742b6c2 2048: Animate sliding tiles 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
8a8c2572b1 2048: Encapsulate away Board's inner workings
This change brings all the board twiddling code into the Board proper to
enable sliding animations further down the line.
2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
9ce5ce3560 2048: Add pop-in animation for newly added tiles 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
11158c2400 2048: Abstract Board into its own struct 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
ec8fe6952f 2048: East const all the things 2021-06-11 22:45:14 +02:00
Sam Atkins
e0fb36aad7 Solitaire: Iterate the foundation stacks and inline move_card()
Keeping this as a separate commit as I'm not certain whether this
is a good change or not. The repeated if-else for each Foundation
stack bothered me a bit, though more so before I reduced the code
in the {}. But maybe the ifs are clearer than the loop?

Doing that also meant I could inline the move_card() code instead
of needing to make it a lambda. Again, maybe it would be better as
a lambda? I'm still figuring out the style Serenity uses, and I
know Andreas is big on expressiveness, and move_card() is more
expressive than just having the code in the loop.
2021-06-11 22:42:38 +02:00
Sam Atkins
4917675529 Solitaire: Fix invisible cards when multiple are tab-moved at once
Previously, pressing <tab> to auto-move cards would render all but
the last one that moved invisible. Now they all render correctly.
:^)
2021-06-11 22:42:38 +02:00
Sam Atkins
f0dcf79116 Solitaire: Combine duplicate tab/double-click logic
The two paths did the same thing, in two different ways. Now they
are the same. :^)

Can't quite put all of the logic into
attempt_to_move_card_to_foundations() because the double-click has
to check that you clicked on the top card.
2021-06-11 22:42:38 +02:00
Sam Atkins
adedb3de2a Solitaire: Subtract points when undoing a card-flip
Solitaire: Correct default arg definition location
2021-06-11 22:42:38 +02:00
Sam Atkins
8d8b1d9531 Solitaire: Correctly score automatic moves using <tab> 2021-06-11 22:42:38 +02:00
Joshua Gollaher
eea95c4532 Chess: Remove 1:1 window aspect ratio 2021-06-11 11:31:35 +02:00
Ali Mohammad Pur
51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Gunnar Beutner
fab9b2f068 Hearts: Don't destroy the animation handler while running it 2021-06-04 19:32:25 +02:00
Timothy Flynn
2b762ef940 Solitaire+LibCards: Draw card stacks with rounded corners
Now that the cards have rounded corners, draw the stack box behind the
cards with rounded corners as well. This way, the corner of the stack
box doesn't peek out from behind the cards.

The caveat here is that the "play" card stack now needs to hold a
reference to the "waste" stack beneath it so it knows when not to draw
its background on top of the waste stack. To faciliate that, the array
of card stacks is now a NonnullRefPtrVector so the play stack can store
a smart pointer to the waste stack (instead of a raw pointer or
reference).
2021-06-04 19:11:45 +02:00
Matthew Jones
1748591570 Solitaire: Fixes undo feature from incorrect merge conflict resolution 2021-06-04 00:15:25 +02:00
Matthew B. Jones
ecaae2d10f
Solitaire: Add keys for drawing and moving cards to foundation stacks
Also shifts logic of starting game length timer into function
`start_timer_if_necessary`, so it can be called from original
mouse event handler and new `auto_move_eligible_cards_to_stacks`
2021-06-03 08:43:28 +01:00
Matthew B. Jones
ab4f4ddc3c
Solitaire: Add undo functionality 2021-06-03 01:16:49 +01:00
Matthew B. Jones
3ad7a1e944
Hearts: Play the first valid card (left-to-right) when pressing space 2021-06-02 23:07:12 +01:00
BrandonKi
ee38f5241d LibChess: Change cursor style when hovering or dragging valid piece 2021-06-02 11:18:40 +02:00
Gunnar Beutner
45117a4134 Hearts: Fix sorting for pick_low_points_high_value_card
Previously the function did not sort the hand at all which means we
wouldn't necessarily pick the card with the highest value.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
63d3beb78c Hearts: Prefer to pass high value cards
Previously we'd prefer to pass high points cards. Instead we should
prefer to pass high value cards first.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
8b9da08d5a Hearts: Pick better non-matching cards
When we don't have a matching card for the lead card rather than
always preferring to play hearts we should try to get rid of our
high value cards first if no other player has hearts cards higher
than what we have.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
4a8d8da46c Hearts: Make debugging AI suggestions easier
When building Hearts with HEARTS_DEBUG we highlight the card the AI
would have picked. This makes comparing AI and human decisions easier.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
2b2d992946 Hearts: Pick better cards when we're the third player
When we're the third player in a trick and we don't have a lower value
card we would previously pick a slightly higher value card. Instead
we should pick the highest value card unless there are points in the
current trick or the lead card is spades and the higher value card
we would've picked is higher than the queen and another player still
has the queen.

The rationale is that we have to take the trick anyway so we might as
well get rid of our highest value card. If the trailing player has a
lower value card of the same type we take the trick but don't gain
any points. If they don't have a card of the same type it doesn't
matter whether we play a high value or low value card.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
38f8a6aabb Hearts: Pick better lead cards
Previously the AI would prefer playing a lead card for which no other
player had a card with a higher value even though it also had a card
for which a higher value card was still in play.
2021-06-01 08:52:08 +02:00
Marcus Nilsson
f7667901ed Solitaire: Start timer when first card is moved
Starts the game timer when the first card is clicked or moved instead of
when a new game is started.

Fixes #7489
2021-05-27 22:55:37 +02:00
Gunnar Beutner
971f4ca71c Hearts: Highlight cards when an invalid play is attempted
This briefly inverts the selected card when the user attempts to make
an invalid play.
2021-05-26 19:57:08 +02:00
Timothy Flynn
a428812ba2 Solitaire: Persist high score separately per game mode
With different scoring rules for one-card vs. three-card draw mode, it
makes more sense to separately track their high scores.
2021-05-25 21:20:50 +02:00
Timothy Flynn
5d4cca7e0c Solitaire: Award bonus points based on time elapsed
The exact formula used for bonus points seems to vary by implementation.
This uses Klondike Solitaire's formula:

    https://en.wikipedia.org/wiki/Klondike_(solitaire)#Scoring
2021-05-25 21:20:50 +02:00
Timothy Flynn
0f80e9e4db Solitaire: Tweak scoring for three-card draw mode
Currently, the player loses 100 points each time the waste stack is
recycled. In three-card draw mode, it's standard to only lose 20 points
after the third recycle event.
2021-05-25 21:20:50 +02:00
Timothy Flynn
cf9094cf46 Solitaire: Remove dead call to Game::start_game_over_animation
This invocation will exit immediately. There's also no reason to invoke
stop_game_over_animation here because that's the first thing that will
happen in the call to setup.
2021-05-25 21:20:50 +02:00
Timothy Flynn
0b30a0febb Solitaire: Only update high score after a victorious game
Doesn't make much sense to update the high score on a lost game.
2021-05-25 21:20:50 +02:00
Gunnar Beutner
95401d2ca2 Hearts: Don't advance the game's state when an animation is playing
Previously we'd end up cancelling an animation that was still playing
when the user selects a card.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
fc99aa92bd Hearts: Fix animations that get stuck "mid-flight"
When an animation is stopped the cards should be moved to their final
position anyway. Otherwise they might end up getting stuck in the
middle of the animation.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
87ace131bc Hearts: Add support for playing more than one hand
This changes the game so that more than one hand can be played. Once
one player has 100 or more points the game ends. A score card is shown
between each hand.

Fixes #7374.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
e636ed43eb Hearts: Let the AI continuously play games
When there are no human players (toggled with Shift-F10) the AI will
continuously start new games when the current game has finished.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
ac1eba2f7c Hearts: Implement passing cards to other players
Fixes #7375.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
fab073f33c Hearts: Move card click handler into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
89d38b7e94 Hearts: Move sorting helper from Player::pick_lead_card into a method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
4ba9cc82c0 Hearts: Move code to reposition cards into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
9a6c6a98e5 Hearts: Move round initialization into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
4e3a1f2da9 Hearts: Move hand sorting functionality into a method 2021-05-25 21:05:35 +02:00
Josh Perry
d27616cf36 Hearts: Allow player to set their name
Added a new settings dialog to Hearts with a textbox to allow the
player to set a name, which is persisted in the Hearts config file.
2021-05-23 20:43:53 +01:00
Gunnar Beutner
6a194869cf Hearts: Add key combinations to letting the AI play for you
A single card can be played with F10 while Shift-F10 toggles the AI
for the current as well as all future tricks.
2021-05-23 18:15:36 +02:00
Gunnar Beutner
2dfced2501 Hearts: Let the AI prefer lead cards for which other cards are in play
When picking a lead card the AI should avoid playing cards where it
knows that no other player has a lower value card of the same type.
2021-05-23 18:15:36 +02:00
Gunnar Beutner
647d0f9f8a Hearts: Fix sorting function for lead cards
The pick_lead_card() function sometimes picks the incorrect card
because the sorted_hand vector wasn't being sorted properly.
2021-05-23 18:15:36 +02:00
Gunnar Beutner
1ae18c1228 Hearts: Let the AI pick better lead cards
Instead of picking the card with the lowest value we should pick the
card with the highest value for which we know no lower value card is
in play anymore and that someone else still has an even higher value
card.
2021-05-22 12:03:31 +01:00
Gunnar Beutner
c2a4b581fe Hearts: Prefer to play Queen of Spades when we're the trailing player
Previously in a trick like 2S, KS, 5S we'd rather follow up with AS
instead of QS. We should prefer to play QS in this case.
2021-05-22 12:03:31 +01:00
Gunnar Beutner
0dd22c4e23 Hearts: Fix crash when starting an animation when there already is one
This ensures that the preceding animation is stopped first.
2021-05-22 12:03:31 +01:00
Gunnar Beutner
dfa2075887 Hearts: Remove dead code 2021-05-22 12:03:31 +01:00
Ryan Wilson
1965d60aeb
GameOfLife: Add choosable patterns 2021-05-22 09:54:58 +01:00
Gunnar Beutner
c3efae85f2 Games: Add Hearts 2021-05-21 23:38:18 +02:00
Gunnar Beutner
3e47eec862 Solitaire: Move cards functionality into LibCards 2021-05-21 23:38:18 +02:00
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00
Lenny Maiorani
800ea8ea96 Userland: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-21 10:07:06 +01:00
Gunnar Beutner
3f42d39dce Solitaire: Fix a spelling mistake in one of the variable names 2021-05-20 22:07:20 +02:00
Andreas Kling
8a6c37deef LibGfx: Remove Gfx::FontDatabase::default_bold_fixed_width_font()
Ask for a bold_variant() of the default_fixed_width_font() instead.
2021-05-20 20:55:29 +02:00
Andreas Kling
6a012ad79f LibGfx: Remove Gfx::FontDatabase::default_bold_font()
Instead use default_font().bold_variant() in cases where we want a bold
variant of the default font. :^)
2021-05-20 20:55:29 +02:00
Jesse Buhagiar
2f49241296 Solitaire: Prevent player dragging entire stack to foundation
Currently, it is possible for the player to drag an entire stack
of cards to the foundation stack, provided the top card of the stack
(i.e the "root" card) can be dropped onto the foundation stack.
This causes an invalid state where, e.g, red cards end up in a
black foundation stack, or vice versa.
2021-05-18 20:05:10 +02:00
Dmitrii Ubskii
9c963fa17b Pong: Make the game winnable
- Make the ball chill out a bit by reducing its x velocity by 1.
- Make the AI dumber. It now relaxes until the ball is coming towards it
  and is in its half of the court.
2021-05-18 18:58:07 +01:00
Dmitrii Ubskii
9a7aac1c6a Pong: Fix paddle movement across resets if keys are held
The game waited for the next key down event before moving the player
paddle. Now the state of the arrow keys is carried over between resets.
2021-05-18 18:58:07 +01:00
Dmitrii Ubskii
58131082f4 Pong: Improve mouse controls
Just because you're the player, doesn't mean you can cheat ;)

- Limit paddle speed when following mouse cursor.
- Unhide pointer -- can't grab it, can't see when it's about to leave
  the window otherwise.
- Add last pointer y position indication for the player paddle.
- Prevent the paddle from following the mouse when Up or Down is being
  held (avoid controls fighting).
2021-05-18 18:58:07 +01:00
Dmitrii Ubskii
bb76bcde57 Pong: Improve AI paddle movement
Begin and end triggers for AI paddle to start moving prevent it from
continually jerking around the ball's position. It still moves in steps
of paddle.speed though, but overall experience is smoother.
2021-05-18 18:58:07 +01:00
Dmitrii Ubskii
7c67c9b45f Pong: Fix score display
Player 1's score used to be score's width offset to the right. Now it's
score_margin away from the divider line, same as player 2's.

Also factored out score margin and increased it from 2px to 5px just
to make it look a little nicer.
2021-05-18 18:58:07 +01:00
Timothy Flynn
547c7ba57f Solitaire: Display high score in status bar 2021-05-18 17:57:23 +02:00
Timothy Flynn
3d3a75f1b9 Solitaire: Track and persist high score 2021-05-18 17:57:23 +02:00
Timothy Flynn
7d062d0033 Solitaire: Persist game mode to config file 2021-05-18 17:57:23 +02:00
Timothy Flynn
8afaa7f30e 2048: Display action status tips in status bar 2021-05-18 16:48:39 +02:00
Timothy Flynn
97cee35471 2048: Do not default to only temporarily applying settings changes
Also tweak its text in the settings window to be clearer on what this
check box is doing. Seemed a bit confusing that settings changes
required an extra action to persist.
2021-05-18 16:48:39 +02:00
Timothy Flynn
1a66f487a5 2048: Widen the settings window
It's currently too small to fit the text of some of the settings (in
particular, the "Target tile" text).
2021-05-18 16:48:39 +02:00
Timothy Flynn
f02a13c884 2048: Intialize settings window with current values
Currently, each time you open the settings window in 2048, it displays
the default values rather than the current values. This is confusing, so
display the current values instead.
2021-05-18 16:48:39 +02:00
Marcus Nilsson
198a4e2a3c Solitaire: Stop timer if new game animation is running
Starting a new game before the animation had finished caused a crash
since it never stopped the timer before starting a new one.

Fixes #7222
2021-05-18 16:00:44 +02:00
Dmitrii Ubskii
94569e52f5 2048: Minimize player score when selecting worst tile
Maximizing the board population still takes priority, but if there are
tile generator "moves" that result in equivalent board population after
a player move, the one with the lowest score is selected.
2021-05-18 08:51:56 +01:00
Dmitrii Ubskii
a93d0fe8c2 2048: Evil AI logic: select new tile in the worst position
Not very smart: the worst position is defined such that after the
player's next move the fewest tiles remain empty.
2021-05-18 08:51:56 +01:00
Dmitrii Ubskii
4434e900af 2048: Evil AI settings entry 2021-05-18 08:51:56 +01:00
Dmitrii Ubskii
3e8220dec2 2048: Refactor tile sliding and score logic out of attempt_move() 2021-05-18 08:51:56 +01:00
Jean-Baptiste Boric
0262a99a1f Chess: Fix signed/unsigned issues
Make everything signed so that we don't have to deal with silly casting
issues thoughout the Chess code. I am unsure if this affects the chess
AI negatively, it seems just as "intelligent" before and after this
change :^)
2021-05-17 18:14:05 +01:00
Andreas Kling
67ed580532 Chess: Make the main widget a GUI::Frame for a nicer look :^) 2021-05-17 12:02:38 +02:00
Linus Groh
d7c0370c57 GameOfLife: Don't randomize cells on board resize
Loosing all game state for a simple resize of the board is quite
disappointing, so let's not do that. :^)
2021-05-16 23:00:21 +02:00
Linus Groh
7dea3d41cb GameOfLife: Use a frame as the board widget container
This adds a bit of depth and looks very nice :^)
2021-05-16 23:00:21 +02:00
Linus Groh
9151364e22 GameOfLife: Add vertical separator between interval and action buttons 2021-05-16 23:00:21 +02:00
Linus Groh
d859bde337 GameOfLife: Move "ms" interval label to GML
There's no reason not to!
2021-05-16 23:00:21 +02:00
Linus Groh
e7dc0bdba3 GameOfLife: Auto-size toolbar labels 2021-05-16 23:00:21 +02:00
Linus Groh
9a3f62adc7 GameOfLife: Remove some unused includes 2021-05-16 23:00:21 +02:00
Linus Groh
030360c787 GameOfLife: Add some margin to the toolbar layout
Ideally the inner widgets / vertical separators would have some as well,
but I'm not sure how right now. One step at a time. :^)
2021-05-16 23:00:21 +02:00
Linus Groh
f89eb0e4ce GameOfLife: Switch from single indexed vector to rows+columns
This is not only easier to comprehend code-wise and avoids some function
overloads, but also makes resizing the board while preserving game state
*a lot* easier. We now no longer have to allocate a new board on every
resize, we just grow/shrink the individual row vectors.
Also fixes a crash when clicking the board widget outside of the drawn
board area.
2021-05-16 23:00:21 +02:00
Timothy Flynn
ddb278ab85 Solitaire: Add key combo to dump the state of the layout
Useful for chasing down bugs.
2021-05-16 16:37:51 +02:00
Timothy Flynn
68e86dc804 Solitaire: Add shift modifier to hidden "game over" key combo
Makes it a bit less likely that someone will hit it on accident and ruin
their game.
2021-05-16 16:37:51 +02:00
Timothy Flynn
e310b9cd0d Solitaire: Add setting for number of cards to be drawn
Klondike Solitaire has a couple more modes, but this adds modes for 1-
and 3-card draws.
2021-05-16 16:37:51 +02:00
Timothy Flynn
3a45bf5254 Solitaire: Add stack for the playable cards on top of the waste stack
While the waste stack and the playable card on top of the waste stack
are collectively referred to as the "waste", it's programatically nice
to separate them to enable 3-card-draw mode. In that mode, the playable
stack will contain 3 cards with a slight x-axis shift, while the waste
stack underneath will remain unshifted. So rather than introducing some
ugly logic to CardStack to handle this, it's more convenient to have a
separate stack on top of the waste stack.
2021-05-16 16:37:51 +02:00
Linus Groh
0fb96e6cbf GameOfLife: Spell about action app name as "Game Of Life" 2021-05-15 17:55:49 +01:00
Linus Groh
9f9f54a9ad GameOfLife: Add separator before quit menu action 2021-05-15 17:55:27 +01:00
Linus Groh
310ec73550 GameOfLife: Add alt shortcuts to menus 2021-05-15 17:54:50 +01:00
Linus Groh
2225e18749 GameOfLife: Rename primary menu to just "Game" 2021-05-15 17:52:58 +01:00
Andres Crucitti
d99991e39c Games: Add GameOfLife
This patch introduces a new game based on Conway's Game of Life.
2021-05-15 17:44:21 +01:00
Jean-Baptiste Boric
090936e424 Userland: Replace arc4random() with get_random<u32>() 2021-05-14 22:24:02 +02:00
Andreas Kling
31d4bcf5bf Userland: Tighten a *lot* of pledges! :^)
Since applications using Core::EventLoop no longer need to create a
socket in /tmp/rpc/, and also don't need to listen for incoming
connections on this socket, we can remove a whole bunch of pledges!
2021-05-13 23:28:40 +02:00
Linus Groh
f47153d437 2048: Add separator before quit menu action 2021-05-12 23:04:36 +01:00
Linus Groh
91eda22208 Everywhere: Add Alt shortcuts to remaining top-level menus
Not sure why some menus did have one and others didn't, even in the
same application - now they all do. :^)
I added character shortcuts to some menu actions as well.
2021-05-12 18:09:42 +01:00
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
Umar Haroon
53e1ee2cb7 2048: Added Redo Support 2021-05-11 10:22:27 +01:00
Linus Groh
83d980ab9e Chess+Help: Remove erroneous ampersand from app name
This is not applicable here, the alt shortcut is set elsewhere.
2021-05-07 20:37:28 +01:00
Timothy Flynn
e8b508516a Solitaire: Decrease new game animation delay
The current setting is an awful long time to wait for a game to start.
2021-05-05 21:38:45 +02:00
Timothy Flynn
a07c178a02 Solitaire: Add statusbar segment to display elapsed time
The timer begins after the new-game animation ends, and stops when
either the game-over animation begins or the new-game animation is
started again.
2021-05-05 21:38:45 +02:00
Timothy Flynn
b2576b7e45 Solitaire: Add a GUI::Statusbar to the Solitaire window
This will display the score (instead of updating the window title) and
any hovered action text.
2021-05-05 21:38:45 +02:00
Timothy Flynn
59193dd6b3 Solitaire: Only start timer when the timer event is needed
The timer is no longer used to trigger a paint event for all updates; it
is only used to paint the new-game and game-over animations. So only run
the timer during those events.
2021-05-05 21:38:45 +02:00
Timothy Flynn
4fc9c1d710 Solitaire: Refactor painting logic to accomodate to-be-added widgets
A series of events led to this change: The goal is to add more widgets
to the Solitaire GML, such as a GUI::Statusbar. To do so without this
change, the window ends up with some black artifacts between the main
Solitaire frame and the added elements, because the GML specifies the
main widget to have fill_with_background_color=false. However, setting
that property to true results in the background color of the widget
interferring with the Solitaire frame trying to manually paint its
background green. This results in flickering and some elements in the
Solitaire frame being painted over by the main background color.

To avoid all of that behavior, this sets fill_with_background_color=true
and the Solitaire frame's background color to green in the GML. Further,
the frame now only queues a paint update on the specific Gfx::Rect areas
that need to be updated. This also means we no longer need to track if a
stack of cards is dirty, because we only trigger a paint event for dirty
stacks.
2021-05-05 21:38:45 +02:00
Timothy Flynn
bb7b76e505 Solitaire: Don't invoke srand multiple times
This doesn't need to be invoked each time the game wants something
random.
2021-05-05 21:38:45 +02:00
Timothy Flynn
a540ec3519 Solitaire: Convert Solitaire GUI to a frame
Looks a bit nicer as a frame with inset edges.
2021-05-05 21:38:45 +02:00
Timothy Flynn
0ff4eec8a8 Solitaire: Convert Solitaire window to be created from GML
No functionial change here, but this more easily allows for adding GUI
elements to the Solitaire window. This nests the SolitaireWidget as a
child of the main window's widget so that the SolitaireWidget does not
color the entire window green when it paints its background.
2021-05-05 21:38:45 +02:00
Timothy Flynn
e1492e9a62 Solitaire: Place files in Solitaire namespace and rename main widget
The purpose is to allow the Solitaire widget to be used in GML. The
macro to register a widget requires a namespace, so this moves all files
in the application to the Solitaire namespace. This also renames the
SolitaireWidget class to Game - this is to avoid the redundancy /
verbosity of typing "Solitaire::SolitaireWidget", and matches many other
games in Serenity (Breakout, 2048, etc.).
2021-05-05 21:38:45 +02:00
Timothy Flynn
15f0ee1727 Solitaire: Replace self-owned timer with Core::Object's timer
This is just a bit nicer than owning a separate timer in the Solitaire
application because LibCore will prevent timer events from firing when
e.g. the window is not visible. Therefore SolitaireWidget doesn't need
need to check for such conditions.
2021-05-05 21:38:45 +02:00
Timothy Flynn
cfc3a2ebac Solitaire: Bump stacked cards down to reveal suit
Stacks of cards currently cover the suit completely and players must
click-and-drag cards out of the way to see the suit beneath other cards.
This bumps the stacks down a bit to let players peek the suit without
having to take any action.
2021-05-05 21:38:45 +02:00
Andreas Kling
04c3cddb1e Snake: Spruce up the GUI a tiny bit
Give the game window a GUI::Frame appearance, and make sure the
menus have Alt shortcuts. :^)
2021-05-04 17:32:19 +02:00
Andreas Kling
62125796c3 Minesweeper: Tweak main UI layout a little bit
Move the clock/flag icons closer to their respective text labels.
2021-05-03 18:07:35 +02:00
Andreas Kling
6e4e3cefb2 Minesweeper: Add a tasteful separator line between menubar and UI 2021-05-03 17:08:28 +02:00
Gunnar Beutner
b613817bca Userland: Fix 64-bit portability issues 2021-05-03 08:42:39 +02:00
Matthew Olsson
88cfaf7bf0 LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
2021-05-02 22:48:06 +02:00
Andreas Kling
4b0098e52f Everywhere: Rename app_menu to file_menu or game_menu 2021-05-01 17:40:54 +02:00
Andreas Kling
7ae7170d61 Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Nicholas-Baron
73dd293ec4 Everywhere: Add -Wdouble-promotion warning
This warning informs of float-to-double conversions. The best solution
seems to be to do math *either* in 32-bit *or* in 64-bit, and only to
cross over when absolutely necessary.
2021-04-16 19:01:54 +02:00
Andreas Kling
d8787e0e12 Chess: Alt shortcuts and book title capitalization in menus 2021-04-14 21:32:37 +02:00
Andreas Kling
cfe7f6fe50 Pong: Alt shortcuts in top-level menus 2021-04-14 21:25:02 +02:00
Andreas Kling
8529053ffe 2048: Alt shortcuts and book title capitalization in menus 2021-04-14 21:25:02 +02:00
Jean-Baptiste Boric
900fe5633a Minesweeper: Use one premade mine palette for all mine widgets
Fixes #6283
2021-04-13 21:52:34 +02:00
Andreas Kling
a2baab38fd Everywhere: It's now "Foobar", not "FooBar", and not "foo bar"
I hereby declare these to be full nouns that we don't split,
neither by space, nor by underscore:

- Breadcrumbbar
- Coolbar
- Menubar
- Progressbar
- Scrollbar
- Statusbar
- Taskbar
- Toolbar

This patch makes everything consistent by replacing every other variant
of these with the proper one. :^)
2021-04-13 16:58:15 +02:00
Andreas Kling
a7ad0f14bf Minesweeper: Fix UI layout and focus behavior
Click-to-focus was visually annoying. Switch to tab-to-focus.
2021-04-06 17:55:47 +02:00