mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
AK: Make Vector use size_t for its size and capacity
This commit is contained in:
parent
9c6f7d3e7d
commit
ceec1a7d38
94 changed files with 323 additions and 317 deletions
|
@ -183,8 +183,8 @@ void Field::set_face(Face face)
|
|||
template<typename Callback>
|
||||
void Square::for_each_neighbor(Callback callback)
|
||||
{
|
||||
int r = row;
|
||||
int c = column;
|
||||
size_t r = row;
|
||||
size_t c = column;
|
||||
if (r > 0) // Up
|
||||
callback(field->square(r - 1, c));
|
||||
if (c > 0) // Left
|
||||
|
@ -217,7 +217,7 @@ void Field::reset()
|
|||
|
||||
m_squares.resize(max(m_squares.size(), rows() * columns()));
|
||||
|
||||
for (int i = rows() * columns(); i < m_squares.size(); ++i) {
|
||||
for (int i = rows() * columns(); i < static_cast<int>(m_squares.size()); ++i) {
|
||||
auto& square = m_squares[i];
|
||||
square->button->set_visible(false);
|
||||
square->label->set_visible(false);
|
||||
|
@ -230,12 +230,12 @@ void Field::reset()
|
|||
mines.set(location);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (int r = 0; r < rows(); ++r) {
|
||||
for (int c = 0; c < columns(); ++c) {
|
||||
size_t i = 0;
|
||||
for (size_t r = 0; r < rows(); ++r) {
|
||||
for (size_t c = 0; c < columns(); ++c) {
|
||||
if (!m_squares[i])
|
||||
m_squares[i] = make<Square>();
|
||||
Gfx::Rect rect = { frame_thickness() + c * square_size(), frame_thickness() + r * square_size(), square_size(), square_size() };
|
||||
Gfx::Rect rect = { frame_thickness() + static_cast<int>(c) * square_size(), frame_thickness() + static_cast<int>(r) * square_size(), square_size(), square_size() };
|
||||
auto& square = this->square(r, c);
|
||||
square.field = this;
|
||||
square.row = r;
|
||||
|
@ -276,10 +276,10 @@ void Field::reset()
|
|||
}
|
||||
}
|
||||
|
||||
for (int r = 0; r < rows(); ++r) {
|
||||
for (int c = 0; c < columns(); ++c) {
|
||||
for (size_t r = 0; r < rows(); ++r) {
|
||||
for (size_t c = 0; c < columns(); ++c) {
|
||||
auto& square = this->square(r, c);
|
||||
int number = 0;
|
||||
size_t number = 0;
|
||||
square.for_each_neighbor([&number](auto& neighbor) {
|
||||
number += neighbor.has_mine;
|
||||
});
|
||||
|
@ -380,7 +380,7 @@ void Field::on_square_chorded(Square& square)
|
|||
return;
|
||||
if (!square.number)
|
||||
return;
|
||||
int adjacent_flags = 0;
|
||||
size_t adjacent_flags = 0;
|
||||
square.for_each_neighbor([&](auto& neighbor) {
|
||||
if (neighbor.has_flag)
|
||||
++adjacent_flags;
|
||||
|
@ -461,8 +461,8 @@ void Field::game_over()
|
|||
|
||||
void Field::reveal_mines()
|
||||
{
|
||||
for (int r = 0; r < rows(); ++r) {
|
||||
for (int c = 0; c < columns(); ++c) {
|
||||
for (size_t r = 0; r < rows(); ++r) {
|
||||
for (size_t c = 0; c < columns(); ++c) {
|
||||
auto& square = this->square(r, c);
|
||||
if (square.has_mine && !square.has_flag) {
|
||||
square.button->set_visible(false);
|
||||
|
@ -490,7 +490,7 @@ void Field::set_chord_preview(Square& square, bool chord_preview)
|
|||
});
|
||||
}
|
||||
|
||||
void Field::set_field_size(int rows, int columns, size_t mine_count)
|
||||
void Field::set_field_size(size_t rows, size_t columns, size_t mine_count)
|
||||
{
|
||||
if (m_rows == rows && m_columns == columns && m_mine_count == mine_count)
|
||||
return;
|
||||
|
@ -526,6 +526,6 @@ Square::~Square()
|
|||
template<typename Callback>
|
||||
void Field::for_each_square(Callback callback)
|
||||
{
|
||||
for (int i = 0; i < rows() * columns(); ++i)
|
||||
for (size_t i = 0; i < rows() * columns(); ++i)
|
||||
callback(*m_squares[i]);
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ public:
|
|||
bool has_mine { false };
|
||||
bool has_flag { false };
|
||||
bool is_considering { false };
|
||||
int row { 0 };
|
||||
int column { 0 };
|
||||
int number { 0 };
|
||||
size_t row { 0 };
|
||||
size_t column { 0 };
|
||||
size_t number { 0 };
|
||||
RefPtr<SquareButton> button;
|
||||
RefPtr<SquareLabel> label;
|
||||
|
||||
|
@ -63,13 +63,13 @@ public:
|
|||
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::Size)> on_size_changed);
|
||||
virtual ~Field() override;
|
||||
|
||||
int rows() const { return m_rows; }
|
||||
int columns() const { return m_columns; }
|
||||
size_t rows() const { return m_rows; }
|
||||
size_t columns() const { return m_columns; }
|
||||
size_t mine_count() const { return m_mine_count; }
|
||||
int square_size() const { return 15; }
|
||||
bool is_single_chording() const { return m_single_chording; }
|
||||
|
||||
void set_field_size(int rows, int columns, size_t mine_count);
|
||||
void set_field_size(size_t rows, size_t columns, size_t mine_count);
|
||||
void set_single_chording(bool new_val);
|
||||
|
||||
void reset();
|
||||
|
@ -87,8 +87,8 @@ private:
|
|||
void set_chord_preview(Square&, bool);
|
||||
void set_flag(Square&, bool);
|
||||
|
||||
Square& square(int row, int column) { return *m_squares[row * columns() + column]; }
|
||||
const Square& square(int row, int column) const { return *m_squares[row * columns() + column]; }
|
||||
Square& square(size_t row, size_t column) { return *m_squares[row * columns() + column]; }
|
||||
const Square& square(size_t row, size_t column) const { return *m_squares[row * columns() + column]; }
|
||||
|
||||
void flood_fill(Square&);
|
||||
void on_square_clicked_impl(Square&, bool);
|
||||
|
@ -103,10 +103,10 @@ private:
|
|||
};
|
||||
void set_face(Face);
|
||||
|
||||
int m_rows { 0 };
|
||||
int m_columns { 0 };
|
||||
size_t m_rows { 0 };
|
||||
size_t m_columns { 0 };
|
||||
size_t m_mine_count { 0 };
|
||||
int m_unswept_empties { 0 };
|
||||
size_t m_unswept_empties { 0 };
|
||||
Vector<OwnPtr<Square>> m_squares;
|
||||
RefPtr<Gfx::Bitmap> m_mine_bitmap;
|
||||
RefPtr<Gfx::Bitmap> m_flag_bitmap;
|
||||
|
@ -120,8 +120,8 @@ private:
|
|||
GUI::Label& m_flag_label;
|
||||
GUI::Label& m_time_label;
|
||||
RefPtr<Core::Timer> m_timer;
|
||||
int m_time_elapsed { 0 };
|
||||
int m_flags_left { 0 };
|
||||
size_t m_time_elapsed { 0 };
|
||||
size_t m_flags_left { 0 };
|
||||
Face m_face { Face::Default };
|
||||
bool m_chord_preview { false };
|
||||
bool m_first_click { true };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue