diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-20 01:54:10 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-20 01:54:10 +0200 |
commit | eca9494adfcdd0acb6a27172053195b0c4c8ec09 (patch) | |
tree | 2a07b2caa266fe3f1764232c939ae8946fb8bf73 /Games/Snake | |
parent | 54af44e354b78eb0669e9a1ca3f943868a10a112 (diff) | |
download | serenity-eca9494adfcdd0acb6a27172053195b0c4c8ec09.zip |
Snake: Import skeleton of a new snake game.
Diffstat (limited to 'Games/Snake')
-rw-r--r-- | Games/Snake/.gitignore | 4 | ||||
-rw-r--r-- | Games/Snake/Makefile | 32 | ||||
-rw-r--r-- | Games/Snake/SnakeGame.cpp | 0 | ||||
-rw-r--r-- | Games/Snake/SnakeGame.h | 11 | ||||
-rw-r--r-- | Games/Snake/main.cpp | 52 |
5 files changed, 99 insertions, 0 deletions
diff --git a/Games/Snake/.gitignore b/Games/Snake/.gitignore new file mode 100644 index 0000000000..69c704ac03 --- /dev/null +++ b/Games/Snake/.gitignore @@ -0,0 +1,4 @@ +*.o +*.d +Snake +*.autosave diff --git a/Games/Snake/Makefile b/Games/Snake/Makefile new file mode 100644 index 0000000000..a68bd0fa5b --- /dev/null +++ b/Games/Snake/Makefile @@ -0,0 +1,32 @@ +OBJS = \ + SnakeGame.o \ + main.o + +APP = Snake + +STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation +WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough +FLAVOR_FLAGS = -fno-exceptions -fno-rtti +OPTIMIZATION_FLAGS = -Os +INCLUDE_FLAGS = -I../.. -I. -I../../LibC + +DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND + +CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(FLAVOR_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) +CXX = i686-pc-serenity-g++ +LD = i686-pc-serenity-g++ +LDFLAGS = -L../../LibC -L../../LibCore -L../../LibGUI + +all: $(APP) + +$(APP): $(OBJS) + $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -lcore -lc + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJS:%.o=%.d) + +clean: + @echo "CLEAN"; rm -f $(APPS) $(OBJS) *.d + diff --git a/Games/Snake/SnakeGame.cpp b/Games/Snake/SnakeGame.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/Games/Snake/SnakeGame.cpp diff --git a/Games/Snake/SnakeGame.h b/Games/Snake/SnakeGame.h new file mode 100644 index 0000000000..01e13aabbf --- /dev/null +++ b/Games/Snake/SnakeGame.h @@ -0,0 +1,11 @@ +#pragma once + +#include <LibGUI/GWidget.h> + +class SnakeGame : public GWidget { +public: + explicit SnakeGame(GWidget* parent); + +private: + virtual void paint_event(GPaintEvent&) override; +}; diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp new file mode 100644 index 0000000000..6443761bfa --- /dev/null +++ b/Games/Snake/main.cpp @@ -0,0 +1,52 @@ +#include "SnakeGame.h" +#include <LibGUI/GApplication.h> +#include <LibGUI/GWindow.h> +#include <LibGUI/GBoxLayout.h> +#include <LibGUI/GButton.h> +#include <LibGUI/GMenu.h> +#include <LibGUI/GMenuBar.h> +#include <LibGUI/GAction.h> + +int main(int argc, char** argv) +{ + GApplication app(argc, argv); + + auto* window = new GWindow; + window->set_title("Snake"); + window->set_rect(100, 100, 139, 175); + + auto* widget = new GWidget; + window->set_main_widget(widget); + widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); + + auto* game = new SnakeGame(widget); + + auto menubar = make<GMenuBar>(); + + auto app_menu = make<GMenu>("Snake"); + app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) { + GApplication::the().quit(0); + return; + })); + menubar->add_menu(move(app_menu)); + + auto game_menu = make<GMenu>("Game"); + game_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&] (const GAction&) { + game->reset(); + })); + menubar->add_menu(move(game_menu)); + + auto help_menu = make<GMenu>("Help"); + help_menu->add_action(GAction::create("About", [] (const GAction&) { + dbgprintf("FIXME: Implement Help/About\n"); + })); + menubar->add_menu(move(help_menu)); + + app.set_menubar(move(menubar)); + + window->show(); + + window->set_icon_path("/res/icons/minesweeper/mine.png"); + + return app.exec(); +} |