Games: Run clang-format on everything.

This commit is contained in:
Andreas Kling 2019-06-07 11:48:15 +02:00
parent fd604a7c68
commit fba2c971e7
Notes: sideshowbarker 2024-07-19 13:41:32 +09:00
4 changed files with 29 additions and 30 deletions

View file

@ -1,11 +1,11 @@
#include "Field.h" #include "Field.h"
#include <AK/HashTable.h>
#include <LibCore/CConfigFile.h>
#include <LibGUI/GButton.h> #include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h> #include <LibGUI/GLabel.h>
#include <LibGUI/GPainter.h> #include <LibGUI/GPainter.h>
#include <LibCore/CConfigFile.h>
#include <AK/HashTable.h>
#include <unistd.h>
#include <time.h> #include <time.h>
#include <unistd.h>
class SquareButton final : public GButton { class SquareButton final : public GButton {
public: public:
@ -50,7 +50,7 @@ public:
} }
} }
if (event.button() == GMouseButton::Middle) { if (event.button() == GMouseButton::Middle) {
m_square.field->for_each_square([] (auto& square) { m_square.field->for_each_square([](auto& square) {
if (square.is_considering) { if (square.is_considering) {
square.is_considering = false; square.is_considering = false;
square.button->set_icon(nullptr); square.button->set_icon(nullptr);
@ -120,7 +120,7 @@ Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidg
set_background_color(Color::LightGray); set_background_color(Color::LightGray);
reset(); reset();
m_face_button.on_click = [this] (auto&) { reset(); }; m_face_button.on_click = [this](auto&) { reset(); };
set_face(Face::Default); set_face(Face::Default);
} }
@ -218,7 +218,7 @@ void Field::reset()
if (!square.button) { if (!square.button) {
square.button = new SquareButton(this); square.button = new SquareButton(this);
square.button->set_checkable(true); square.button->set_checkable(true);
square.button->on_click = [this, &square] (GButton&) { square.button->on_click = [this, &square](GButton&) {
on_square_clicked(square); on_square_clicked(square);
}; };
square.button->on_right_click = [this, &square] { square.button->on_right_click = [this, &square] {
@ -244,7 +244,7 @@ void Field::reset()
for (int c = 0; c < columns(); ++c) { for (int c = 0; c < columns(); ++c) {
auto& square = this->square(r, c); auto& square = this->square(r, c);
int number = 0; int number = 0;
square.for_each_neighbor([&number] (auto& neighbor) { square.for_each_neighbor([&number](auto& neighbor) {
number += neighbor.has_mine; number += neighbor.has_mine;
}); });
square.number = number; square.number = number;
@ -262,7 +262,7 @@ void Field::reset()
void Field::flood_fill(Square& square) void Field::flood_fill(Square& square)
{ {
on_square_clicked(square); on_square_clicked(square);
square.for_each_neighbor([this] (auto& neighbor) { square.for_each_neighbor([this](auto& neighbor) {
if (!neighbor.is_swept && !neighbor.has_mine && neighbor.number == 0) if (!neighbor.is_swept && !neighbor.has_mine && neighbor.number == 0)
flood_fill(neighbor); flood_fill(neighbor);
if (!neighbor.has_mine && neighbor.number) if (!neighbor.has_mine && neighbor.number)
@ -333,13 +333,13 @@ void Field::on_square_chorded(Square& square)
if (!square.number) if (!square.number)
return; return;
int adjacent_flags = 0; int adjacent_flags = 0;
square.for_each_neighbor([&] (auto& neighbor) { square.for_each_neighbor([&](auto& neighbor) {
if (neighbor.has_flag) if (neighbor.has_flag)
++adjacent_flags; ++adjacent_flags;
}); });
if (square.number != adjacent_flags) if (square.number != adjacent_flags)
return; return;
square.for_each_neighbor([&] (auto& neighbor) { square.for_each_neighbor([&](auto& neighbor) {
if (neighbor.has_flag) if (neighbor.has_flag)
return; return;
on_square_clicked(neighbor); on_square_clicked(neighbor);
@ -396,7 +396,7 @@ void Field::win()
m_timer.stop(); m_timer.stop();
set_greedy_for_hits(true); set_greedy_for_hits(true);
set_face(Face::Good); set_face(Face::Good);
for_each_square([&] (auto& square) { for_each_square([&](auto& square) {
if (!square.has_flag && square.has_mine) if (!square.has_flag && square.has_mine)
set_flag(square, true); set_flag(square, true);
}); });
@ -435,7 +435,7 @@ void Field::set_chord_preview(Square& square, bool chord_preview)
if (m_chord_preview == chord_preview) if (m_chord_preview == chord_preview)
return; return;
m_chord_preview = chord_preview; m_chord_preview = chord_preview;
square.for_each_neighbor([&] (auto& neighbor) { square.for_each_neighbor([&](auto& neighbor) {
neighbor.button->set_checked(false); neighbor.button->set_checked(false);
if (!neighbor.has_flag && !neighbor.is_considering) if (!neighbor.has_flag && !neighbor.is_considering)
neighbor.button->set_checked(chord_preview); neighbor.button->set_checked(chord_preview);

View file

@ -1,13 +1,13 @@
#include "Field.h" #include "Field.h"
#include <LibCore/CConfigFile.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h> #include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GBoxLayout.h> #include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h> #include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GMenu.h> #include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h> #include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h> #include <LibGUI/GWindow.h>
#include <LibGUI/GLabel.h>
#include <LibCore/CConfigFile.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -58,33 +58,33 @@ int main(int argc, char** argv)
auto menubar = make<GMenuBar>(); auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("Minesweeper"); auto app_menu = make<GMenu>("Minesweeper");
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) { app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) {
GApplication::the().quit(0); GApplication::the().quit(0);
return; return;
})); }));
menubar->add_menu(move(app_menu)); menubar->add_menu(move(app_menu));
auto game_menu = make<GMenu>("Game"); auto game_menu = make<GMenu>("Game");
game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [field] (const GAction&) { game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [field](const GAction&) {
field->reset(); field->reset();
})); }));
game_menu->add_separator(); game_menu->add_separator();
game_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [field] (const GAction&) { game_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [field](const GAction&) {
field->set_field_size(9, 9, 10); field->set_field_size(9, 9, 10);
})); }));
game_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [field] (const GAction&) { game_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [field](const GAction&) {
field->set_field_size(16, 16, 40); field->set_field_size(16, 16, 40);
})); }));
game_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [field] (const GAction&) { game_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [field](const GAction&) {
field->set_field_size(16, 30, 99); field->set_field_size(16, 30, 99);
})); }));
game_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [field] (const GAction&) { game_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [field](const GAction&) {
field->set_field_size(32, 60, 350); field->set_field_size(32, 60, 350);
})); }));
menubar->add_menu(move(game_menu)); menubar->add_menu(move(game_menu));
auto help_menu = make<GMenu>("Help"); auto help_menu = make<GMenu>("Help");
help_menu->add_action(GAction::create("About", [] (const GAction&) { help_menu->add_action(GAction::create("About", [](const GAction&) {
dbgprintf("FIXME: Implement Help/About\n"); dbgprintf("FIXME: Implement Help/About\n");
})); }));
menubar->add_menu(move(help_menu)); menubar->add_menu(move(help_menu));

View file

@ -1,6 +1,6 @@
#include "SnakeGame.h" #include "SnakeGame.h"
#include <LibGUI/GPainter.h>
#include <LibGUI/GFontDatabase.h> #include <LibGUI/GFontDatabase.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/GraphicsBitmap.h> #include <SharedGraphics/GraphicsBitmap.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -198,7 +198,6 @@ void SnakeGame::paint_event(GPaintEvent& event)
painter.fill_rect(right_side, Color::from_rgb(0x888800)); painter.fill_rect(right_side, Color::from_rgb(0x888800));
painter.fill_rect(top_side, Color::from_rgb(0xcccc00)); painter.fill_rect(top_side, Color::from_rgb(0xcccc00));
painter.fill_rect(bottom_side, Color::from_rgb(0x888800)); painter.fill_rect(bottom_side, Color::from_rgb(0x888800));
} }
painter.draw_scaled_bitmap(cell_rect(m_fruit), *m_fruit_bitmaps[m_fruit_type], m_fruit_bitmaps[m_fruit_type]->rect()); painter.draw_scaled_bitmap(cell_rect(m_fruit), *m_fruit_bitmaps[m_fruit_type], m_fruit_bitmaps[m_fruit_type]->rect());

View file

@ -1,11 +1,11 @@
#include "SnakeGame.h" #include "SnakeGame.h"
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h> #include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GBoxLayout.h> #include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h> #include <LibGUI/GButton.h>
#include <LibGUI/GMenu.h> #include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h> #include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h> #include <LibGUI/GWindow.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -23,20 +23,20 @@ int main(int argc, char** argv)
auto menubar = make<GMenuBar>(); auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("Snake"); auto app_menu = make<GMenu>("Snake");
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) { app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) {
GApplication::the().quit(0); GApplication::the().quit(0);
return; return;
})); }));
menubar->add_menu(move(app_menu)); menubar->add_menu(move(app_menu));
auto game_menu = make<GMenu>("Game"); auto game_menu = make<GMenu>("Game");
game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&] (const GAction&) { game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&](const GAction&) {
game->reset(); game->reset();
})); }));
menubar->add_menu(move(game_menu)); menubar->add_menu(move(game_menu));
auto help_menu = make<GMenu>("Help"); auto help_menu = make<GMenu>("Help");
help_menu->add_action(GAction::create("About", [] (const GAction&) { help_menu->add_action(GAction::create("About", [](const GAction&) {
dbgprintf("FIXME: Implement Help/About\n"); dbgprintf("FIXME: Implement Help/About\n");
})); }));
menubar->add_menu(move(help_menu)); menubar->add_menu(move(help_menu));