179 lines
4.7 KiB
C++
179 lines
4.7 KiB
C++
#include <windows.h>
|
|
#include "Player/Player.hpp"
|
|
#include "ChessPieces/ChessPiece.hpp"
|
|
#include "Chessboard/Chessboard.hpp"
|
|
#include "Chessboard/ChessboardVisualizerText.hpp"
|
|
#include "Chessboard/ChessboardVisualizerGraphic.hpp"
|
|
#include "Visualizer/BaseVisualizer.hpp"
|
|
#include "Visualizer/StartMenuVisualizer.hpp"
|
|
#include "Visualizer/HistorieVisualizer.hpp"
|
|
#include "Visualizer/ChessboardVisualizer.hpp"
|
|
#include "Visualizer/CommandMenuVisualizer.hpp"
|
|
#include "Visualizer/PlayingViewVisualizer.hpp"
|
|
#include "Visualizer/InstructionsVisualizer.hpp"
|
|
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <locale>
|
|
|
|
void HandleThirdOption() {
|
|
BaseVisualizer::ClearTerminal();
|
|
InstructionsVisualizer instructions = InstructionsVisualizer();
|
|
instructions.DisplayElement();
|
|
std::cout << "\x1B[u";
|
|
std::cin;
|
|
}
|
|
|
|
void HandleCommandOptions(const std::string& command) {
|
|
if (command == "1") {
|
|
HandleThirdOption();
|
|
} else if (command == "2") {
|
|
// ToDo: Save implementieren
|
|
} else if (command == "3") {
|
|
// ToDo: Exit implementieren -> Möglichkeit noch zu speichern oder einfach speichern?
|
|
} else if (command == "8") {
|
|
// ToDo: Spiel beenden -> Gewinn an anderen gegeben
|
|
} else if (command == "9") {
|
|
// ToDo: Draw anbieten -> Anfrage mit Annahme/Ablehnen an anderen Spieler schicken
|
|
}
|
|
}
|
|
|
|
std::string ExtractAfterDollar(const std::string& userInput) {
|
|
// Überprüfen, ob der String mit '$' beginnt
|
|
if (!userInput.empty() && userInput[0] == '$') {
|
|
return userInput.substr(1); // Rückgabe des Teils nach '$'
|
|
}
|
|
return ""; // Leerer String, wenn kein '$' am Anfang
|
|
}
|
|
|
|
void HandleFirstOption() {
|
|
BaseVisualizer::ClearTerminal();
|
|
Player* playerA = new Player("Player 1");
|
|
Player* playerB = new Player("Player 2");
|
|
|
|
Chessboard chessboard = Chessboard();
|
|
chessboard.SetPlayers(playerA, playerB);
|
|
|
|
chessboard.InitializeStartBoard();
|
|
|
|
PlayingViewVisualizer playView = PlayingViewVisualizer(&chessboard, 4, 12);
|
|
|
|
while (chessboard.IsCheckmate() == false) {
|
|
std::string input;
|
|
|
|
playView.DisplayElement();
|
|
|
|
std::cout << "\x1B[u";
|
|
std::cin >> input;
|
|
|
|
std::string command = ExtractAfterDollar(input);
|
|
|
|
while (command != "3") {
|
|
if (command != "") {
|
|
HandleCommandOptions(command);
|
|
break;
|
|
} else {
|
|
//ToDo: Valide Züge annehmen
|
|
chessboard.MoveChessPiece(input);
|
|
}
|
|
// ToDo: Nicht valide Eingabe melden -> Unterscheidung was falsch?
|
|
}
|
|
break;
|
|
}
|
|
std::cout << "Game is over! - " << chessboard.GetOpponentPlayer()->GetName() << " has won the game!" << std::endl;
|
|
}
|
|
|
|
void HandleSecondOption() {}
|
|
|
|
int main() {
|
|
SetConsoleOutputCP(CP_UTF8);
|
|
|
|
BaseVisualizer::ClearTerminal();
|
|
|
|
StartMenuVisualizer startMenu = StartMenuVisualizer(3);
|
|
int choice = -1;
|
|
|
|
while (startMenu.GetSelectedOption() != 0) {
|
|
BaseVisualizer::ClearTerminal();
|
|
startMenu.DisplayElement1();
|
|
|
|
if (startMenu.GetSelectedOption() == 1) {
|
|
HandleFirstOption();
|
|
} else if (startMenu.GetSelectedOption() == 2) {
|
|
HandleSecondOption();
|
|
} else if (startMenu.GetSelectedOption() == 3) {
|
|
HandleThirdOption();
|
|
}
|
|
}
|
|
|
|
//CommandMenuVisualizer commandMenu = CommandMenuVisualizer(2);
|
|
//commandMenu.DisplayElement();
|
|
//HistorieVisualizer historie = HistorieVisualizer(15, 2, "Player 1", "Player 2");
|
|
//historie.DisplayElement();
|
|
|
|
|
|
|
|
|
|
|
|
/*if () {
|
|
Player* playerA = new Player("Player 1");
|
|
Player* playerB = new Player("Player 2");
|
|
|
|
Chessboard chessboard = Chessboard();
|
|
chessboard.SetPlayers(playerA, playerB);
|
|
|
|
chessboard.InitializeStartBoard();
|
|
|
|
// Jetzt kann man Moves machen. Nach jedem Move müssen die ChessPieces aktualisiert werden.
|
|
chessboard.UpdateChessPieces();
|
|
|
|
//ChessboardVisualizerText* visualizer = new ChessboardVisualizerText();
|
|
ChessboardVisualizer visualizer(&chessboard, 2);
|
|
|
|
|
|
}*/
|
|
//}
|
|
|
|
/*std::cout << "Spieler A: ";
|
|
std::string namePlayerA;
|
|
getline(std::cin, namePlayerA);
|
|
std::cout << "Spieler B: ";
|
|
std::string namePlayerB;
|
|
getline(std::cin, namePlayerB);
|
|
|
|
Player* playerA = new Player("1");
|
|
Player* playerB = new Player("2");*/
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
std::vector<std::vector<ChessPiece>> chessmatrix;
|
|
|
|
Chessboard chessboard;
|
|
|
|
if (argc == 2) {
|
|
std::cout << "Spielstand" << std::endl;
|
|
chessboard.loadBoard(std::string(argv[1]));
|
|
} else {
|
|
chessboard.setBoard(chessboard.getStartBoard());
|
|
}
|
|
|
|
//chessboard.init();
|
|
chessboard.draw();
|
|
|
|
while (true) {
|
|
std::string move;
|
|
std::cout << "Move [" << (chessboard.getTurnOrder() ? "white" : "black") << "]: ";
|
|
std::cin >> move;
|
|
|
|
chessboard.move(move);
|
|
chessboard.saveBoard();
|
|
|
|
}
|
|
*/
|