From ba020ac3baafbc223ea2f9ae094e329d7c07068d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20F=C3=BCrst?= Date: Mon, 29 Apr 2024 17:41:23 +0200 Subject: [PATCH] restructure and use cmake --- .gitignore | 1 + CMakeLists.txt | 22 +++++++++++++++++ Makefile | 24 ------------------- bin/.gitignore | 4 ---- build-and-run.sh | 5 ++++ .../Point.cpp | 0 {include => components}/Point.h | 2 +- {src => components}/Snack.cpp | 0 {include => components}/Snack.h | 0 src/SnakeImpl.cpp => components/Snake.cpp | 0 {include => components}/Snake.h | 6 ++--- {src => game}/Controller.cpp | 0 {include => game}/Controller.h | 5 ++-- {src => game}/Game.cpp | 0 {include => game}/Game.h | 9 +++---- {src => input-output}/Graphics.cpp | 0 {include => input-output}/Graphics.h | 4 ++-- {src => input-output}/Player.cpp | 0 {include => input-output}/Player.h | 4 +++- src/main.cpp => main.cpp | 5 ++-- 20 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 CMakeLists.txt delete mode 100755 Makefile delete mode 100644 bin/.gitignore create mode 100644 build-and-run.sh rename src/PointClassImpl.cpp => components/Point.cpp (100%) rename {include => components}/Point.h (91%) rename {src => components}/Snack.cpp (100%) rename {include => components}/Snack.h (100%) rename src/SnakeImpl.cpp => components/Snake.cpp (100%) rename {include => components}/Snake.h (94%) rename {src => game}/Controller.cpp (100%) rename {include => game}/Controller.h (85%) rename {src => game}/Game.cpp (100%) rename {include => game}/Game.h (86%) rename {src => input-output}/Graphics.cpp (100%) rename {include => input-output}/Graphics.h (76%) rename {src => input-output}/Player.cpp (100%) rename {include => input-output}/Player.h (91%) rename src/main.cpp => main.cpp (72%) diff --git a/.gitignore b/.gitignore index 1f1c1d3..4210ff2 100755 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ *.out *.app *.vscode +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..71eb1d2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8) +project(snake) + +find_package(Curses REQUIRED) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_BUILD_TYPE Debug) + +set(SOURCES + components/Point.cpp + components/Snack.cpp + components/Snake.cpp + game/Controller.cpp + game/Game.cpp + input-output/Graphics.cpp + input-output/Player.cpp + main.cpp +) + +include_directories(${CURSES_INCLUDE_DIR}) +add_executable(snake ${SOURCES}) +target_link_libraries(snake ${CURSES_LIBRARIES}) \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100755 index 0dc31d8..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -CXX := g++ -CXX_FLAGS := -Wall -Wextra -std=c++11 -ggdb - -BIN := bin -SRC := src -INCLUDE := include -LIB := lib - -LIBRARIES := -lncurses -EXECUTABLE := main - - -all: $(BIN)/$(EXECUTABLE) - -run: clean all - clear - ./$(BIN)/$(EXECUTABLE) - -$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp - $(CXX) $(CXX_FLAGS) -I$(INCLUDE) -L$(LIB) $^ -o $@ $(LIBRARIES) - -clean: - -rm $(BIN)/* - diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index 5e7d273..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/build-and-run.sh b/build-and-run.sh new file mode 100644 index 0000000..a4254cb --- /dev/null +++ b/build-and-run.sh @@ -0,0 +1,5 @@ +mkdir build +cd build +cmake .. +make +./snake \ No newline at end of file diff --git a/src/PointClassImpl.cpp b/components/Point.cpp similarity index 100% rename from src/PointClassImpl.cpp rename to components/Point.cpp diff --git a/include/Point.h b/components/Point.h similarity index 91% rename from include/Point.h rename to components/Point.h index bee87c3..e4f0105 100755 --- a/include/Point.h +++ b/components/Point.h @@ -1,6 +1,6 @@ #pragma once -#include "Graphics.h" +#include "../input-output/Graphics.h" class Point{ private: diff --git a/src/Snack.cpp b/components/Snack.cpp similarity index 100% rename from src/Snack.cpp rename to components/Snack.cpp diff --git a/include/Snack.h b/components/Snack.h similarity index 100% rename from include/Snack.h rename to components/Snack.h diff --git a/src/SnakeImpl.cpp b/components/Snake.cpp similarity index 100% rename from src/SnakeImpl.cpp rename to components/Snake.cpp diff --git a/include/Snake.h b/components/Snake.h similarity index 94% rename from include/Snake.h rename to components/Snake.h index e867da1..bbbb0a3 100755 --- a/include/Snake.h +++ b/components/Snake.h @@ -1,10 +1,10 @@ #pragma once -#include - -#include "Point.h" //the library we need to implement the snake +#include "Point.h" #include "Snack.h" +#include + #define BODY 'o' class Snake{ private: diff --git a/src/Controller.cpp b/game/Controller.cpp similarity index 100% rename from src/Controller.cpp rename to game/Controller.cpp diff --git a/include/Controller.h b/game/Controller.h similarity index 85% rename from include/Controller.h rename to game/Controller.h index c102abc..c72bf11 100755 --- a/include/Controller.h +++ b/game/Controller.h @@ -1,7 +1,8 @@ #pragma once -#include "Graphics.h" -#include "Snake.h" +#include "../input-output/Graphics.h" +#include "../components/Snake.h" +#include "../components/Point.h" #define DEFEAT -1 diff --git a/src/Game.cpp b/game/Game.cpp similarity index 100% rename from src/Game.cpp rename to game/Game.cpp diff --git a/include/Game.h b/game/Game.h similarity index 86% rename from include/Game.h rename to game/Game.h index 08dc6e4..9cb673e 100755 --- a/include/Game.h +++ b/game/Game.h @@ -1,10 +1,11 @@ #pragma once -//This class will be the abstract Game Interface -#include #include "Controller.h" -#include "Snake.h" -#include "Player.h" +#include "../components/Snake.h" +#include "../input-output/Player.h" + +#include + class SnakeGame{ private: std::string gameName; diff --git a/src/Graphics.cpp b/input-output/Graphics.cpp similarity index 100% rename from src/Graphics.cpp rename to input-output/Graphics.cpp diff --git a/include/Graphics.h b/input-output/Graphics.h similarity index 76% rename from include/Graphics.h rename to input-output/Graphics.h index 4833d46..129c1d1 100755 --- a/include/Graphics.h +++ b/input-output/Graphics.h @@ -1,13 +1,13 @@ #pragma once -#include //include library for terminal graphics +#include #define UP KEY_UP #define DOWN KEY_DOWN #define LEFT KEY_LEFT #define RIGHT KEY_RIGHT #define EXIT_GAME 'q' -typedef int graphics_input; //the type of the graphics input +typedef int graphics_input; #define GAME_TOP_WALL_Y 1 diff --git a/src/Player.cpp b/input-output/Player.cpp similarity index 100% rename from src/Player.cpp rename to input-output/Player.cpp diff --git a/include/Player.h b/input-output/Player.h similarity index 91% rename from include/Player.h rename to input-output/Player.h index e03e3b2..481c496 100755 --- a/include/Player.h +++ b/input-output/Player.h @@ -1,14 +1,16 @@ #pragma once +#include "../game/Controller.h" + #include #include -#include "Controller.h" class Player{ private: std::string name; unsigned int points; unsigned int timesPlayed; + public: Player(); Player(std::string _name); diff --git a/src/main.cpp b/main.cpp similarity index 72% rename from src/main.cpp rename to main.cpp index 3f852d2..c89ada5 100755 --- a/src/main.cpp +++ b/main.cpp @@ -1,12 +1,11 @@ #include #include -#include "Game.h" -using namespace std; + +#include "game/Game.h" int main() { SnakeGame game; game.play(); return 0; - } \ No newline at end of file