Task is to create a flood-it game in a 20x60 game, starting in the upper left corner. Numbers are used instead of colours for ease. So, the code seems to be working fine up to one point. But after a certain amount of rounds, player plays and then it just crashes ("...stopped working") message. Here is the code:
#include <stdio.h>
#include <stdlib.h>
int k=0,l=0;
void BoardMaking(int A[20][60]){
int i,j;
srand(time(0));
for(i=0;i<20;i++){
for(j=0;j<60;j++){
A[i][j]=rand()%5 +1;
}
}
}
void Print_Board(int A[20][60]){
int i,j;
for(i=0;i<20;i++){
for(j=0;j<60;j++){
printf("%d",A[i][j]);
}
printf("\n");
}
}
int Player(){
int x;
printf("\ngive a number between 1-5\n");
scanf("%d",&x);
return x;
}
void Change(int A[20][60],int y,int x){
A[k][l]=x;
if(A[k][l+1]==y){
A[k][l+1]=x;
l++;
Change(A,y,x);
}
if(A[k][l-1]==y){
A[k][l-1]=x;
l--;
Change(A,y,x);
}
if(A[k-1][l]==y){
A[k-1][l]=x;
k--;
Change(A,y,x);
}
if(A[k+1][l]==y){
A[k+1][l]=x;
k++;
Change(A,y,x);
}
k=0;l=0;
}
int main(){
int y,x;
int A[20][60];
BoardMaking(A);
while(1){
Print_Board(A);
x=Player();
if (x==A[0][0]){
printf("give another number \n");
}
else if (x!=A[0][0])
{
y=A[0][0];
Change(A,y,x);
}
}
return 0;
}