标题:[推荐]扫雷的程序~~~
只看楼主
涛声依旧
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2005-3-5
 问题点数:0 回复次数:15 
[推荐]扫雷的程序~~~

# 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); }

搜索更多相关主题的帖子: define include 扫雷 BOOL 
2005-04-21 21:51
流浪魂
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2005-4-21
得分:0 
不错

何谓菜鸟?,呵呵,就是会吃菜的鸟。
2005-04-21 22:48
weizheng
Rank: 1
等 级:新手上路
威 望:2
帖 子:286
专家分:0
注 册:2005-4-21
得分:0 
经典,什么时候把一些更大的程序传上来,让看看。 比如是系统的,或者是一个大型软件的。

温和如玉,完美纯正。
2005-04-23 11:50
fuzi9128
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-12-8
得分:0 

收了谢谢:)

2005-12-10 13:13
layabout
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2005-12-2
得分:0 

用什么编的啊,界面怎么样,


学习不难!难的是一辈子兢兢业业,老老实实,勤勤恳恳的学习!!!
2005-12-10 13:58
layabout
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2005-12-2
得分:0 
能不能注释下啊????

学习不难!难的是一辈子兢兢业业,老老实实,勤勤恳恳的学习!!!
2005-12-10 14:03
fabio210
Rank: 1
等 级:新手上路
威 望:1
帖 子:58
专家分:0
注 册:2005-11-6
得分:0 
不错不错

2005-12-10 14:06
city505
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-11-5
得分:0 

太好了!

2005-12-10 16:21
独孤逍遥
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2005-9-25
得分:0 
怎么VC编译不过??

物以方圆 义薄云天 何以载物 四海纵横
2005-12-10 16:58
solocode
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-12-2
得分:0 

很好,谢谢~~

2005-12-10 17:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-16318-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.702618 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved