Minesweeper Game in C++
#include<iostream>
#include <stdlib.h>
#include<conio.h>
using namespace std;
void main()
{
int option;
int counter=0;
cout<<"for easy enter 1, for hard enter 2: ";
cin>>option;
cout<<endl;
while(option!=1&&option!=2)
{
cout<<"enter 1 or 2: ";
cin>>option;
cout<<endl;
}
int mainArray[10][10]; //main array which has the values
if(option==1)
{
srand(time(0));
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{mainArray[i][j]=0 + rand()% 7;}
}
}
if(option==2)
{
srand(time(0));
for(int d=0;d<10;d++)
{
for(int f=0;f<10;f++)
{mainArray[d][f]=0 + rand()% 4;}
}
}
char dispArray[10][10]; //array to be displayed
for(int k=0;k<10;k++)
{ cout<<endl;
for(int l=0;l<10;l++)
{
dispArray[k][l]='*';
cout<<dispArray[k][l]<<" ";
}
}
int row;
int column;
do{
cout<<endl;
cout<<"\nEnter Row number (0 to 9): ";
cin>>row;
cout<<"Enter Column number (0 to 9): ";
cin>>column;
if(mainArray[row][column]!=0)
{
counter++;
}
clrscr();
dispArray[row][column]=(char)(mainArray[row][column]+48); //int converted it into char by its ASCII code
for(int p=0;p<10;p++)
{ cout<<endl;
for(int q=0;q<10;q++)
{
cout<<dispArray[p][q]<<" ";
}
}
}
while(mainArray[row][column]!=0);
cout<<"\n\ngame over"<<endl<<"total score= "<<counter;
_getch();
}
0 comments:
Post a Comment