mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
Hearts: Use AK::get_random_uniform() instead of rand()/srand()
This commit is contained in:
parent
1621311d73
commit
5201c17d9b
1 changed files with 2 additions and 4 deletions
|
@ -10,13 +10,13 @@
|
||||||
#include "ScoreCard.h"
|
#include "ScoreCard.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
|
#include <AK/Random.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Dialog.h>
|
#include <LibGUI/Dialog.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
REGISTER_WIDGET(Hearts, Game);
|
REGISTER_WIDGET(Hearts, Game);
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ namespace Hearts {
|
||||||
|
|
||||||
Game::Game()
|
Game::Game()
|
||||||
{
|
{
|
||||||
srand(time(nullptr));
|
|
||||||
|
|
||||||
m_delay_timer = Core::Timer::create_single_shot(0, [this] {
|
m_delay_timer = Core::Timer::create_single_shot(0, [this] {
|
||||||
dbgln_if(HEARTS_DEBUG, "Continuing game after delay...");
|
dbgln_if(HEARTS_DEBUG, "Continuing game after delay...");
|
||||||
advance_game();
|
advance_game();
|
||||||
|
@ -215,7 +213,7 @@ void Game::setup(String player_name, int hand_number)
|
||||||
|
|
||||||
for (auto& player : m_players) {
|
for (auto& player : m_players) {
|
||||||
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
||||||
auto card = deck.take(rand() % deck.size());
|
auto card = deck.take(get_random_uniform(deck.size()));
|
||||||
if constexpr (!HEARTS_DEBUG) {
|
if constexpr (!HEARTS_DEBUG) {
|
||||||
if (&player != &m_players[0])
|
if (&player != &m_players[0])
|
||||||
card->set_upside_down(true);
|
card->set_upside_down(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue