summaryrefslogtreecommitdiff
path: root/Games/Snake
diff options
context:
space:
mode:
Diffstat (limited to 'Games/Snake')
-rw-r--r--Games/Snake/.gitignore4
-rw-r--r--Games/Snake/Makefile32
-rw-r--r--Games/Snake/SnakeGame.cpp0
-rw-r--r--Games/Snake/SnakeGame.h11
-rw-r--r--Games/Snake/main.cpp52
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();
+}