⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse.h

📁 有点类似于Windows的扫雷小游戏
💻 H
字号:
# if !defined(__CONIO_H)
# include <conio.h>
# endif

# if !defined(__DOS_DEF_)
# include <dos.h>
# endif

# if !defined( __STDIO_H )
# include <stdio.h>
# endif

# if !defined( __STDLIB_H )
# include <stdlib.h>
# endif

# if !defined( __GRAPHICS_H )
# include <graphics.h>
# endif

# if !defined( BYTE )
# define BYTE  unsigned char
# endif
# if !defined( WORD )
# define WORD  unsigned int
# endif
# if !defined( DWORD )
# define DWORD unsigned long
# endif
# if !defined( BOOL )
# define BOOL  unsigned char
# endif
# if !defined( TRUE )
# define TRUE  1
# endif
# if !defined( FALSE )
# define FALSE 0
# endif

# define MOUSE          0x33
# define ARROWWIDTH     19
# define ARROWLENGTH    11
/*----------------------------------------------------------*/
int           nowx=160,nowy=100;
int           oldx,oldy;
int           old_state,now_state=0;
char          buf[ARROWWIDTH][ARROWLENGTH];
char          arrow[ARROWWIDTH][ARROWLENGTH]=
	 {00,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
	  00,00,-1,-1,-1,-1,-1,-1,-1,-1,-1,
	  00,15,00,-1,-1,-1,-1,-1,-1,-1,-1,
	  00,15,15,00,-1,-1,-1,-1,-1,-1,-1,
	  00,15,15,15,00,-1,-1,-1,-1,-1,-1,
	  00,15,15,15,15,00,-1,-1,-1,-1,-1,
	  00,15,15,15,15,15,00,-1,-1,-1,-1,
	  00,15,15,15,15,15,15,00,-1,-1,-1,
	  00,15,15,15,15,15,15,15,00,-1,-1,
	  00,15,15,15,15,15,15,15,15,00,-1,
	  00,15,15,15,15,00,00,00,00,00,00,
	  00,15,15,00,15,15,00,-1,-1,-1,-1,
	  00,15,00,00,15,15,00,-1,-1,-1,-1,
	  00,00,-1,-1,00,15,15,00,-1,-1,-1,
	  00,-1,-1,-1,00,15,15,00,-1,-1,-1,
	  -1,-1,-1,-1,-1,00,15,15,00,-1,-1,
	  -1,-1,-1,-1,-1,00,15,15,00,-1,-1,
	  -1,-1,-1,-1,-1,-1,00,00,00,-1,-1,
	  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
          };
/*----------------------------------------------------------*/
void drawarrow(int x,int y)
{
  int xx,yy;
  for (xx=0;xx<ARROWWIDTH;xx++)
     for (yy=0;yy<ARROWLENGTH;yy++)
	if (arrow[xx][yy]!=-1)putpixel(x+yy,y+xx,arrow[xx][yy]);
}
void getpic(int x,int y,BYTE *buf)
{
  int xx,yy;
  for(yy=0;yy<ARROWWIDTH;yy++)
     for(xx=0;xx<ARROWLENGTH;xx++)
	*(buf++)=getpixel(x+xx,y+yy);
}
void putpic(int x,int y,BYTE *buf)
{
  int xx,yy;
  for(yy=0;yy<ARROWWIDTH;yy++)
     for(xx=0;xx<ARROWLENGTH;xx++)
	putpixel(x+xx,y+yy,*(buf++));
}
void hide()
{
  putpic(nowx,nowy,*buf);
}
void show()
{
  getpic(nowx,nowy,*buf);
  drawarrow(nowx,nowy);
}
int MouseState()
{
  union REGS regs;
  regs.x.ax = 3;
  int86(MOUSE, &regs, &regs);
  return(regs.x.bx);
}
void Set_Range(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 Mouse_Reset()
{
  union REGS regs;
  regs.x.ax = 0;
  int86(MOUSE, &regs, &regs);
  if (! regs.x.ax)
  {
     printf("Mousedriver not installed.");
     exit(0);
  }
  Set_Range(0,0,319,199);
}
void Get_XY(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 Set_XY(int x,int y)
{
  union REGS ireg;
  ireg.x.ax=4;
  ireg.x.cx=x;
  ireg.x.dx=y;
  int86(MOUSE,&ireg,&ireg);
}
/*----------------------------------------------------------*/
/***************
 Mouse_Reset();
 Set_Range(0,0,639,479);
 nowx=320;nowy=240;
 Set_XY(nowx,nowy);
 show();
 while(1)
  {oldx=nowx;oldy=nowy;old_state=now_state;
   Get_XY(&nowx,&nowy);
   now_state=MouseState();
   if(nowx!=oldx||nowy!=oldy)
      {putpic(oldx,oldy,*buf);show();}
   delay(100);
   }
*************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -