C#实现的Windows扫雷的辅助程序
这个小程序可以实现自动扫雷,只是娱乐和学习之用,没别的用途,大家勿骂。
我没有改变计时器,想必大家都知道系统自带一个方便扫雷的功能就是“XYZZY shift”这时屏幕的(0,0)像素若是白点则是安全的,若是黑点则是有雷。所以就可以用程序实现之:
1。打开扫雷
2。发送“XYZZY shift”给扫雷程序
3。判断屏幕(0,0)点的颜色
4。模拟鼠标点击。
_________________________________________________________________
程序运行效果
自动扫雷 下载
以下是程序代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Collections.Generic;
namespace 扫雷辅助
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int i = 0;
public int flag = 0;
public int BoomCount_x = 9;//横向雷数
public int BoomCout_y = 9;//纵向雷数
public int offset_x = 22;
public int offset_y = 110;
public int delay = 0;
//调用API
调用APT申明
private bool IsBoom()//判断有没有雷
{
Bitmap img = new Bitmap(1,1);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(1,1));
Color color = img.GetPixel(0,0);
//if (color == Color.Black)
// return true;
//else
// return false;
img.Dispose();
g.Dispose();
if (color.R == 255)//White
{
return false;
}
else
{
return true;
}
}
private Point endPostion;
public void SetLabelText(int x, int y)// 用一个label标签显示雷的位置
{
for (int j = 0; j < x; j++)
{
for (int i = 0; i < y; i++)
{
label1.Text += "○";
}
label1.Text += "\n";
}
}
private void button1_Click(object sender, EventArgs e)//自动扫雷按钮
{
NativeRect rect;
IntPtr winmineHandle = FindWindow("扫雷","扫雷");//找到扫雷游戏窗口
if (winmineHandle == IntPtr.Zero)
{
MessageBox.Show("没有找到扫雷窗口");
return;
}
else
{
//发送按键
SetForegroundWindow(winmineHandle);
SendKeys.SendWait("X");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Shift");
GetWindowRect(new HandleRef(this, winmineHandle), out rect);//得到窗口矩形
endPostion.X = rect.left +offset_x;//偏移坐标,用于找到第一个方块的位置
endPostion.Y = rect.top + offset_y;
SetCursorPos(endPostion.X, endPostion.Y);//设置鼠标位置
//模拟一次鼠标点击
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
label1.Text = "";
SetCursorPos(endPostion.X, endPostion.Y);
progressBar1.Value = 0;
for (int j = 0; j < BoomCount_x; j++)
{
for (int i = 0; i < BoomCout_y; i++)
{
progressBar1.Value++;
System.Threading.Thread.Sleep(delay);
SetCursorPos(endPostion.X + 16 * i, endPostion.Y + 16 * j);
if (!IsBoom())
{
label1.Text += "○";
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}
else
{
label1.Text += "●";
//mouse_event(MouseEventFlag.RightDown, 0, 0, 0, UIntPtr.Zero);
//mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
}
}
label1.Text += "\n";
}
}
}
private void button2_Click(object sender, EventArgs e)//打开扫雷 按钮
{
//判断是否启动扫雷程序
Process p = new Process();
p.StartInfo.FileName = "winmine.exe";
p.Start();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_MouseMove(object sender, MouseEventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
label2.Text += "\n打开扫雷后设置相应等级,软件等级\n与游戏等级相一致.然后再点\n\"自动扫雷\"即可.\n注意:扫雷过程中鼠标别乱动..\n当然失败也是正常的\n屡次失败请点图像试试";
SetLabelText(BoomCount_x,BoomCout_y);
}
private void pictureBox1_Click(object sender, EventArgs e)//由发送一次xyzzy shift是开启扫雷的//作弊,再发送一次是关闭作弊,这个图片的点击事件专门用来发送按键,在不能正常使用的时候开启作弊
{
IntPtr winmineHandle = FindWindow("扫雷", "扫雷");
if (winmineHandle == IntPtr.Zero)
{
MessageBox.Show("扫雷没打开不要乱点--!");
return;
}
else
{
SetForegroundWindow(winmineHandle);
SendKeys.SendWait("X");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Shift");
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)//中级扫雷
{
BoomCount_x = 16;
BoomCout_y = 16;
this.Width = 450;
progressBar1.Minimum = 0;
progressBar1.Maximum = 256;
label1.Text = "";
SetLabelText(16, 16);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)//初级扫雷
{
this.Width=370;
BoomCount_x = 9;
BoomCout_y = 9;
progressBar1.Minimum = 0;
progressBar1.Maximum = 81;
label1.Text = "";
SetLabelText(9, 9);
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)//高级扫雷
{
this.Width = 640;
BoomCount_x = 16;
BoomCout_y = 30;
progressBar1.Minimum =0;
progressBar1.Maximum = 480;
label1.Text = "";
SetLabelText(16,30);
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
delay= hScrollBar1.Value;
}
private void button3_Click_1(object sender, EventArgs e)
{
AboutBox ab = new AboutBox();
ab.ShowDialog();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Collections.Generic;
namespace 扫雷辅助
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int i = 0;
public int flag = 0;
public int BoomCount_x = 9;//横向雷数
public int BoomCout_y = 9;//纵向雷数
public int offset_x = 22;
public int offset_y = 110;
public int delay = 0;
//调用API
调用APT申明
private bool IsBoom()//判断有没有雷
{
Bitmap img = new Bitmap(1,1);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(1,1));
Color color = img.GetPixel(0,0);
//if (color == Color.Black)
// return true;
//else
// return false;
img.Dispose();
g.Dispose();
if (color.R == 255)//White
{
return false;
}
else
{
return true;
}
}
private Point endPostion;
public void SetLabelText(int x, int y)// 用一个label标签显示雷的位置
{
for (int j = 0; j < x; j++)
{
for (int i = 0; i < y; i++)
{
label1.Text += "○";
}
label1.Text += "\n";
}
}
private void button1_Click(object sender, EventArgs e)//自动扫雷按钮
{
NativeRect rect;
IntPtr winmineHandle = FindWindow("扫雷","扫雷");//找到扫雷游戏窗口
if (winmineHandle == IntPtr.Zero)
{
MessageBox.Show("没有找到扫雷窗口");
return;
}
else
{
//发送按键
SetForegroundWindow(winmineHandle);
SendKeys.SendWait("X");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(10);
SendKeys.SendWait("Shift");
GetWindowRect(new HandleRef(this, winmineHandle), out rect);//得到窗口矩形
endPostion.X = rect.left +offset_x;//偏移坐标,用于找到第一个方块的位置
endPostion.Y = rect.top + offset_y;
SetCursorPos(endPostion.X, endPostion.Y);//设置鼠标位置
//模拟一次鼠标点击
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
label1.Text = "";
SetCursorPos(endPostion.X, endPostion.Y);
progressBar1.Value = 0;
for (int j = 0; j < BoomCount_x; j++)
{
for (int i = 0; i < BoomCout_y; i++)
{
progressBar1.Value++;
System.Threading.Thread.Sleep(delay);
SetCursorPos(endPostion.X + 16 * i, endPostion.Y + 16 * j);
if (!IsBoom())
{
label1.Text += "○";
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}
else
{
label1.Text += "●";
//mouse_event(MouseEventFlag.RightDown, 0, 0, 0, UIntPtr.Zero);
//mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
}
}
label1.Text += "\n";
}
}
}
private void button2_Click(object sender, EventArgs e)//打开扫雷 按钮
{
//判断是否启动扫雷程序
Process p = new Process();
p.StartInfo.FileName = "winmine.exe";
p.Start();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_MouseMove(object sender, MouseEventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
label2.Text += "\n打开扫雷后设置相应等级,软件等级\n与游戏等级相一致.然后再点\n\"自动扫雷\"即可.\n注意:扫雷过程中鼠标别乱动..\n当然失败也是正常的\n屡次失败请点图像试试";
SetLabelText(BoomCount_x,BoomCout_y);
}
private void pictureBox1_Click(object sender, EventArgs e)//由发送一次xyzzy shift是开启扫雷的//作弊,再发送一次是关闭作弊,这个图片的点击事件专门用来发送按键,在不能正常使用的时候开启作弊
{
IntPtr winmineHandle = FindWindow("扫雷", "扫雷");
if (winmineHandle == IntPtr.Zero)
{
MessageBox.Show("扫雷没打开不要乱点--!");
return;
}
else
{
SetForegroundWindow(winmineHandle);
SendKeys.SendWait("X");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Z");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Y");
System.Threading.Thread.Sleep(5);
SendKeys.SendWait("Shift");
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)//中级扫雷
{
BoomCount_x = 16;
BoomCout_y = 16;
this.Width = 450;
progressBar1.Minimum = 0;
progressBar1.Maximum = 256;
label1.Text = "";
SetLabelText(16, 16);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)//初级扫雷
{
this.Width=370;
BoomCount_x = 9;
BoomCout_y = 9;
progressBar1.Minimum = 0;
progressBar1.Maximum = 81;
label1.Text = "";
SetLabelText(9, 9);
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)//高级扫雷
{
this.Width = 640;
BoomCount_x = 16;
BoomCout_y = 30;
progressBar1.Minimum =0;
progressBar1.Maximum = 480;
label1.Text = "";
SetLabelText(16,30);
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
delay= hScrollBar1.Value;
}
private void button3_Click_1(object sender, EventArgs e)
{
AboutBox ab = new AboutBox();
ab.ShowDialog();
}
}
}
以上只做了初级中级高级三种情况 , 稍为作改一下就可以任意雷.
这几天有些事没有时间把代码用时传上来,没有卖关子的意思,请大家谅解.