#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "mouse.c"
#define YES 1
#define NO 0
#define XPX 15 /* X pixels by square */
#define YPX 15 /* Y pixels by square */
#define DEFCX 30 /* Default number of squares */
#define DEFCY 28
#define MINE 255-'0' /* So that when it prints, it prints char 0xff */
#define STSQUARE struct stsquare
STSQUARE {
unsigned char value/* Number of mines in the surround squares */
unsigned char sqopen/* Square is open */
unsigned char sqpress/* Square is pressed */
unsigned char sqmark/* Square is marked */
} *psquare
#define value(x,y) (psquare+(x)*ncy+(y))->value
#define sqopen(x,y) (psquare+(x)*ncy+(y))->sqopen
#define sqpress(x,y) (psquare+(x)*ncy+(y))->sqpress
#define sqmark(x,y) (psquare+(x)*ncy+(y))->sqmark
int XST, /* Offset of first pixel X */
YST,
ncx, /* Number of squares in X */
ncy,
cmines, /* Mines discovered */
initmines, /* Number of initial mines */
sqclosed, /* Squares still closed */
maxy/* Max. number of y pixels of the screen */
void Graph_init(void)
void Read_param(int argc, char *argv[])
void Set_mines(int nminas)
void Set_square(int x, int y, int status)
void Mouse_set(void)
void Draw_squares(void)
int Do_all(void)
void Blow_up(void)
void Open_square(int x, int y)
int Open_near_squares(int x, int y)
/************************************************************************/
void main(int argc, char *argv[])
{
if (!mouse_reset()) {
cputs(" ERROR: I can't find a mouse driver\r\n")
exit(2)
}
Graph_init()
Read_param(argc, argv)
Mouse_set()
do {
randomize()
cleardevice()
Set_mines(cmines=initmines)
mouse_enable()
Draw_squares()
}
while (Do_all() != '\x1b')
closegraph()
}
/*************************************************************************
* *
* F U N C T I O N S *
* *
*************************************************************************/
/*----------------------------------------------------------------------*/
void Graph_init(void)
{
int graphdriver=DETECT, graphmode, errorcode
if(errorcode <0) {
cprintf("\n\rGraphics System Error: %s\n",grapherrormsg(errorcode))
exit(98)
}
initgraph(&graphdriver, &graphmode, "")
errorcode=graphresult()
if(errorcode!=grOk) {
printf(" Graphics System Error: %s\n",grapherrormsg(errorcode))
exit(98)
}
maxy=getmaxy()
} /* Graph_init */
/*----------------------------------------------------------------------*/
void Read_param(int argc, char *argv[])
{
int x, y, m
x=y=m=0
if (argc!=1) {
if (!isdigit(*argv[1])) {
closegraph()
cprintf("Usage is: %s [x] [y] [m]\r\n\n"
"Where x is the horizontal size\r\n"
" y is the vertical size\r\n"
" m is the number of mines\r\n\n"
" Left mouse button: Open the square\r\n"
"Right mouse button: Mark the square\r\n"
" -The first time puts a 'mine' mark\r\n"
" -The second time puts a 'possible "
"mine' mark\r\n"
" -The third time unmarks the square\r\n"
"Left+Right buttons: Open the surrounded squares only if "
"the count of mines\r\n"
" is equal to the number in the square",argv[0])
exit (1)
}
switch (argc) {
case 4: m=atoi(argv[3])
case 3: y=atoi(argv[2])
case 2: x=atoi(argv[1])
}
}
XST=100
ncx=DEFCX
if (maxy==479) {
YST=30
ncy=DEFCY
}
else {
YST=25
ncy=20
}
if (x>0 &&x<ncx)
ncx=x
if (y>0 &&y<ncy) {
YST+=((ncy-y)*YPX)>>1
ncy=y
}
initmines= m ? m : ncx*ncy*4/25/* There are about 16% of mines */
if (((void near*)psquare=calloc(ncx*ncy, sizeof(STSQUARE)))==NULL) {
closegraph()
cputs("ERROR: Not enought memory")
exit(3)
}
} /* Read_param */
/*----------------------------------------------------------------------*/
void Set_mines(int nminas)
{
俄罗斯方快http://topic.csdn.net/t/20051201/01/4429905.html扫雷
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
struct list
{
int x
int y
int num
int bomb
int wa
}
struct list di[10][10]
int currentx=210
int currenty=130
void initxy(void)
{
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
{
di[j].x=i*20+200
di[j].y=j*20+120
di[j].wa=0
di[j].bomb=0
}
}
void initmu(void)
{
int i,j
setcolor(2)
rectangle(200,120,400,320)
rectangle(190,110,410,330)
setfillstyle(8,14)
floodfill(191,111,2)
for(i=0i<=9i++)
for(j=0j<=9j++)
rectangle(di[j].x,di[j].y,di[j].x+19,di[j].y+19)
outtextxy(450,200,"press 'enter' to kick")
outtextxy(450,250,"press '\' to mark")
}
void randbomb(void)
{
int k
int i,j
randomize()
for(i=0i<=9i++)
for(j=0j<=9j++)
{
k=random(5)
if(k==2)
di[j].bomb=1
}
}
void jisuan(void)
{
int k=0
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
{
if(i&&j&&di[i-1][j-1].bomb)
k=k+1
if(i&&di[i-1][j].bomb)
k=k+1
if(j&&di[j-1].bomb)
k=k+1
if(i<=8&&di[i+1][j].bomb)
k=k+1
if(j<=8&&di[j+1].bomb)
k=k+1
if(i<=8&&j<=8&&di[i+1][j+1].bomb)
k=k+1
if(i&&j<=8&&di[i-1][j+1].bomb)
k=k+1
if(i<=8&&j&&di[i+1][j-1].bomb)
k=k+1
di[j].num=k
k=0
}
}
void xianbomb(void)
{
int i,j
char biaoji[2]
char znum[2]
biaoji[0]=1
biaoji[1]=NULL
for(i=0i<=9i++)
for(j=0j<=9j++)
{
if(di[j].bomb==1)
outtextxy(di[j].x+2,di[j].y+2,biaoji)
else
{
itoa(di[j].num,znum,10)
setfillstyle(1,0)
bar(i*20+202,j*20+122,i*20+218,j*20+138)
outtextxy(i*20+202,j*20+122,znum)
}
}
}
void move(void)
{
int key
key=bioskey(1)
if(key)
key=bioskey(0)
if(key==0x4800)
{
if(currenty>130)
{
setcolor(0)
circle(currentx,currenty,5)
currenty-=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currenty=310
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x4b00)
{
if(currentx>210)
{
setcolor(0)
circle(currentx,currenty,5)
currentx-=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currentx=390
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x4d00)
{
if(currentx<390)
{
setcolor(0)
circle(currentx,currenty,5)
currentx+=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currentx=210
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x5000)
{
if(currenty<310)
{
setcolor(0)
circle(currentx,currenty,5)
currenty+=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currenty=130
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x1c0d)
{
int i,j
char snum[2]
snum[0]=NULL
snum[1]=NULL
i=(currentx-210)/20
j=(currenty-130)/20
if(di[j].bomb==1)
{
outtextxy(100,100,"game over")
xianbomb()
sleep(2)
exit(0)
}
if(di[j].bomb==0)
{
di[j].wa=1
setfillstyle(1,0)
bar(currentx-8,currenty-8,currentx+8,currenty+8)
setcolor(15)
itoa(di[j].num,snum,10)
outtextxy(currentx-8,currenty-8,snum)
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x2b5c)
{
char biaoji[2]
biaoji[0]=1
biaoji[1]=NULL
setcolor(0)
bar(currentx-8,currenty-8,currentx+8,currenty+8)
setcolor(4)
outtextxy(currentx-8,currenty-8,biaoji)
circle(currentx,currenty,5)
}
}
void success(void)
{
int k=1
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
if(di[j].bomb==0&&di[j].wa==0)
k=0
if(k==1)
{
outtextxy(100,100,"success good")
xianbomb()
sleep(2)
exit(0)
}
}
void main(void)
{
int gd=DETECT,gm
initgraph(&gd,&gm,"")
initxy()
initmu()
randbomb()
jisuan()
setcolor(4)
circle(210,130,5)
while(1)
{
move()
success()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)