added first game rendering engine
This commit is contained in:
70
main.cpp
Normal file
70
main.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
string spielfeld[3][3] = {
|
||||
{" ", " ", " "},
|
||||
{" ", " ", " "},
|
||||
{" ", " ", " "}
|
||||
};
|
||||
|
||||
struct userInput {
|
||||
bool ok;
|
||||
int spalte;
|
||||
int zeile;
|
||||
};
|
||||
|
||||
void render() {
|
||||
system("cls");
|
||||
|
||||
cout << " | 1 | 2 | 3 |" << endl;
|
||||
cout << "---------------" << endl;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
cout << i+1 << " | ";
|
||||
for (int j = 0; j < 3; j++) {
|
||||
cout << spielfeld[i][j] << " | ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "---------------" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
userInput getUserInput() {
|
||||
int inputSpalte, inputZeile;
|
||||
cout << "Zeile: ";
|
||||
cin >> inputZeile;
|
||||
cout << "Spalte: ";
|
||||
cin >> inputSpalte;
|
||||
cout << endl;
|
||||
if (spielfeld[inputSpalte-1][inputZeile-1] == " ") {
|
||||
return {true, inputSpalte-1, inputZeile-1};
|
||||
} else {
|
||||
cout << endl << "Input konnte nicht gelesen werden" << endl;
|
||||
return getUserInput();
|
||||
}
|
||||
}
|
||||
|
||||
void checkforWin() {
|
||||
// TODO: check for win or fail and return a game struct.
|
||||
}
|
||||
|
||||
int main() {
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
cout << fixed << setprecision(2);
|
||||
|
||||
int counter = 1;
|
||||
while (true) {
|
||||
render();
|
||||
string current_player = counter++ % 2 == 1 ? "X" : "O";
|
||||
cout << endl << "Am Zug ist Spieler: " << current_player << endl;
|
||||
if (auto [ok, spalte, zeile] = getUserInput(); ok) {
|
||||
spielfeld[zeile][spalte] = current_player;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user