| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1808 人关注过本帖
标题:[求助] 哪位高手有扫雷的源程序啊??
只看楼主 加入收藏
dry2005
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-9-15
收藏
 问题点数:0 回复次数:8 
[求助] 哪位高手有扫雷的源程序啊??
小弟想要一个小游戏“扫雷”的源程序。有哪位有啊?可以 给我吗?我想研究研究。。。
搜索更多相关主题的帖子: 扫雷 
2005-09-16 00:22
liyanguestc
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2005-5-15
收藏
得分:0 

# 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网站http://www38.websamba.com/liyanguestc


2005-09-29 20:29
VFOX
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-10-9
收藏
得分:0 
简直太厉害了
编这么一个程序一定是C高手了
2005-10-10 15:50
yurec
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2005-7-5
收藏
得分:0 
收下。以后分析。
2005-10-10 17:22
socks
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2005-10-13
收藏
得分:0 
刚学了4天C,看不懂。

虔诚的初学者~~~
2005-10-14 01:15
mfkdx123
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-10-11
收藏
得分:0 
我学了二个月了还看不懂
2005-10-17 20:27
忆楠
Rank: 1
等 级:新手上路
帖 子:721
专家分:0
注 册:2004-7-5
收藏
得分:0 
这些东西google上应该都能搜到~~

建议多使用搜索器~~不懂不知道的就去搜~

点 鼠 标 , 救 饥 民 http://www./
2005-10-17 22:51
dvsb
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-11
收藏
得分:0 
我怎么运行不了阿
2008-10-11 17:23
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
这个估计只能用tc才能运行吧。。调用int 0x33鼠标中断

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-10-11 20:55
快速回复:[求助] 哪位高手有扫雷的源程序啊??
数据加载中...
 
   



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

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