Browse Source

Initial Commit

Roman Hergenreder 5 years ago
commit
67975b5095
9 changed files with 161 additions and 0 deletions
  1. 38 0
      Makefile
  2. 24 0
      src/Field.cpp
  3. 38 0
      src/Field.h
  4. BIN
      src/Field.h.gch
  5. 39 0
      src/Piece.h
  6. BIN
      src/Piece.h.gch
  7. 6 0
      src/pieces/Pawn.cpp
  8. 16 0
      src/pieces/Pawn.h
  9. BIN
      src/pieces/Pawn.h.gch

+ 38 - 0
Makefile

@@ -0,0 +1,38 @@
+CC=gcc
+CXX=g++
+CFLAGS := -c -Wall -Wextra -std=c++11
+SRC_DIR := ./src
+OBJ_DIR := ./obj
+INCLUDE := -I./src
+MKDIR_P := mkdir -p
+SRC_FILES := $(shell find $(SRC_DIR) -name '*.cpp')
+OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(SRC_FILES:$(SRC_DIR)/%.cpp=%.o))
+
+chess: $(OBJ_FILES)
+	$(CXX) $(LDFLAGS) -o $@ $^
+
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
+	$(CXX) $(CFLAGS) -c -o $@ $<
+
+# test:
+# 	echo $(SRC_FILES)
+#
+# all: compile link
+#
+# compile: build $(SRC_FILES)
+#
+# build: $(SRC_FILES)
+# 	echo $@
+# 	$(CXX) $(CFLAGS) $(INCLUDE) -o $@ $<
+#
+# $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
+# 	${MKDIR_P} $(dir $@)
+# 	$(CXX) $(CFLAGS) -o $@ $(OBJ_FILES)
+
+link:
+	${CXX} -o chess ${CFLAGS} ${OBJ_FILES} ${LDFLAGS} ${LDLIBS}
+
+clean:
+	rm -rf ./obj/*.o
+	rm -rf ./obj/**/*.o
+	rm -f ./chess

+ 24 - 0
src/Field.cpp

@@ -0,0 +1,24 @@
+#include "Field.h"
+
+#include "pieces/Pawn.h"
+
+CField::CField() {
+  reset();
+}
+
+void CField::reset() {
+  for(unsigned int x = 0; x < 8; x++) {
+    for(unsigned int y = 0; y < 8; y++) {
+      if(y == 1)
+        pieces[x][y] = new CPawn(CPiece::Color::WHITE);
+      else if(y == 2)
+        pieces[x][y] = new CPawn(CPiece::Color::BLACK);
+    }
+  }
+}
+
+
+int main(int argc, char *argv[]) {
+  CField field;
+  cout << field;
+}

+ 38 - 0
src/Field.h

@@ -0,0 +1,38 @@
+#ifndef FIELD_H
+#define FIELD_H
+
+#include <iostream>
+
+using namespace std;
+
+class CField {
+
+  class CPiece *pieces[8][8];
+
+public:
+
+  CField();
+  ~CField() { }
+
+  void reset();
+
+  friend ostream& operator<<(ostream &os, const CField &piece) {
+    os << "  ";
+    for(unsigned int y = 0; y < 8; y++)
+      os << "  " << (char)((int)'A' + y);
+    os << endl;
+
+    for(unsigned int y = 0; y < 8; y++) {
+      os << " " << y;
+      for(unsigned int x = 0; x < 8; x++) {
+        os << "  " << (piece.pieces[x][y] != nullptr) ? piece.pieces[x][y]->m_Icon : " ";
+      }
+      os << endl;
+    }
+
+    return os;
+  }
+
+};
+
+#endif

BIN
src/Field.h.gch


+ 39 - 0
src/Piece.h

@@ -0,0 +1,39 @@
+#ifndef PIECE_H
+#define PIECE_H
+
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+class CPiece {
+
+public:
+
+  enum Color {
+    WHITE = 0,
+    BLACK
+  };
+
+private:
+
+  string m_Icon;
+  int m_Color;
+
+public:
+
+  CPiece(string icon, int color) {
+    m_Icon = icon;
+    m_Color = color;
+  }
+
+  ~CPiece() { }
+
+  friend ostream &operator<<(ostream &os, const CPiece &piece) {
+    cout << "Printing" << endl;
+    return os << piece.m_Icon;
+  }
+
+};
+
+#endif

BIN
src/Piece.h.gch


+ 6 - 0
src/pieces/Pawn.cpp

@@ -0,0 +1,6 @@
+#include "Pawn.h"
+
+CPawn::CPawn(int color)
+  : CPiece((color == Color::WHITE ? "♙" : "♟"), color) {
+    hasMoved = false;
+}

+ 16 - 0
src/pieces/Pawn.h

@@ -0,0 +1,16 @@
+#ifndef PIECE_PAWN_H
+#define PIECE_PAWN_H
+
+#include "../Piece.h"
+
+class CPawn : public CPiece {
+
+  bool hasMoved;
+
+public:
+
+  CPawn(int color);
+  ~CPawn() { }
+};
+
+#endif

BIN
src/pieces/Pawn.h.gch