From 9c0acb89b98ccea49e9c5e522b39490c8cb28c0e Mon Sep 17 00:00:00 2001 From: AdmiralEmser Date: Sun, 9 Oct 2022 17:13:41 +0200 Subject: [PATCH] added: first text templates, first checks for piece movement, Information: There is no tui.h since MSVC doesn't find the code in there... for some unexplainable reason... Check FC-Chess.h -> FCC::TUI for further information. --- .gitignore | 3 +- CMakePresets.json | 101 -------------------- FC-Chess/CMakeLists.txt | 2 +- FC-Chess/FC-Chess.cpp | 65 +++++++++++-- FC-Chess/FC-Chess.h | 51 ++++++++-- FC-Chess/_unused_and_old/_graphics.h | 20 ++++ FC-Chess/{ => _unused_and_old}/graphics.cpp | 12 ++- FC-Chess/_unused_and_old/graphics.h | 18 ++++ FC-Chess/_unused_and_old/lang.cpp | 6 ++ FC-Chess/_unused_and_old/lang.h | 22 +++++ FC-Chess/_unused_and_old/tui.h | 18 ++++ FC-Chess/graphics.h | 14 --- FC-Chess/lang.h | 20 ++++ FC-Chess/main.cpp | 8 +- FC-Chess/tui.cpp | 19 ++++ 15 files changed, 241 insertions(+), 138 deletions(-) delete mode 100644 CMakePresets.json create mode 100644 FC-Chess/_unused_and_old/_graphics.h rename FC-Chess/{ => _unused_and_old}/graphics.cpp (55%) create mode 100644 FC-Chess/_unused_and_old/graphics.h create mode 100644 FC-Chess/_unused_and_old/lang.cpp create mode 100644 FC-Chess/_unused_and_old/lang.h create mode 100644 FC-Chess/_unused_and_old/tui.h delete mode 100644 FC-Chess/graphics.h create mode 100644 FC-Chess/lang.h create mode 100644 FC-Chess/tui.cpp diff --git a/.gitignore b/.gitignore index de367d6..a41222e 100644 --- a/.gitignore +++ b/.gitignore @@ -351,4 +351,5 @@ MigrationBackup/ # own out/ -.vscode/ \ No newline at end of file +.vscode/ +build/ \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json deleted file mode 100644 index f4bc98b..0000000 --- a/CMakePresets.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "windows-base", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - }, - { - "name": "x64-debug", - "displayName": "x64 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x64", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x64-release", - "displayName": "x64 Release", - "inherits": "x64-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "x86-debug", - "displayName": "x86 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x86", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x86-release", - "displayName": "x86 Release", - "inherits": "x86-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "linux-debug", - "displayName": "Linux Debug", - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "vendor": { - "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { - "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" - } - } - }, - { - "name": "macos-debug", - "displayName": "macOS Debug", - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, - "vendor": { - "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { - "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" - } - } - } - ] -} diff --git a/FC-Chess/CMakeLists.txt b/FC-Chess/CMakeLists.txt index a6486b3..1df0288 100644 --- a/FC-Chess/CMakeLists.txt +++ b/FC-Chess/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required (VERSION 3.8) # Add source to this project's executable. -add_executable (FC-Chess "main.cpp" "fc-chess.cpp" "graphics.cpp") +add_executable (FC-Chess "main.cpp" "FC-Chess.cpp" "tui.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET FC-Chess PROPERTY CXX_STANDARD 20) diff --git a/FC-Chess/FC-Chess.cpp b/FC-Chess/FC-Chess.cpp index 8c5cb6b..b803252 100644 --- a/FC-Chess/FC-Chess.cpp +++ b/FC-Chess/FC-Chess.cpp @@ -1,9 +1,29 @@ -#include "fc-chess.h" +#include "FC-Chess.h" + +FCC::Chess::Chess() +{ + + //start game + FCC::Chess::startup(); + FCC::Chess::mainLoop(); +} void FCC::Chess::mainLoop() { - FCC::ChessTUI tui; + // initialize user interface + + // tui.startup(); + // main loop + while(!gameEnded) + { + /*MISSING: user input*/ + // tui.mainLoop(); + } +} + +void FCC::Chess::startup() +{ // preparing board: colors for (int8_t i = 0; i < 8; i++) { for (int j = 0; i < 2; i++) { @@ -32,11 +52,40 @@ void FCC::Chess::mainLoop() posPieces[i][4] = (uint8_t)(Pieces::QUEEN); } - // main loop - while(!gameEnded) { + // set language to English (default) + // m_lang = FCC::Languages::ENGLISH; +} - tui.mainLoop(); +bool FCC::Chess::checkIsEnemyOnField() +{ + // Check if the selected piece/field unequals the target piece/field => is true then + if (posColor[selX][selY] != posColor[tarX][tarY]) + { + return true; } - - -} \ No newline at end of file + return false; +} + +bool FCC::Chess::checkSelectedPosInBounds() +{ + // check if X and Y values are below 8. No negative values have to be checked since the var type is unsigned int + if (selX <= 7 && selX <= 7) + { + return true; + } + return false; +} + +bool FCC::Chess::checkTargetPosInBounds() +{ + // check if X and Y values are below 8. No negative values have to be checked since the var type is unsigned int + if (tarX <= 7 && tarX <= 7) + { + return true; + } + return false; +} + +//void FCC::Chess::set_lang(FCC::Languages lang) { +// m_lang = lang; +//} diff --git a/FC-Chess/FC-Chess.h b/FC-Chess/FC-Chess.h index e2452b8..b48835a 100644 --- a/FC-Chess/FC-Chess.h +++ b/FC-Chess/FC-Chess.h @@ -1,7 +1,7 @@ #pragma once -#include - -#include "graphics.h" +//#include +// #include "tui.h" +#include "lang.h" namespace FCC { @@ -20,21 +20,58 @@ namespace FCC BLACK = 10, WHITE = 20 }; - + // classes and funcs + class TUI + { + /* Why is FCC::TUI here and not in tui.h, so another file? Well, that's quite easy. MSVC doesn't know how to access code from other files, apparently. + Error code is that class FCC::TUI wouldn't be a member of namespace FCC - which is a wrong statement. It is a member of FCC. + So yeah, thanks Microsoft.*/ + + public: + // constructor and destructor + TUI() = default; + virtual ~TUI() = default; + + // funcs + void startup(); + void mainLoop(); + void testLoop(); + }; + class Chess { public: // constructor and destructor - Chess() = default; - ~Chess() = default; + Chess(); + virtual ~Chess() = default; // vars - uint8_t posPieces[8][8], posColor[8][8], posPossible[8][8]; + uint8_t posPieces[8][8], posColor[8][8], posPossible[8][8], selX, selY, tarX, tarY; //tar = target, sel = selected, pos = possible // funcs + void startup(); void mainLoop(); + void checkHorizontalMovementAllowed(); + void checkVerticalMovementAllowed(); + void checkDiagonalMovementAllowed(); + //void set_lang(FCC::Languages lang); + private: + // vars bool gameEnded; + + // texts for tui and gui + FCC::Lang lang; + FCC::TUI tui; + //FCC::ChessLang chessLangObj; + //FCC::Languages m_lang{ FCC::Languages::ENGLISH }; + + // funcs + void input(); + bool checkIsEnemyOnField(); + bool checkSelectedPosInBounds(); + bool checkTargetPosInBounds(); + void resetFieldColors(); }; } diff --git a/FC-Chess/_unused_and_old/_graphics.h b/FC-Chess/_unused_and_old/_graphics.h new file mode 100644 index 0000000..d02d9e7 --- /dev/null +++ b/FC-Chess/_unused_and_old/_graphics.h @@ -0,0 +1,20 @@ +#pragma once +#include + +#include "FC-Chess.h" + +namespace FCC +{ + class TUI + { + public: + // constructor and destructor + TUI() = default; + virtual ~TUI() = default; + + // funcs + void startup(); + void mainLoop(); + void testLoop(); + }; +} diff --git a/FC-Chess/graphics.cpp b/FC-Chess/_unused_and_old/graphics.cpp similarity index 55% rename from FC-Chess/graphics.cpp rename to FC-Chess/_unused_and_old/graphics.cpp index 9955f23..f0add7f 100644 --- a/FC-Chess/graphics.cpp +++ b/FC-Chess/_unused_and_old/graphics.cpp @@ -1,10 +1,18 @@ #include "graphics.h" +// #include "FC-Chess.h" -void FCC::ChessTUI::mainLoop() { +void FCC::TUI::startup() +{ + +} + +void FCC::TUI::mainLoop() +{ } -void FCC::ChessTUI::testLoop() { +void FCC::TUI::testLoop() +{ std::cout << "\u2654" << std::endl; std::cout << "♔" << std::endl; //std::cout << L"♔"; diff --git a/FC-Chess/_unused_and_old/graphics.h b/FC-Chess/_unused_and_old/graphics.h new file mode 100644 index 0000000..c7142a6 --- /dev/null +++ b/FC-Chess/_unused_and_old/graphics.h @@ -0,0 +1,18 @@ +#pragma once +#include "FC-Chess.h" + +namespace FCC +{ + class TUI + { + public: + // constructor and destructor + TUI() = default; + virtual ~TUI() = default; + + // funcs + void startup(); + void mainLoop(); + void testLoop(); + }; +} \ No newline at end of file diff --git a/FC-Chess/_unused_and_old/lang.cpp b/FC-Chess/_unused_and_old/lang.cpp new file mode 100644 index 0000000..44714f6 --- /dev/null +++ b/FC-Chess/_unused_and_old/lang.cpp @@ -0,0 +1,6 @@ +#include "lang.h" + +void FCC::ChessLang::setLanguage(uint8_t setLangTo) +{ + language = setLangTo; +} \ No newline at end of file diff --git a/FC-Chess/_unused_and_old/lang.h b/FC-Chess/_unused_and_old/lang.h new file mode 100644 index 0000000..d71b7c3 --- /dev/null +++ b/FC-Chess/_unused_and_old/lang.h @@ -0,0 +1,22 @@ +#pragma once +#include +//#include "FC-Chess.h" +#include + +namespace FCC { + enum class Languages { + ENGLISH, + GERMAN + }; +} +namespace FCC::ChessLang +{ + inline std::string testString(FCC::Languages lang) { + switch (lang) { + case FCC::Languages::ENGLISH: + return "Hello World"; + case FCC::Languages::GERMAN: + return "Hallo Welt"; + } + } +} \ No newline at end of file diff --git a/FC-Chess/_unused_and_old/tui.h b/FC-Chess/_unused_and_old/tui.h new file mode 100644 index 0000000..c7142a6 --- /dev/null +++ b/FC-Chess/_unused_and_old/tui.h @@ -0,0 +1,18 @@ +#pragma once +#include "FC-Chess.h" + +namespace FCC +{ + class TUI + { + public: + // constructor and destructor + TUI() = default; + virtual ~TUI() = default; + + // funcs + void startup(); + void mainLoop(); + void testLoop(); + }; +} \ No newline at end of file diff --git a/FC-Chess/graphics.h b/FC-Chess/graphics.h deleted file mode 100644 index 9a5b3da..0000000 --- a/FC-Chess/graphics.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include - -#include "FC-Chess.h" - -namespace FCC -{ - class ChessTUI - { - public: - void mainLoop(); - void testLoop(); - }; -} \ No newline at end of file diff --git a/FC-Chess/lang.h b/FC-Chess/lang.h new file mode 100644 index 0000000..26945a9 --- /dev/null +++ b/FC-Chess/lang.h @@ -0,0 +1,20 @@ +#pragma once +#include +#include + +namespace FCC +{ + class Lang + { + public: + // texts shown in gui/tui + std::string menuButtonPlay = "Start Game!"; + std::string menuButtonSettings = "Settings"; + std::string menuButtonCredits = "Credits"; + std::string menuButtonExitGame = "Exit to Desktop"; + std::string error = "An error occoured. The game will exit now."; + std::string gameForbiddenMove = "This move is not allowed."; + std::string credits = "FoxCreation Chess by SinusFox 2022.\nContact: admiralemser@gmail.com\nhttps://github.com/AdmiralEmser/FC-Chess"; + std::string backButton = "Back <--"; + }; +} \ No newline at end of file diff --git a/FC-Chess/main.cpp b/FC-Chess/main.cpp index b699344..c41f80f 100644 --- a/FC-Chess/main.cpp +++ b/FC-Chess/main.cpp @@ -1,17 +1,17 @@ // FC-Chess.cpp : Defines the entry point for the application. // -#include "fc-chess.h" +#include "FC-Chess.h" //using namespace std; int main() { FCC::Chess gm; - gm.mainLoop(); + - FCC::ChessTUI test; - test.testLoop(); + // FCC::TUI test; + // test.testLoop(); return 0; } diff --git a/FC-Chess/tui.cpp b/FC-Chess/tui.cpp new file mode 100644 index 0000000..1c78e81 --- /dev/null +++ b/FC-Chess/tui.cpp @@ -0,0 +1,19 @@ +// #include "tui.h" +#include "FC-Chess.h" + +void FCC::TUI::startup() +{ + +} + +void FCC::TUI::mainLoop() +{ + +} + +void FCC::TUI::testLoop() +{ + std::cout << "\u2654" << std::endl; + std::cout << "♔" << std::endl; + //std::cout << L"♔"; +} \ No newline at end of file