Browse Source

Refactoring: Bauernumwandlung.c Wichtige includes ergänzt, Emman Mensdorf

main
Emman Mensdorf 11 months ago
parent
commit
1a41c22f84
  1. 19
      src/Bauernumwandlung.c

19
src/Bauernumwandlung.c

@ -22,25 +22,29 @@
bool ist_umwandlung_gerlaubt_Bauer(char** Brett, int startX, int startY, int endX, int endY, Player player) { bool ist_umwandlung_gerlaubt_Bauer(char** Brett, int startX, int startY, int endX, int endY, Player player) {
if ((player == PLAYER_WHITE) && (endY == 7) && (Brett[startY][startX] == 'P')) { if ((player == PLAYER_WHITE) && (endY == 7) && (Brett[startY][startX] == 'P')) {
bauer_umwandeln(Brett,startX,startY,endX,endY,player);
return true; return true;
} else if ((player == PLAYER_BLACK) && (endY == 0) && (Brett[startY][startX] == 'p')) { } else if ((player == PLAYER_BLACK) && (endY == 0) && (Brett[startY][startX] == 'p')) {
bauer_umwandeln(Brett,startX,startY,endX,endY,player);
return true; return true;
} else { } else {
return false; return false;
} }
return false;
} }
char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int endY, Player player){ char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int endY, Player player){
if(ist_umwandlung_gerlaubt_Bauer(Brett ,startX,startY,endX,endY,player) == true){
char* Figur; char* Figur;
printf("Which piece would you like to create?"); printf("Which piece would you like to create?");
if(player == PLAYER_WHITE){ if(player == PLAYER_WHITE){
printf("Q for Queen, R for Rook, B for Bishop, or N for Knight"); printf("Q for Queen, R for Rook, B for Bishop, or N for Knight");
Figur = getUserInput();
//Figur = getUserInput();
Figur = 'Q';
}else{ }else{
printf("q for Queen, r for Rook, b for Bishop, or n for Knight"); printf("q for Queen, r for Rook, b for Bishop, or n for Knight");
Figur = getUserInput();
//Figur = getUserInput();
Figur = 'q';
} }
if ((player == PLAYER_WHITE && (Figur == 'Q' || Figur == 'R' || Figur == 'B' || Figur == 'N')) || if ((player == PLAYER_WHITE && (Figur == 'Q' || Figur == 'R' || Figur == 'B' || Figur == 'N')) ||
@ -49,16 +53,13 @@ char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int
} else { } else {
return 'W'; // Undefiniertes Zeichen als Fehlerwert return 'W'; // Undefiniertes Zeichen als Fehlerwert
} }
}
return 'W'; // Undefiniertes Zeichen als Fehlerwert
} }
void bauer_umwandeln(char** Brett, int startX, int startY, int endX, int endY, Player player) { void bauer_umwandeln(char** Brett, int startX, int startY, int endX, int endY, Player player) {
char Figur = bauer_umwandel_abfrage(Brett, startX, startY, endX, endY, player); char Figur = bauer_umwandel_abfrage(Brett, startX, startY, endX, endY, player);
if (Figur != 'W') {
Brett[endY][endX] = Figur; Brett[endY][endX] = Figur;
Brett[startY][startX] = ' '; Brett[startY][startX] = ' ';
}else{
printf("Invalid move");
}
} }
Loading…
Cancel
Save