Browse Source

refactoring: unnötige Kommentare löschen

main^2
fdai7726 11 months ago
committed by Peter Wiebe
parent
commit
d74eb007a6
  1. 27
      src/main/c/VierGewinnt.c

27
src/main/c/VierGewinnt.c

@ -32,10 +32,9 @@ void showColumnFullMessage();
void showWinMessage(int player); void showWinMessage(int player);
//Write starter function
int main_function() { int main_function() {
char board[ROWS][COLS]; char board[ROWS][COLS];
int currentPlayer = 1; // Spieler 1 beginnt
int currentPlayer = 1;
initializeBoard(board); initializeBoard(board);
printBoard(board); printBoard(board);
@ -70,7 +69,6 @@ int main_function() {
return 0; return 0;
} }
// Write initializeBoard function
void initializeBoard(char board[ROWS][COLS]) { void initializeBoard(char board[ROWS][COLS]) {
for (int i = 0; i < ROWS; i++) { for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) { for (int j = 0; j < COLS; j++) {
@ -80,7 +78,6 @@ void initializeBoard(char board[ROWS][COLS]) {
} }
// Write printBoard function
void printBoard(char board[ROWS][COLS]) { void printBoard(char board[ROWS][COLS]) {
clearScreen(); clearScreen();
printf("\n"); printf("\n");
@ -99,7 +96,6 @@ void printBoard(char board[ROWS][COLS]) {
printf(" 1 2 3 4 5 6 7\n\n"); printf(" 1 2 3 4 5 6 7\n\n");
} }
// Write clearScreen function
void clearScreen() { void clearScreen() {
#ifdef _WIN32 #ifdef _WIN32
system("cls"); system("cls");
@ -108,12 +104,10 @@ void clearScreen() {
#endif #endif
} }
// Write isColumnFull function
int isColumnFull(char board[ROWS][COLS], int col) { int isColumnFull(char board[ROWS][COLS], int col) {
return (board[0][col] != ' '); return (board[0][col] != ' ');
} }
//Write dropPiece function
int dropPiece(char board[ROWS][COLS], int col, char player) { int dropPiece(char board[ROWS][COLS], int col, char player) {
for (int i = ROWS - 1; i >= 0; i--) { for (int i = ROWS - 1; i >= 0; i--) {
if (board[i][col] == ' ') { if (board[i][col] == ' ') {
@ -122,11 +116,10 @@ int dropPiece(char board[ROWS][COLS], int col, char player) {
} }
} }
return 0; // Column is full
return 0;
} }
// Write checkHorizontal function
int checkHorizontal(char board[ROWS][COLS], char player) { int checkHorizontal(char board[ROWS][COLS], char player) {
for (int row = 0; row < ROWS; row++) { for (int row = 0; row < ROWS; row++) {
for (int col = 0; col <= COLS - 4; col++) { for (int col = 0; col <= COLS - 4; col++) {
@ -134,14 +127,13 @@ int checkHorizontal(char board[ROWS][COLS], char player) {
board[row][col + 1] == player && board[row][col + 1] == player &&
board[row][col + 2] == player && board[row][col + 2] == player &&
board[row][col + 3] == player) { board[row][col + 3] == player) {
return 1; // Gewonnen
return 1;
} }
} }
} }
return 0; return 0;
} }
//Write checkVertical function
int checkVertical(char board[ROWS][COLS], char player) { int checkVertical(char board[ROWS][COLS], char player) {
for (int col = 0; col < COLS; col++) { for (int col = 0; col < COLS; col++) {
for (int row = 0; row <= ROWS - 4; row++) { for (int row = 0; row <= ROWS - 4; row++) {
@ -149,7 +141,7 @@ int checkVertical(char board[ROWS][COLS], char player) {
board[row + 1][col] == player && board[row + 1][col] == player &&
board[row + 2][col] == player && board[row + 2][col] == player &&
board[row + 3][col] == player) { board[row + 3][col] == player) {
return 1; // Gewonnen
return 1;
} }
} }
} }
@ -158,7 +150,6 @@ int checkVertical(char board[ROWS][COLS], char player) {
// Write checkDiagonalLR function
int checkDiagonalLR(char board[ROWS][COLS], char player) { int checkDiagonalLR(char board[ROWS][COLS], char player) {
for (int row = 0; row <= ROWS - 4; row++) { for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 0; col <= COLS - 4; col++) { for (int col = 0; col <= COLS - 4; col++) {
@ -166,7 +157,7 @@ int checkDiagonalLR(char board[ROWS][COLS], char player) {
board[row + 1][col + 1] == player && board[row + 1][col + 1] == player &&
board[row + 2][col + 2] == player && board[row + 2][col + 2] == player &&
board[row + 3][col + 3] == player) { board[row + 3][col + 3] == player) {
return 1; // Gewonnen
return 1;
} }
} }
} }
@ -176,7 +167,6 @@ int checkDiagonalLR(char board[ROWS][COLS], char player) {
// Write checkDiagonalRL function
int checkDiagonalRL(char board[ROWS][COLS], char player) { int checkDiagonalRL(char board[ROWS][COLS], char player) {
for (int row = 0; row <= ROWS - 4; row++) { for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 3; col < COLS; col++) { for (int col = 3; col < COLS; col++) {
@ -184,7 +174,7 @@ int checkDiagonalRL(char board[ROWS][COLS], char player) {
board[row + 1][col - 1] == player && board[row + 1][col - 1] == player &&
board[row + 2][col - 2] == player && board[row + 2][col - 2] == player &&
board[row + 3][col - 3] == player) { board[row + 3][col - 3] == player) {
return 1; // Gewonnen
return 1;
} }
} }
} }
@ -192,7 +182,6 @@ int checkDiagonalRL(char board[ROWS][COLS], char player) {
} }
// Write checkWin function
int checkWin(char board[ROWS][COLS], char player) { int checkWin(char board[ROWS][COLS], char player) {
return checkHorizontal(board, player) || return checkHorizontal(board, player) ||
checkVertical(board, player) || checkVertical(board, player) ||
@ -201,12 +190,10 @@ int checkWin(char board[ROWS][COLS], char player) {
} }
// Write showMessage function
void showMessage(const char* messageColor, const char* message) { void showMessage(const char* messageColor, const char* message) {
printf("%s%s"RESET_COLOR, messageColor, message); printf("%s%s"RESET_COLOR, messageColor, message);
} }
// Write showInvalidInputMessage function
void showInvalidInputWarning() { void showInvalidInputWarning() {
showMessage(RED, "Ungültige Eingabe. Bitte wähle eine Spalte zwischen 1 und 7.\n"); showMessage(RED, "Ungültige Eingabe. Bitte wähle eine Spalte zwischen 1 und 7.\n");
} }
@ -214,14 +201,12 @@ void showInvalidInputWarning() {
// Write showColumnFullMessage function
void showColumnFullMessage() { void showColumnFullMessage() {
showMessage(RED, "Die ausgewählte Spalte ist bereits belegt. Bitte wähle eine andere Spalte aus.\n"); showMessage(RED, "Die ausgewählte Spalte ist bereits belegt. Bitte wähle eine andere Spalte aus.\n");
} }
// Write showWinMessage function
void showWinMessage(int player) { void showWinMessage(int player) {
printf("Spieler %d hat gewonnen!\n", player); printf("Spieler %d hat gewonnen!\n", player);
} }

Loading…
Cancel
Save