Browse Source

restructure and use cmake

master
Constantin Fürst 8 months ago
parent
commit
ba020ac3ba
  1. 1
      .gitignore
  2. 22
      CMakeLists.txt
  3. 24
      Makefile
  4. 4
      bin/.gitignore
  5. 5
      build-and-run.sh
  6. 0
      components/Point.cpp
  7. 2
      components/Point.h
  8. 0
      components/Snack.cpp
  9. 0
      components/Snack.h
  10. 0
      components/Snake.cpp
  11. 6
      components/Snake.h
  12. 0
      game/Controller.cpp
  13. 5
      game/Controller.h
  14. 0
      game/Game.cpp
  15. 9
      game/Game.h
  16. 0
      input-output/Graphics.cpp
  17. 4
      input-output/Graphics.h
  18. 0
      input-output/Player.cpp
  19. 4
      input-output/Player.h
  20. 5
      main.cpp

1
.gitignore

@ -31,3 +31,4 @@
*.out
*.app
*.vscode
build

22
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})

24
Makefile

@ -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)/*

4
bin/.gitignore

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

5
build-and-run.sh

@ -0,0 +1,5 @@
mkdir build
cd build
cmake ..
make
./snake

0
src/PointClassImpl.cpp → components/Point.cpp

2
include/Point.h → components/Point.h

@ -1,6 +1,6 @@
#pragma once
#include "Graphics.h"
#include "../input-output/Graphics.h"
class Point{
private:

0
src/Snack.cpp → components/Snack.cpp

0
include/Snack.h → components/Snack.h

0
src/SnakeImpl.cpp → components/Snake.cpp

6
include/Snake.h → components/Snake.h

@ -1,10 +1,10 @@
#pragma once
#include <list>
#include "Point.h" //the library we need to implement the snake
#include "Point.h"
#include "Snack.h"
#include <list>
#define BODY 'o'
class Snake{
private:

0
src/Controller.cpp → game/Controller.cpp

5
include/Controller.h → 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

0
src/Game.cpp → game/Game.cpp

9
include/Game.h → game/Game.h

@ -1,10 +1,11 @@
#pragma once
//This class will be the abstract Game Interface
#include <string>
#include "Controller.h"
#include "Snake.h"
#include "Player.h"
#include "../components/Snake.h"
#include "../input-output/Player.h"
#include <string>
class SnakeGame{
private:
std::string gameName;

0
src/Graphics.cpp → input-output/Graphics.cpp

4
include/Graphics.h → input-output/Graphics.h

@ -1,13 +1,13 @@
#pragma once
#include <curses.h> //include library for terminal graphics
#include <curses.h>
#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

0
src/Player.cpp → input-output/Player.cpp

4
include/Player.h → input-output/Player.h

@ -1,14 +1,16 @@
#pragma once
#include "../game/Controller.h"
#include <iostream>
#include <string>
#include "Controller.h"
class Player{
private:
std::string name;
unsigned int points;
unsigned int timesPlayed;
public:
Player();
Player(std::string _name);

5
src/main.cpp → main.cpp

@ -1,12 +1,11 @@
#include <ncurses.h>
#include <iostream>
#include "Game.h"
using namespace std;
#include "game/Game.h"
int main() {
SnakeGame game;
game.play();
return 0;
}
Loading…
Cancel
Save