Add to Favorites    Make Home Page 4437 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Mine Sweeper Game.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Mine Sweeper Game.
Author Rajiv Krishan
Author Email itsrajivbansal [at] yahoo.com
Description Its a game seems to be same as Microsoft Minesweeper Game. It
workd similarly.
Category C » Games and Graphics
Hits 369274
Code Select and Copy the Code
//Its a Game By Rajiv Krishan, MCA, Panjab University Regional Centre, //Muktsar, Mobile no. 9815064903 #include <stdio.h> #include <conio.h> #include <graphics.h> #include <dos.h> #include <stdlib.h> #include <time.h> #define MROW 8 #define MCOL 8 #define MINES 5 #define BSIZE 15 union REGS i,o; //9 for mines main() { int bm=DETECT,bg=DETECT,maxx,maxy,button,x,y,i,j,checkx,checky,nclick; int arr[8][8],dot[MINES]; int count1,count2; int row,col; time_t t; clrscr(); initgraph(&bm,&bg,"e:\tcc\bgi"); maxx=getmaxx(); maxy=getmaxy(); if(initmouse()==0) { closegraph(); restorecrtmode(); printf("MOUSE NOT FOUND"); exit(1); } while(!kbhit()) { char loop='t'; setcolor(WHITE); setviewport(0,0,getmaxx(),getmaxy(),1); clearviewport(); showmouse(); //It Blanks the Array for(i=0;i<MROW;i++) for(j=0;j<MCOL;j++) arr[i][j]=0; //put mines in random blocks srand((unsigned) time(&t)); for(i=0;i<MINES;i++) { dot[i]=rand()%64; for(j=0;j<i;j++) if(dot[i]==dot[j]) break; if(i!=j) { i--; continue; } else { row=dot[i]/MROW; col=dot[i]%MCOL; arr[row][col]=9; } } //put mines value in other blocks for(row=0;row<MROW;row++) { for(col=0;col<MCOL;col++) { if(arr[row][col]!=9) //No Mine { int i,num=0,temp,ecol,erow,startrow; temp=col==0?col:col-1; ecol=col!=MCOL-1?col+1:col; startrow=row==0?row:row-1; erow=row==MROW-1?row:row+1; for(i=startrow;i<=erow;i++) for(j=temp;j<=ecol;j++) if(arr[i][j]==9) num++; arr[row][col]=num; } } } rectangle(0,0,maxx,maxy); //sets view port to the play area only setviewport(200,190,385,370,1); nclick=0; while(!kbhit()&&loop=='t') { int row=10,col=5; setlinestyle(0,0,3); rectangle(row-5,col-3,row*17,col*33); //Draws outer block setlinestyle(0,0,2); for(i=0;i<MROW;i++) { for(j=0;j<MCOL;j++) { rectangle(row,col,row+BSIZE,col+BSIZE); if(arr[i][j]!=9) { int temp[3]; if(arr[i][j]>=80) outtextxy(row+4,col+4,"F"); else if(arr[i][j]>=50) { itoa((arr[i][j]-50),temp,10); outtextxy(row+BSIZE/2,col+BSIZE/2,temp); } } row+=BSIZE+5; } row=10; col+=BSIZE+5; } if(nclick==MROW*MCOL-MINES) { setviewport(0,0,getmaxx(),getmaxy(),1); outtextxy(200,100,"CONGRATS! YOU WON THE GAME"); getch(); loop='f'; } getpos(&button,&x,&y); //puts F tag in Array if(button&2) { int val,prex=x,prey=y; x=210+(x-210)/20*20; y=195+(y-195)/20*20; val=arr[(y-195)/20][(x-210)/20]; if(val<10 || val>=80) { val=val>=80?val-80:80+val; arr[(y-195)/20][(x-210)/20]=val; while(button&2) getpos(&button,&x,&y); hidemouse(); setpos(30,50); clearviewport(); showmouse(); setpos(prex,prey); } } if(button&1 && x>=210 && x<=365 && y>=195 && y<=350) { char temp[4]; int trow,tcol; //determine current box x=210+(x-210)/20*20; y=195+(y-195)/20*20; trow=(y-195)/20; tcol=(x-210)/20; if(arr[trow][tcol]==9) { int row=10,col=5; setviewport(0,0,getmaxx(),getmaxy(),1); hidemouse(); outtextxy(200,100,"SORRY,YOU LOOSE THE GAME"); setviewport(200,190,385,370,1); //prints X marks in END on screen for(i=0;i<MROW;i++) { for(j=0;j<MCOL;j++) { if(arr[i][j]==9 || arr[i][j]==89) { setfillstyle(1,RED); bar(row,col,row+BSIZE,col+BSIZE); outtextxy(row+5,col+5,"x"); } row+=20; } row=10; col+=20; } showmouse(); setviewport(0,0,getmaxx(),getmaxy(),1); setfillstyle(1,YELLOW); bar(170,400,270,425); bar(330,400,430,425); while(loop=='t') { setcolor(BLUE); outtextxy(180,410,"PLAY AGAIN"); outtextxy(360,410,"QUIT"); getpos(&button,&x,&y); if(!button&1) { if(x>=170 && x<=270 && y>=400 && y<=425) { setfillstyle(1,CYAN); bar(170,400,270,425); setfillstyle(1,YELLOW); bar(330,400,430,425); outtextxy(180,410,"PLAY AGAIN"); outtextxy(360,410,"QUIT"); while(x>=170 && x<=270 && y>=400 && y<=425 && !button&1) getpos(&button,&x,&y); } if(x>=330 && x<=430 && y>=400 && y<=425) { setfillstyle(1,CYAN); bar(330,400,430,425); setfillstyle(1,YELLOW); bar(170,400,270,425); } outtextxy(180,410,"PLAY AGAIN"); outtextxy(360,410,"QUIT"); while(x>=330 && x<=430 && y>=400 && y<=425 && !button&1) getpos(&button,&x,&y); } else { if(x>=170 && x<=270 && y>=400 && y<=425) { setviewport(200,190,385,370,1); loop='f'; hidemouse(); break; } if(x>=330 && x<=430 && y>=400 && y<=425) { restorecrtmode(); closegraph(); exit(0); } } } } else { //NOT ON DANGER AREA if(arr[trow][tcol]<50) { nclick++; arr[trow][tcol]+=50; } } } } if(loop=='t') { restorecrtmode(); closegraph(); exit(0); } } } initmouse() { i.x.ax=0; int86(0x0033,&i,&o); return(o.x.ax); } showmouse() { i.x.ax=1; int86(0x0033,&i,&o); } hidemouse() { i.x.ax=2; int86(0x0033,&i,&o); } restarea(int x1,int x2,int y1,int y2) { i.x.ax=7; i.x.cx=x1; i.x.dx=x2; int86(0x0033,&i,&o); i.x.ax=8; i.x.cx=y1; i.x.dx=y2; int86(0x0033,&i,&o); } setpos(int x,int y) { i.x.ax=4; i.x.cx=x; i.x.dx=y; int86(0x0033,&i,&o); } getpos(int *button,int *x,int *y) { i.x.ax=3; int86(0x0033,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=485


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review