Minesweeper project

closed account (G60iz8AR)
Is this this a correct code to get out of a minesweeper ?
#include <fstream>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

const int DIM = 10;
void loadSwamp( int swamp[][DIM], ifstream &swampFile );
void printSwamp( int swamp[][DIM] );
void printEscape( int swamp [][DIM], int row, int col );

int main( int argc, char**argv )
{
ifstream swampFile;
swampFile.open( argv[1], ios::in );
if (!swampFile) exit(0);

int row,col;
swampFile >> row >> col;

int swamp[DIM][DIM];

loadSwamp( swamp, swampFile );
printSwamp( swamp );

printEscape( swamp, row, col );
cout << endl;

return 0;
} // END MAIN

//####################################################################

void printEscape( int swamp [][DIM], int row, int col )
{
cout << "[" << row << "," << col << "]";

while ( row !=0 && col != 0 && row != DIM-1 && col != DIM-1 )
{
if ( swamp[row-1][col] == 1) // N
{
swamp[row][col] = -1;
row--;
cout << "[" << row << "," << col << "]";
}
else if ( swamp[row-1][col+1] == 1 ) // NE
{
swamp[row][col] = -1;
row--; col++;
cout << "[" << row << "," << col << "]";
}

else if (swamp[row] [col+1] == 1 ) //EAST
{
swamp[row][col] = -1
col++;
cout << "[" << row << "," << col << "]" ;

}

else if (swamp[row+1] [col+1] == 1 ) // SOUTHEAST
{
swamp[row][col] = -1 ;
row++; col--;
cout << "[" << row << "," << col << "]" ;

}

else if (swamp[row+1] [col] == 1 ) // SOUTH
{
swamp[row][col] = -1 ;
row++;
cout << "[" << row << "," << col << "]" ;

}
else if (swamp[row+1] [col-1] ==1 ) //SOUTHWEST
{
swamp[row][col] = -1 ;
row ++; col--;
cout << "[" << row << "," << col << "]" ;
}
else if (swamp[row+1] [col-1] ==1 ) //WEST
swamp[row][col] = -1 ;
col--;
cout << "[" << row << "," << col << "]" ;
}





// YOUR CODE HERE TO ADD THE CASES FOR SE, S, SW, W, NW etc.



} // END WHILE

} // END PRINT ESCAPE

void loadSwamp( int swamp[][DIM], ifstream &swampFile )
{
for ( int r=0; r<DIM ; r++ )
for ( int c=0 ; c<DIM ; c++ )
swampFile >> swamp[r][c];
}

void printSwamp( int swamp[][DIM] )
{
for ( int r=0; r<DIM ; r++ )
{
for ( int c=0 ; c<DIM ; c++ )
cout << swamp[r][c] << " ";
cout << endl;
}
cout << endl;
}
Topic archived. No new replies allowed.