当前位置: 代码迷 >> C语言 >> 求助高手指点C程序
  详细解决方案

求助高手指点C程序

热度:234   发布时间:2004-12-31 08:58:00.0
求助高手指点C程序
我有一个扫雷的C程序作业老师让在游戏开始前加上自定义 雷的数目,我刚学了不久,不会啊,求各位高手指点一下,感激不尽
----------------解决方案--------------------------------------------------------

为什么叫你题还要积分??? 抱怨 # include <dos.h> # include <time.h> # include <stdio.h> # include <stdlib.h>

# define BYTE unsigned char # define BOOL BYTE # define WORD unsigned int # define DWORD unsigned long

# define TRUE 1 # define FALSE !TRUE

# define MOUSE 0x33 # define LBUTTON 1 # define RBUTTON 2 # define SX 35 # define SY 7

# define MINE 9

BOOL InitMouse(); BYTE Scr(int,int); BYTE MouseState(); void Edge(int,int); void TurnBack(int,int); void InitArrow(); void InitCursor(); void MouseShow(); void MouseHide(); void CursorShow(); void CursorHide(); void SetRange(int,int,int,int); void GetXY(int*,int*); void SetXY(int,int); void WaitMouse(); void WaitKey(); void Prt(int,int,BYTE,BYTE); void Locate(BYTE,BYTE); void FailExitGame(); void ExitGame();

BOOL Turn[10][10]; BYTE Mine[10][10]; BYTE Mark[10][2]; WORD CursorMode; int x,y;

void main() { int i; int Total=0; BYTE Button; BOOL QUIT=FALSE;

if (!InitMouse()) { printf("Mouse not installed!"); exit(0); } clrscr(); CursorHide();

/* InitArrow(); InitCursor(); */

randomize(); Locate(36,20); printf("Mines:%d ",0);

for (y=0;y<10;y++) for (x=0;x<10;x++) { Mine[y][x]=NULL; Turn[y][x]=FALSE; }

for (i=0;i<10;i++) { x=random(10); y=random(10); while (Mine[y][x]) { x=random(10); y=random(10); } Mine[y][x]=MINE; }

for (y=0;y<10;y++) for (x=0;x<10;x++) { i=0; if (Mine[y][x]!=MINE) { if ((Mine[y][x-1]==MINE)&&((x-1)>=0)) i++; if ((Mine[y][x+1]==MINE)&&((x+1)<10)) i++; if ((Mine[y-1][x]==MINE)&&((y-1)>=0)) i++; if ((Mine[y+1][x]==MINE)&&((y+1)<10)) i++; if ((Mine[y-1][x-1]==MINE)&&((x-1)>=0)&&((y-1)>=0)) i++; if ((Mine[y-1][x+1]==MINE)&&((x+1)<10)&&((y-1)>=0)) i++; if ((Mine[y+1][x+1]==MINE)&&((x+1)<10)&&((y+1)<10)) i++; if ((Mine[y+1][x-1]==MINE)&&((x-1)>=0)&&((y+1)<10)) i++; Mine[y][x]=i; } Prt(x+SX,y+SY,'?',9) ; }

MouseShow(); while(!QUIT) { if (kbhit()) if (getch()==27) QUIT=TRUE; Button=MouseState()&3; if (Button) { GetXY(&x,&y); WaitMouse(); x>>=3; y>>=3; x-=SX; y-=SY; if (x>=0&&x<10&&y>=0&&y<10) { if (Button&LBUTTON) { if (Mine[y][x]==MINE) FailExitGame(); if (Mine[y][x]==NULL) Edge(x,y); else TurnBack(x,y); } if (Button&RBUTTON) { if (!(Turn[y][x]&1)) { switch (Turn[y][x]) { case 0: Turn[y][x]=2; MouseHide(); Prt(x+SX,y+SY,'*',15); Locate(36,20); printf("Mines:%d ",++Total); MouseShow(); Mark[Total][0]=x; Mark[Total][1]=y; if (Total==10) ExitGame(); break; case 2: Turn[y][x]=0; MouseHide(); Prt(x+SX,y+SY,'?',9) ; Locate(36,20); printf("Mines:%d ",--Total); MouseShow(); break; } } } } } } WaitKey(); MouseHide(); CursorShow(); }

BYTE MouseState() { union REGS regs; regs.x.ax = 3; int86(MOUSE, &regs, &regs); return(regs.x.bx); }

void MouseShow() { union REGS regs; regs.x.ax = 1; int86(MOUSE, &regs, &regs); }

void MouseHide() { union REGS regs; regs.x.ax = 2; int86(MOUSE, &regs, &regs); }

void InitArrow() { /* BYTE shape[16]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xf0,0xd8,0x98,0x0c,0x0c,0x06,0x07,0x03}; D(_DS,shape,3,1); */ }

void InitCursor() { union REGS regs; regs.x.ax = 10; regs.x.bx = 0; regs.x.cx = 0; regs.x.dx = (7 * 16 + 15) * 256 +3; int86(MOUSE, &regs, &regs); }

BOOL InitMouse() { union REGS regs; regs.x.ax = 0; int86(MOUSE, &regs, &regs); return (regs.x.ax); } void SetRange(int start_x,int start_y,int end_x,int end_y) { union REGS r; r.x.ax=7; r.x.cx=start_x; r.x.dx=end_x; int86(0x33,&r,&r); r.x.ax=8; r.x.cx=start_y; r.x.dx=end_y; int86(MOUSE,&r,&r); } void GetXY(int *x,int *y) { union REGS ireg,oreg; ireg.x.ax=3; int86(MOUSE,&ireg,&oreg); *x=oreg.x.cx; *y=oreg.x.dx; } void SetXY(int x,int y) { union REGS ireg; ireg.x.ax=4; ireg.x.cx=x; ireg.x.dx=y; int86(MOUSE,&ireg,&ireg); }

/* Waiting for releasing the mouse button */ void WaitMouse() { int xx,yy; while (MouseState()) { GetXY(&xx,&yy); if (xx!=x||yy!=y) SetXY(x,y); } }

void Prt(int x,int y,BYTE ch,BYTE color) { pokeb(0xb800,y*160+x*2,ch); pokeb(0xb800,y*160+x*2+1,color); }

BYTE Scr(int x,int y) { return peekb(0xb800,y*160+x*2); }

void CursorHide() { _AH=3; geninterrupt(0x10); CursorMode=_CX; _AH=1; _CH=32; geninterrupt(0x10); } void CursorShow() { _AH=1; _CX=CursorMode; geninterrupt(0x10); }

void WaitKey() { _AH=0; geninterrupt(0x16); }

void Edge(int xx,int yy) { if (xx<0||xx>9||yy<0||yy>9||Turn[yy][xx]) return; TurnBack(xx,yy); if (Mine[yy][xx]==NULL) { Edge(xx+1,yy); Edge(xx-1,yy); Edge(xx,yy+1); Edge(xx,yy-1); } }

void TurnBack(int xx,int yy) { if (!Turn[yy][xx]) { MouseHide(); Prt(xx+SX,yy+SY,Mine[yy][xx]+48,12); MouseShow(); Turn[yy][xx]=Turn[yy][xx]||1; } }

void Locate(BYTE Col,BYTE Line) { pokeb(0x0,0x450,Col); pokeb(0x0,0x451,Line); }

void FailExitGame() { sound(1000); delay(500); nosound(); for (y=0;y<10;y++) for (x=0;x<10;x++) if (Mine[y][x]==MINE) Prt(x+SX,y+SY,'*',14+128); MouseHide(); CursorShow(); printf("\nFail!\n"); exit(0); }

void ExitGame() { int i,m=0; for (i=0;i<10;i++) if (Mine[Mark[i][1]][Mark[i][0]]) m++; if (m<9) FailExitGame(); MouseHide(); CursorShow(); printf("\nOK,Good!\n"); exit(0); }


----------------解决方案--------------------------------------------------------
真是高手啊!
随便问问,C都能用于什么场合啊!
----------------解决方案--------------------------------------------------------
这么长。。是自己写的吗
我可不行啊~!
----------------解决方案--------------------------------------------------------
c什么都能做,看你是不是钻研了
----------------解决方案--------------------------------------------------------
是呀是呀,但我们很就容易地就做一个windows应用程序吗?至少我们做一个在windows环境下运行的程序,用C语言太麻烦了,不如用C的超集C++或者C#了
----------------解决方案--------------------------------------------------------
  相关解决方案