mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
Snake: Use AK::get_random_uniform() instead of rand()
This commit is contained in:
parent
4c8fe01bff
commit
d3d170851d
1 changed files with 4 additions and 6 deletions
|
@ -6,13 +6,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SnakeGame.h"
|
#include "SnakeGame.h"
|
||||||
|
#include <AK/Random.h>
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
SnakeGame::SnakeGame()
|
SnakeGame::SnakeGame()
|
||||||
{
|
{
|
||||||
|
@ -21,7 +20,6 @@ SnakeGame::SnakeGame()
|
||||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png"));
|
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png"));
|
||||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png"));
|
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png"));
|
||||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png"));
|
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png"));
|
||||||
srand(time(nullptr));
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0);
|
m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0);
|
||||||
|
@ -63,13 +61,13 @@ void SnakeGame::spawn_fruit()
|
||||||
{
|
{
|
||||||
Coordinate coord;
|
Coordinate coord;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
coord.row = rand() % m_rows;
|
coord.row = get_random_uniform(m_rows);
|
||||||
coord.column = rand() % m_columns;
|
coord.column = get_random_uniform(m_columns);
|
||||||
if (is_available(coord))
|
if (is_available(coord))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_fruit = coord;
|
m_fruit = coord;
|
||||||
m_fruit_type = rand() % m_fruit_bitmaps.size();
|
m_fruit_type = get_random_uniform(m_fruit_bitmaps.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::IntRect SnakeGame::score_rect() const
|
Gfx::IntRect SnakeGame::score_rect() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue