Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

c - Minesweeper variation

I really don't understand why does it stop after the reading of the bombs(k). On the function bomb, I just need to place the bombs randomly on a 2d array. Then I use the function counter to detect the surrounding bombs and have some numbers. Lastly in result I just want to print the array. I could really use your help. Thanks for your time.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
 char *bomb(int,int,char*);
 void counter(int,int,char*);

 void result(int,int,char*);
 
 
int main(int argc, char **argv){
 
    int i,j,k,m,n;
 
    system("chcp 1253");
    srand(time(NULL));
    do{
    printf ( "Dimensions:" );
    scanf ( "%d%d",& m , & n ); 
    }
    while (m < 0 && n < 0);
    char *msweep[m][n];
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
        msweep[i][j]=0;
        }
    }
    bomb(m,n,**msweep);
    counter(m,n,**msweep);
    result(m,n,**msweep);
 
    return 0;
 
 
}
char *bomb(int m,int n,char *msweep)
{
    int x,y,k,i,j;
    printf ("Bombs:");
    do
    {
    scanf ("%d",&k);    
    } while ( k > ( m * n ) );
    x= rand()%m;
    y= rand()%n;
    printf("x: %d",x);
    printf("y: %d",y);
    *(msweep + x + y) = '+';
 
 
    return msweep;
}
void counter(int m,int n,char *msweep)
{
    int i,j;
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i -1) + j)='+'){
                *(msweep + i + j)= *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i+1) + j)='+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + i + (j-1))='+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + i + (j+1))='+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i - 1) + (j + 1)) = '+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i-1) + (j-1))='+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i+1) + (j+1) ) ='+')
                 {
                    *(msweep + i + j)= *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j,n;j++){
             if (*(msweep + i + j)!='+'){
                if  (*(msweep + (i+1) + (j-1) ) ='+'){
                    *(msweep + i + j) = *(msweep + i + j) + 1;
 
 
                }            
            }       
        }
    }
}
void result(int m,int n,char *msweep){
    int i,j;
    for (i=0;i<m;i++); {
        for (j=0;j<n;j++) {
            printf("%d", *(msweep + i + j));
        }
        printf("
");
    }
 
}`
question from:https://stackoverflow.com/questions/65858301/minesweeper-variation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...