Merge pull request #3 from AdmiralEmser/dev
Major merge request. Please check each commit for details.
This commit is contained in:
+2
-1
@@ -351,4 +351,5 @@ MigrationBackup/
|
|||||||
|
|
||||||
# own
|
# own
|
||||||
out/
|
out/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
build/
|
||||||
@@ -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}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
cmake_minimum_required (VERSION 3.8)
|
cmake_minimum_required (VERSION 3.8)
|
||||||
|
|
||||||
# Add source to this project's executable.
|
# 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)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET FC-Chess PROPERTY CXX_STANDARD 20)
|
set_property(TARGET FC-Chess PROPERTY CXX_STANDARD 20)
|
||||||
|
|||||||
+117
-23
@@ -1,42 +1,136 @@
|
|||||||
#include "fc-chess.h"
|
#include "FC-Chess.h"
|
||||||
|
|
||||||
void FCC::Chess::mainLoop()
|
FCC::Chess::Chess()
|
||||||
{
|
{
|
||||||
FCC::ChessTUI tui;
|
// initialize user interface
|
||||||
|
tui.startup();
|
||||||
|
|
||||||
|
//start game
|
||||||
|
FCC::Chess::mainMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::Chess::mainMenu()
|
||||||
|
{
|
||||||
|
/* TO DO
|
||||||
|
- Add options
|
||||||
|
- call FCC::Chess::GameLoop when game begins */
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::Chess::gameLoop()
|
||||||
|
{
|
||||||
|
// initialize board
|
||||||
|
FCC::Chess::startupGame();
|
||||||
|
|
||||||
|
// main loop
|
||||||
|
while(!gameEnded)
|
||||||
|
{
|
||||||
|
/* To Do: user input */
|
||||||
|
tui.mainLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::Chess::startupGame()
|
||||||
|
{
|
||||||
// preparing board: colors
|
// preparing board: colors
|
||||||
for (int8_t i = 0; i < 8; i++) {
|
for (int8_t i = 0; i < 8; i++) {
|
||||||
for (int j = 0; i < 2; i++) {
|
for (int j = 0; i < 2; i++) {
|
||||||
posColor[i][j] = (uint8_t)(PiecesColors::BLACK);
|
posColor[i][j] = PiecesColors::BLACK;
|
||||||
}
|
}
|
||||||
for (int j = 6; i < 8; i++) {
|
for (int j = 6; i < 8; i++) {
|
||||||
posColor[i][j] = (uint8_t)(PiecesColors::WHITE);
|
posColor[i][j] = PiecesColors::WHITE;
|
||||||
}
|
}
|
||||||
for (int j = 2; i < 7; i++) {
|
for (int j = 2; i < 7; i++) {
|
||||||
posColor[i][j] = (uint8_t)(PiecesColors::NONE);
|
posColor[i][j] = PiecesColors::NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// preparing board: pieces
|
// preparing board: pieces
|
||||||
for (int8_t i = 0; i < 8; i++) {
|
for (int8_t i = 0; i < 8; i++) {
|
||||||
posPieces[1][i] = (uint8_t)(Pieces::PAWN);
|
posPieces[1][i] = Pieces::PAWN;
|
||||||
posPieces[6][i] = (uint8_t)(Pieces::PAWN);
|
posPieces[6][i] = Pieces::PAWN;
|
||||||
}
|
}
|
||||||
for (int8_t i = 0; i < 2; i++) {
|
for (int8_t i = 0; i < 2; i++) {
|
||||||
posPieces[i][0] = (uint8_t)(Pieces::ROOK);
|
posPieces[i][0] = Pieces::ROOK;
|
||||||
posPieces[i][7] = (uint8_t)(Pieces::ROOK);
|
posPieces[i][7] = Pieces::ROOK;
|
||||||
posPieces[i][1] = (uint8_t)(Pieces::KNIGHT);
|
posPieces[i][1] = Pieces::KNIGHT;
|
||||||
posPieces[i][6] = (uint8_t)(Pieces::KNIGHT);
|
posPieces[i][6] = Pieces::KNIGHT;
|
||||||
posPieces[i][2] = (uint8_t)(Pieces::BISHOP);
|
posPieces[i][2] = Pieces::BISHOP;
|
||||||
posPieces[i][5] = (uint8_t)(Pieces::BISHOP);
|
posPieces[i][5] = Pieces::BISHOP;
|
||||||
posPieces[i][3] = (uint8_t)(Pieces::KING);
|
posPieces[i][3] = Pieces::KING;
|
||||||
posPieces[i][4] = (uint8_t)(Pieces::QUEEN);
|
posPieces[i][4] = Pieces::QUEEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FCC::Chess::checkIsEnemyOnField(uint8_t* x, uint8_t* y)
|
||||||
|
{
|
||||||
|
// Check if the selected piece/field unequals the target piece/field => is true then
|
||||||
|
if (posColor[*x][*y] != posColor[selX][selY])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FCC::Chess::checkPosInBounds(uint8_t* x, uint8_t* y)
|
||||||
|
{
|
||||||
|
// check if X and Y values are below 8. No negative values have to be checked since the var type is unsigned int
|
||||||
|
if (*x <= 7 && *y <= 7)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::Chess::checkAllowedMoves()
|
||||||
|
{
|
||||||
|
// reset all allowed positions
|
||||||
|
for (uint8_t i = 0; i <= 7; i++)
|
||||||
|
{
|
||||||
|
for (uint8_t j = 0; j <= 7; j++)
|
||||||
|
{
|
||||||
|
posPossible[i][j] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// main loop
|
// check piece and then check possible moves accordingly
|
||||||
while(!gameEnded) {
|
switch (FCC::Chess::posPieces[FCC::Chess::selX][FCC::Chess::selY]) {
|
||||||
|
case FCC::Pieces::PAWN:
|
||||||
tui.mainLoop();
|
break;
|
||||||
|
case FCC::Pieces::ROOK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tui.errOutput(&lang.errNoPieceOnPosition);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
void FCC::Chess::checkMovesHorizontal()
|
||||||
|
{
|
||||||
|
for (uint8_t i = selX; i <= 7; i++)
|
||||||
|
{
|
||||||
|
if (checkIsEnemyOnField(&i, &selY)) break;
|
||||||
|
posPossible[i][selY] = true;
|
||||||
|
}
|
||||||
|
for (uint8_t i = selX; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (checkIsEnemyOnField(&i, &selY)) break;
|
||||||
|
posPossible[i][selY] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::Chess::checkMovesVertical()
|
||||||
|
{
|
||||||
|
for (uint8_t i = selY; i <= 7; i++)
|
||||||
|
{
|
||||||
|
if (checkIsEnemyOnField(&selX, &i)) break;
|
||||||
|
posPossible[selX][i] = true;
|
||||||
|
}
|
||||||
|
for (uint8_t i = selY; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (checkIsEnemyOnField(&selX, &i)) break;
|
||||||
|
posPossible[selX][i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//void FCC::Chess::set_lang(FCC::Languages lang) {
|
||||||
|
// m_lang = lang;
|
||||||
|
//}
|
||||||
|
|||||||
+58
-8
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
|
// #include "tui.h"
|
||||||
#include "graphics.h"
|
#include "lang.h"
|
||||||
|
|
||||||
namespace FCC
|
namespace FCC
|
||||||
{
|
{
|
||||||
@@ -20,21 +20,71 @@ namespace FCC
|
|||||||
BLACK = 10,
|
BLACK = 10,
|
||||||
WHITE = 20
|
WHITE = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
// classes and funcs
|
// 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();
|
||||||
|
void errOutput(std::string* errMessage);
|
||||||
|
};
|
||||||
|
|
||||||
class Chess
|
class Chess
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructor and destructor
|
// constructor and destructor
|
||||||
Chess() = default;
|
Chess();
|
||||||
~Chess() = default;
|
virtual ~Chess() = default;
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
uint8_t posPieces[8][8], posColor[8][8], posPossible[8][8];
|
FCC::Pieces posPieces[8][8];
|
||||||
|
FCC::PiecesColors posColor[8][8];
|
||||||
|
bool posPossible[8][8];
|
||||||
|
uint8_t selX, selY, tarX, tarY; //tar = target, sel = selected, pos = possible
|
||||||
|
|
||||||
// funcs
|
// funcs
|
||||||
void mainLoop();
|
void mainMenu();
|
||||||
|
void startupGame();
|
||||||
|
void gameLoop();
|
||||||
|
// void checkHorizontalMovementAllowed();
|
||||||
|
// void checkVerticalMovementAllowed();
|
||||||
|
// void checkDiagonalMovementAllowed();
|
||||||
|
//void set_lang(FCC::Languages lang);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// vars
|
||||||
bool gameEnded;
|
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(uint8_t* x, uint8_t* y);
|
||||||
|
bool checkPosInBounds(uint8_t* x, uint8_t* y);
|
||||||
|
void checkAllowedMoves();
|
||||||
|
void checkMovesHorizontal();
|
||||||
|
void checkMovesVertical();
|
||||||
|
void checkMovesDiagonal();
|
||||||
|
void checkMovesKnight();
|
||||||
|
void checkMovesKing();
|
||||||
|
void checkMovesPawn();
|
||||||
|
void checkPosEqualsSelPos(uint8_t* x, uint8_t* y);
|
||||||
|
void resetFieldColors();
|
||||||
|
void resetAllowedMovement();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include "lang.h"
|
||||||
|
|
||||||
|
void FCC::ChessLang::setLanguage(uint8_t setLangTo)
|
||||||
|
{
|
||||||
|
language = setLangTo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
//#include "FC-Chess.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#include "graphics.h"
|
|
||||||
|
|
||||||
void FCC::ChessTUI::mainLoop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FCC::ChessTUI::testLoop() {
|
|
||||||
std::cout << "\u2654" << std::endl;
|
|
||||||
std::cout << "♔" << std::endl;
|
|
||||||
//std::cout << L"♔";
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "FC-Chess.h"
|
|
||||||
|
|
||||||
namespace FCC
|
|
||||||
{
|
|
||||||
class ChessTUI
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void mainLoop();
|
|
||||||
void testLoop();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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 <--";
|
||||||
|
|
||||||
|
// error texts
|
||||||
|
std::string errNoPieceOnPosition = "Error: Empty position.";
|
||||||
|
};
|
||||||
|
}
|
||||||
+2
-11
@@ -1,17 +1,8 @@
|
|||||||
// FC-Chess.cpp : Defines the entry point for the application.
|
#include "FC-Chess.h"
|
||||||
//
|
|
||||||
|
|
||||||
#include "fc-chess.h"
|
|
||||||
|
|
||||||
//using namespace std;
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
// starting the game
|
||||||
FCC::Chess gm;
|
FCC::Chess gm;
|
||||||
gm.mainLoop();
|
|
||||||
|
|
||||||
FCC::ChessTUI test;
|
|
||||||
test.testLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// #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"♔";
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCC::TUI::errOutput(std::string* errMessage)
|
||||||
|
{
|
||||||
|
std::cout << *errMessage;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user