summaryrefslogtreecommitdiff
path: root/Games
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-25 14:49:47 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-25 14:52:35 +0100
commitceec1a7d38d4c8941dbf537b85bd50f0030ffbec (patch)
tree2b137c37ae0f331bb3626583a619a3175ef614d4 /Games
parent9c6f7d3e7d2252ad2d51f2c7c7379cab867fa477 (diff)
downloadserenity-ceec1a7d38d4c8941dbf537b85bd50f0030ffbec.zip
AK: Make Vector use size_t for its size and capacity
Diffstat (limited to 'Games')
-rw-r--r--Games/Minesweeper/Field.cpp30
-rw-r--r--Games/Minesweeper/Field.h26
-rw-r--r--Games/Snake/SnakeGame.cpp4
-rw-r--r--Games/Snake/SnakeGame.h2
4 files changed, 31 insertions, 31 deletions
diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp
index cff67823a6..36d7449672 100644
--- a/Games/Minesweeper/Field.cpp
+++ b/Games/Minesweeper/Field.cpp
@@ -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]);
}
diff --git a/Games/Minesweeper/Field.h b/Games/Minesweeper/Field.h
index db6ee64fbb..742329fde8 100644
--- a/Games/Minesweeper/Field.h
+++ b/Games/Minesweeper/Field.h
@@ -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 };
diff --git a/Games/Snake/SnakeGame.cpp b/Games/Snake/SnakeGame.cpp
index 39ba9caa44..5c05446185 100644
--- a/Games/Snake/SnakeGame.cpp
+++ b/Games/Snake/SnakeGame.cpp
@@ -66,7 +66,7 @@ void SnakeGame::reset()
bool SnakeGame::is_available(const Coordinate& coord)
{
- for (int i = 0; i < m_tail.size(); ++i) {
+ for (size_t i = 0; i < m_tail.size(); ++i) {
if (m_tail[i] == coord)
return false;
}
@@ -134,7 +134,7 @@ void SnakeGame::timer_event(Core::TimerEvent&)
dirty_cells.append(m_head);
- for (int i = 0; i < m_tail.size(); ++i) {
+ for (size_t i = 0; i < m_tail.size(); ++i) {
if (m_head == m_tail[i]) {
game_over();
return;
diff --git a/Games/Snake/SnakeGame.h b/Games/Snake/SnakeGame.h
index 6ecb5fa099..e015f3fd73 100644
--- a/Games/Snake/SnakeGame.h
+++ b/Games/Snake/SnakeGame.h
@@ -81,7 +81,7 @@ private:
Coordinate m_fruit;
int m_fruit_type { 0 };
- int m_length { 0 };
+ size_t m_length { 0 };
unsigned m_score { 0 };
String m_score_text;
unsigned m_high_score { 0 };