|
@ -4,11 +4,14 @@ |
|
|
#include "Spiellogik.h" |
|
|
#include "Spiellogik.h" |
|
|
#include <time.h> |
|
|
#include <time.h> |
|
|
#define N 20 |
|
|
#define N 20 |
|
|
|
|
|
int update1(int realU[N][N],char richtung); |
|
|
|
|
|
int speed = 0; |
|
|
|
|
|
|
|
|
/**Main Methode die das Spiel startet, loopt und beendet |
|
|
/**Main Methode die das Spiel startet, loopt und beendet |
|
|
* indem die anderen Methoden/Funktionen aufgerufen werden |
|
|
* indem die anderen Methoden/Funktionen aufgerufen werden |
|
|
*/ |
|
|
*/ |
|
|
int main(int argc, char ** argv){ |
|
|
int main(int argc, char ** argv){ |
|
|
|
|
|
|
|
|
int quit=0; |
|
|
int quit=0; |
|
|
int winb=0; |
|
|
int winb=0; |
|
|
int looseb=0; |
|
|
int looseb=0; |
|
@ -20,12 +23,17 @@ int main(int argc, char ** argv){ |
|
|
|
|
|
|
|
|
char g='d'; |
|
|
char g='d'; |
|
|
Apfel(realU); |
|
|
Apfel(realU); |
|
|
|
|
|
char richtung; |
|
|
|
|
|
int testint; |
|
|
|
|
|
|
|
|
while(winb==0 && quit==0 && looseb==0){ |
|
|
while(winb==0 && quit==0 && looseb==0){ |
|
|
Umgebung(realU); |
|
|
Umgebung(realU); |
|
|
|
|
|
richtung = getInput(); |
|
|
|
|
|
testint = update1(realU, richtung); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//loose=loose(realU); |
|
|
|
|
|
winb=win(realU); |
|
|
|
|
|
|
|
|
//looseb=lose(realU,richtung); |
|
|
|
|
|
//winb=win(realU); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -38,3 +46,118 @@ int main(int argc, char ** argv){ |
|
|
|
|
|
|
|
|
//Scoreanzeige |
|
|
//Scoreanzeige |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int update1(int realU[N][N],char richtung) { |
|
|
|
|
|
|
|
|
|
|
|
int groesste ; |
|
|
|
|
|
int ii = sucheXWert(realU); |
|
|
|
|
|
int jj = sucheYWert(realU); |
|
|
|
|
|
|
|
|
|
|
|
if(richtung == 'u') { |
|
|
|
|
|
if(ii == 0) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
if(realU[ii + 1] [jj] == (N * N) + 1) { |
|
|
|
|
|
realU[ii + 1] [jj] = groesste + 1; |
|
|
|
|
|
Apfel(realU); |
|
|
|
|
|
speed = speed + 20; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if(!lose(realU, richtung)) { |
|
|
|
|
|
realU[ii - 1][jj] = groesste + 1; |
|
|
|
|
|
for (int i = 0; i < N; i++) { |
|
|
|
|
|
for (int j = 0; j < N; j++) { |
|
|
|
|
|
if (realU[i][j] != 0 && realU[i][j] != (N * N) + 1) { |
|
|
|
|
|
realU[i][j]--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (richtung == 'd') { |
|
|
|
|
|
if (ii == N - 1) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
if (realU[ii + 1][jj] == (N * N) + 1) { |
|
|
|
|
|
realU[ii + 1][jj] = groesste + 1; |
|
|
|
|
|
Apfel(realU); |
|
|
|
|
|
speed = speed + 20; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (!lose(realU, richtung)) { |
|
|
|
|
|
realU[ii + 1][jj] = groesste + 1; |
|
|
|
|
|
for (int i = 0; i < N; i++) { |
|
|
|
|
|
for (int j = 0; j < N; j++) { |
|
|
|
|
|
if (realU[i][j] != 0 && realU[i][j] != (N * N) + 1) { |
|
|
|
|
|
realU[i][j]--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (richtung == 'l') { |
|
|
|
|
|
if (jj == 0) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
if (realU[ii][jj - 1] == (N * N) + 1) { |
|
|
|
|
|
realU[ii][jj - 1] = groesste + 1; |
|
|
|
|
|
Apfel(realU); |
|
|
|
|
|
speed = speed + 20; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (!lose(realU, richtung)) { |
|
|
|
|
|
realU[ii][jj - 1] = groesste + 1; |
|
|
|
|
|
for (int i = 0; i < N; i++) { |
|
|
|
|
|
for (int j = 0; j < N; j++) { |
|
|
|
|
|
if (realU[i][j] != 0 && realU[i][j] != (N * N) + 1) { |
|
|
|
|
|
realU[i][j]--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (jj == N - 1) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
if (realU[ii][jj + 1] == (N * N) + 1) { |
|
|
|
|
|
realU[ii][jj + 1] = groesste + 1; |
|
|
|
|
|
Apfel(realU); |
|
|
|
|
|
speed = speed + 20; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (!lose(realU, richtung)) { |
|
|
|
|
|
realU[ii][jj + 1] = groesste + 1; |
|
|
|
|
|
for (int i = 0; i < N; i++) { |
|
|
|
|
|
for (int j = 0; j < N; j++) { |
|
|
|
|
|
if (realU[i][j] != 0 && realU[i][j] != (N * N) + 1) { |
|
|
|
|
|
realU[i][j]--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (win(realU)) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} else { |
|
|
|
|
|
Umgebung(realU); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |