2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-04-19 20:54:10 -03:00
|
|
|
#include "SnakeGame.h"
|
2021-08-26 21:19:41 -03:00
|
|
|
#include <LibConfig/Client.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2020-10-31 18:58:52 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Menu.h>
|
2021-04-13 11:18:20 -03:00
|
|
|
#include <LibGUI/Menubar.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Window.h>
|
2020-01-12 08:29:40 -03:00
|
|
|
#include <stdio.h>
|
2021-03-12 13:29:37 -03:00
|
|
|
#include <unistd.h>
|
2019-04-19 20:54:10 -03:00
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2021-08-27 10:46:35 -03:00
|
|
|
if (pledge("stdio rpath recvfd sendfd unix", nullptr) < 0) {
|
2020-01-12 08:29:40 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 09:05:19 -03:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2020-01-12 08:29:40 -03:00
|
|
|
|
2021-08-26 21:19:41 -03:00
|
|
|
Config::pledge_domains("Snake");
|
|
|
|
|
|
2021-08-27 10:46:35 -03:00
|
|
|
if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) {
|
2020-01-12 08:29:40 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2019-04-19 20:54:10 -03:00
|
|
|
|
2020-11-01 17:16:45 -03:00
|
|
|
if (unveil("/res", "r") < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unveil(nullptr, nullptr) < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 18:58:52 -03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-snake");
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
auto window = GUI::Window::construct();
|
2019-07-23 13:20:00 -03:00
|
|
|
|
2019-04-20 14:51:10 -03:00
|
|
|
window->set_double_buffering_enabled(false);
|
2019-04-19 20:54:10 -03:00
|
|
|
window->set_title("Snake");
|
2021-05-04 12:02:36 -03:00
|
|
|
window->resize(324, 344);
|
2019-04-19 20:54:10 -03:00
|
|
|
|
2020-03-04 05:46:23 -03:00
|
|
|
auto& game = window->set_main_widget<SnakeGame>();
|
2019-04-19 20:54:10 -03:00
|
|
|
|
2021-07-21 16:21:03 -03:00
|
|
|
auto& game_menu = window->add_menu("&Game");
|
2019-08-27 08:25:08 -03:00
|
|
|
|
2021-05-01 05:45:39 -03:00
|
|
|
game_menu.add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, [&](auto&) {
|
2020-03-04 05:46:23 -03:00
|
|
|
game.reset();
|
2019-08-27 08:25:08 -03:00
|
|
|
}));
|
2021-05-01 05:45:39 -03:00
|
|
|
game_menu.add_separator();
|
|
|
|
|
game_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
2020-07-04 11:52:01 -03:00
|
|
|
GUI::Application::the()->quit();
|
2019-04-19 20:54:10 -03:00
|
|
|
}));
|
|
|
|
|
|
2021-07-21 16:21:03 -03:00
|
|
|
auto& help_menu = window->add_menu("&Help");
|
2021-01-04 19:51:49 -03:00
|
|
|
help_menu.add_action(GUI::CommonActions::make_about_action("Snake", app_icon, window));
|
2019-04-19 20:54:10 -03:00
|
|
|
|
|
|
|
|
window->show();
|
|
|
|
|
|
2020-10-31 18:58:52 -03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2019-04-19 20:54:10 -03:00
|
|
|
|
2020-07-04 09:05:19 -03:00
|
|
|
return app->exec();
|
2019-04-19 20:54:10 -03:00
|
|
|
}
|