近来无事,写个连连看辅助,下面先说下思路吧(口才不行,见谅哈)

游戏辅助有三种方法,一种是读内存,这个不知道怎么分析,还有一种是获取封包,这个分析起来复杂,最后一种是图片识别再分析,这里采用最后一种 图片识别来做。

设计UI如下

连连看开始》启动辅助》得到游戏窗口信息(位置,大小)》将游戏窗口置顶(其实就是激活状态),并恢复默认状态》截取整个屏幕保存起来》得到游戏区域的坐标信息》分割游戏区域将每一块的大小,位置,并在其上面取9个点的颜色值,存入到List<List<T>>中(同时判断是不是背景色,背景判断是求9个点的颜色平均值,如果每个点和平均值相差5以内就认定是背景)》循环List<List<T>>开始识别

 

下面说下识别时候的思路

先给个图片

我们都知道连连看最多只可以拐2次

假设红色方块是开始位置,先向左一个方格,得到方格,如果是背景或者是已经消除了的,则检测上方,如果是没有消除的,则判定是不是一样的,

然后向下取一个方格,这时候已经拐了1次了,然后判断这个方格的左侧,然后右侧,然后下侧

按照图上的解释下

得到1是背景则向上,不是背景,判断和目标方块不一样,则向下得到3,是背景,则查看3的左侧,是背景,再左侧,是背景,再….查看到尽头是背景(这个地方为什么不看上下了呢?因为这个时候已经拐了2次了),然后看右侧,得到5,是背景,再右侧…到尽头是背景,然后还是继续向下得到6,是背景,然后看6的左右,依次类推,如果1的下方都没有找到 ,那么继续向左找,得到7,看7的上下,依次类推

 

 

本来我是打算使用大漠插件做的 ,但是遇到2个问题:1、采集图片信息太慢,每个方块9个点,采集19*11个方块竟然用了40多S(也可能是我没有找到合适的方法),2、识别后点击的时候快速移动并点击多次会报错

所以我准备自己调用user32.dll的方法来实现

 

另外,你需要开启连连看游戏,截屏一个图片,然后创建一个解决方案将这个图片放到窗体上,模拟一个游戏窗口,你总不能编写的时候 一会启动一下游戏吧,测试可以用你这个窗口来,等写好后最后测试再用QQ游戏测试下效果

 

新建一个winform方案,再这个方案想再添加一个专案,就是上面提到的那个测试窗体,就是拉一个picbox放图片,窗体样式设为none效果如下图,

这里你还要得到一个数据,就是窗口左上角到上图红点位置的xy坐标值

我使用根据进程获取句柄,后来发现连连看进程名字会改变,所以需要在config.txt里面配置下  或者修改根据窗口名字获得句柄

然后下面介绍下各个类的作用

Form1  主窗体

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Text;
  7 using System.Windows.Forms;
  8 using System.Threading;
  9 using System.Diagnostics;
 10 using System.IO;
 11 
 12 namespace LianLianHelp
 13 {
 14     public partial class Form1 : Form
 15     {
 16         public static int SleepTime = 10;
 17         private bool isstop = true;
 18         private bool isstart = false;
 19         string gamename = "KYODAI~1";
 20         public Form1()
 21         {
 22             InitializeComponent();
 23             // dm.SetPath(Application.StartupPath + "\\aa");
 24         }
 25         Point gamePoint1 = new Point();
 26         private void button1_Click(object sender, EventArgs e)
 27         {
 28 
 29             this.button1.Enabled = false;
 30             // Start();
 31             Thread th = new Thread(Start);
 32             th.IsBackground = true;
 33             th.Start();
 34         }
 35 
 36         private void Start()
 37         {
 38             isstart = true;
 39             isstop = false;
 40             LianLianHelp.LianLelp.ClearList();
 41             GetGamePanel();
 42             GetNodes();
 43             try
 44             {
 45                 StarCheckNode();
 46             }
 47             catch
 48             { }
 49             isstart = false;
 50             isstop = true;
 51             this.button1.BeginInvoke(new MethodInvoker(delegate()
 52             {
 53                 button1.Enabled = true;
 54             }));
 55         }
 56 
 57         /// <summary>
 58         /// 得到游戏信息
 59         /// </summary>
 60         private void GetGamePanel()
 61         {
 62             //YodaoDict    LianLianDemo
 63             // Process[] ps = Process.GetProcessesByName("KYODAI~1");
 64             Process[] ps = Process.GetProcessesByName(gamename);
 65             IntPtr lianlian_hwnd = ps[0].MainWindowHandle;
 66             //  int lianlian_hwnd = dm.FindWindow("", "QQ游戏 - 连连看角色版");
 67 
 68             Point mousepoint = LianLianHelp.GetMousePoint();
 69             LianLianHelp.ShowWindow(lianlian_hwnd, 1);
 70             LianLianHelp.SetForegroundWindow(lianlian_hwnd);
 71             // dm.GetCursorPos(ref x, ref y);
 72             //dm.SetWindowState(lianlian_hwnd, 1);
 73             // dm.MoveTo(0, 0);
 74             LianLianHelp.MoveMouse(0, 0);
 75             //LianLianHelp.SetWindowSize();
 76             LianLianHelp.LianLelp.PrintScreen(Application.StartupPath + "\\screen.jpg");
 77             // dm.CaptureJpg(0, 0, dm.GetScreenWidth(), dm.GetScreenHeight(), "screen.jpg", 100);
 78             LianLianHelp.MoveMouse(mousepoint.X, mousepoint.Y);
 79             // dm.MoveTo((int)x, (int)y);
 80             //得到窗口大小
 81             int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
 82             LianLianHelp.GetWindowRects(lianlian_hwnd, ref x1, ref y1, ref x2, ref y2);
 83             gamePoint1 = new Point((int)x1 + HelpSource.game_offset.X, (int)y1 + HelpSource.game_offset.Y);
 84         }
 85 
 86         /// <summary>
 87         /// 得到游戏图片方块
 88         /// </summary>
 89         private void GetNodes()
 90         {
 91             int x = gamePoint1.X;
 92             int y = gamePoint1.Y;
 93 
 94             Bitmap bitmap = new Bitmap(Application.StartupPath + "\\screen.jpg");
 95             for (int j = 0; j < 19; j++)
 96             {
 97                 int _x = x + HelpSource.pieceSize.Width * j;
 98 
 99                 List<LianLianClass> lclist = new List<LianLianClass>();
100                 for (int i = 0; i < 11; i++)
101                 {
102                     int _y = y + HelpSource.pieceSize.Height * i;
103                     LianLianClass lc = new LianLianClass();
104 
105                     int xindex = _x + 10;
106                     int[] _corlrs = new int[9];
107                     int cindex = 0;
108                     for (int m = 0; m < 3; m++)
109                     {
110                         int yindex = _y + 10;
111                         for (int n = 0; n < 3; n++)
112                         {
113                             Color color = bitmap.GetPixel(xindex, yindex);
114 
115                             int r = Convert.ToInt32(color.R);
116                             int g = Convert.ToInt32(color.G);
117                             int b = Convert.ToInt32(color.B);
118                             //string colorstr = dm.GetColor(xindex, yindex);
119                             //int _colorcount = Getcolor(colorstr);
120                             _corlrs[cindex] = r + g + b;
121                             yindex += 5;
122                             cindex++;
123                         }
124                         xindex += 5;
125                     }
126                     int colorcount = 0;
127                     lc.IsBackgrpund = CheckValue(_corlrs, ref colorcount);
128                     lc.ThisPoint = new Point(_x + 15, _y + 15);
129                     lc.ListPoint = new Point(j, i);
130                     lc.ColorNumCount = _corlrs;
131                     lclist.Add(lc);
132                 }
133                 LianLianHelp.LianLelp.LianList.Add(lclist);
134             }
135             bitmap.Dispose();
136         }
137 
138         private void StarCheckNode()
139         {
140             List<List<LianLianClass>> lianList = LianLianHelp.LianLelp.LianList;
141             while (true)
142             {
143                 for (int x = 0; x < 19; x++)
144                 {
145                     for (int y = 0; y < 11; y++)
146                     {
147                         if (lianList[x][y].IsBackgrpund || lianList[x][y].Ismove)
148                             continue;
149                         thisllc = lianList[x][y];
150 
151                         //  thisllc.ListPoint = new Point(x, y);
152                         if (!CheckNode(thisllc, 0, NODETYPE.SOURCENODE, TODIRECTION.LEFT))
153                             if (!CheckNode(thisllc, 0, NODETYPE.SOURCENODE, TODIRECTION.UP))
154                                 if (!CheckNode(thisllc, 0, NODETYPE.SOURCENODE, TODIRECTION.RIGHT))
155                                     CheckNode(thisllc, 0, NODETYPE.SOURCENODE, TODIRECTION.DOWN);
156                     }
157                 }
158                 if (LianLianHelp.LianLelp.CheckISOK())
159                 {
160                     break;
161                 }
162             }
163         }
164         LianLianClass thisllc = null;
165         LianLianClass checkllc = null;
166         /// <summary>
167         /// 
168         /// </summary>
169         /// <param name="lc">当前位置方块</param>
170         /// <param name="checkindex">第几个转弯,</param>
171         /// <param name="nodeType">lc类型</param>
172         /// <param name="toDirection">方向</param>
173         private bool CheckNode(LianLianClass lc, int checkindex, NODETYPE nodeType, TODIRECTION toDirection)
174         {
175             if (isstop)
176             {
177                 throw new Exception();
178             }
179             if (checkindex > 2)
180                 return false;
181             if (toDirection == TODIRECTION.LEFT)
182             {
183                 #region left
184                 LianLianClass _lc = LianLianHelp.LianLelp.GetNextLLC(lc.ListPoint.X, lc.ListPoint.Y, toDirection);
185                 if (_lc == null)
186                     return false;
187                 if (_lc.ListPoint == thisllc.ListPoint)
188                     return false;
189                 if (_lc.IsBackgrpund || _lc.Ismove)
190                 {
191                     int _c = checkindex + 1;
192                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.UP))
193                     {
194                         return true;
195                     }
196                     _c = checkindex + 1;
197                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.DOWN))
198                     {
199                         return true;
200                     }
201                     else
202                     {
203                         _c = checkindex;
204                         return CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.LEFT);
205                     }
206                 }
207                 else
208                 {
209                     if (LianLianHelp.LianLelp.Isalike(_lc, thisllc))
210                     {
211                         ClickNode(_lc, thisllc);
212                         return true;
213                     }
214                     else
215                         return false;
216                 }
217                 #endregion
218             }
219             else if (toDirection == TODIRECTION.RIGHT)
220             {
221                 LianLianClass _lc = LianLianHelp.LianLelp.GetNextLLC(lc.ListPoint.X, lc.ListPoint.Y, toDirection);
222                 if (_lc == null)
223                     return false;
224                 if (_lc.ListPoint == thisllc.ListPoint)
225                     return false;
226                 if (_lc.IsBackgrpund || _lc.Ismove)
227                 {
228                     int _c = checkindex + 1;
229                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.UP))
230                     {
231                         return true;
232                     }
233                     _c = checkindex + 1;
234                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.DOWN))
235                     {
236                         return true;
237                     }
238                     else
239                     {
240                         _c = checkindex;
241                         return CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.RIGHT);
242                     }
243                 }
244                 else
245                 {
246                     if (LianLianHelp.LianLelp.Isalike(_lc, thisllc))
247                     {
248                         ClickNode(_lc, thisllc);
249                         return true;
250                     }
251                     else
252                         return false;
253                 }
254             }
255             else if (toDirection == TODIRECTION.UP)
256             {
257                 LianLianClass _lc = LianLianHelp.LianLelp.GetNextLLC(lc.ListPoint.X, lc.ListPoint.Y, toDirection);
258                 if (_lc == null)
259                     return false;
260                 if (_lc.ListPoint == thisllc.ListPoint)
261                     return false;
262                 if (_lc.IsBackgrpund || _lc.Ismove)
263                 {
264                     int _c = checkindex + 1;
265                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.LEFT))
266                     {
267                         return true;
268                     }
269                     _c = checkindex + 1;
270                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.RIGHT))
271                     {
272                         return true;
273                     }
274                     else
275                     {
276                         _c = checkindex;
277                         return CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.UP);
278                     }
279                 }
280                 else
281                 {
282                     if (LianLianHelp.LianLelp.Isalike(_lc, thisllc))
283                     {
284                         ClickNode(_lc, thisllc);
285                         return true;
286                     }
287                     else
288                         return false;
289                 }
290             }
291             else
292             {
293                 LianLianClass _lc = LianLianHelp.LianLelp.GetNextLLC(lc.ListPoint.X, lc.ListPoint.Y, toDirection);
294                 if (_lc == null)
295                     return false;
296                 if (_lc.ListPoint == thisllc.ListPoint)
297                     return false;
298                 if (_lc.IsBackgrpund || _lc.Ismove)
299                 {
300                     int _c = checkindex + 1;
301                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.LEFT))
302                     {
303                         return true;
304                     }
305                     _c = checkindex + 1;
306                     if (CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.RIGHT))
307                     {
308                         return true;
309                     }
310                     else
311                     {
312                         _c = checkindex;
313                         return CheckNode(_lc, _c, NODETYPE.OTHERNODE, TODIRECTION.DOWN);
314                     }
315                 }
316                 else
317                 {
318                     if (LianLianHelp.LianLelp.Isalike(_lc, thisllc))
319                     {
320                         ClickNode(_lc, thisllc);
321                         return true;
322                     }
323                     else
324                         return false;
325                 }
326             }
327 
328         }
329 
330         private bool CheckValue(int[] values, ref  int count)
331         {
332             foreach (int i in values)
333             {
334                 count += i;
335             }
336             int _index = count / values.Length;
337             foreach (int i in values)
338             {
339                 if (Math.Abs(i - _index) >= 5)
340                 {
341                     return false;
342                 }
343             }
344             return true;
345         }
346 
347         private void ClickNode(LianLianClass lc1, LianLianClass lc2)
348         {
349             lc1.Ismove = true;
350             lc2.Ismove = true;
351             LianLianHelp.MoveMouse(lc1.ThisPoint.X, lc1.ThisPoint.Y);
352             Thread.Sleep(100);
353             LianLianHelp.LeftClick(lc1.ThisPoint.X, lc1.ThisPoint.Y);
354             Thread.Sleep(100);
355             LianLianHelp.MoveMouse(lc2.ThisPoint.X, lc2.ThisPoint.Y);
356             Thread.Sleep(100);
357             LianLianHelp.LeftClick(lc2.ThisPoint.X, lc2.ThisPoint.Y);
358             Thread.Sleep(SleepTime);
359             Console.WriteLine("Click(" + lc1.ListPoint.X + "," + lc1.ListPoint.Y + ") and (" + lc2.ListPoint.X + "," + lc2.ListPoint.Y + ")");
360         }
361 
362         private void button2_Click(object sender, EventArgs e)
363         {
364             Application.Exit();
365         }
366 
367         private void radioButton2_Click(object sender, EventArgs e)
368         {
369             RadioButton rdo = sender as RadioButton;
370             int index = int.Parse(rdo.Tag.ToString());
371             Random r = new Random();
372             switch (index)
373             {
374                 case 0:
375                     SleepTime = 10;
376                     break;
377                 case 1: SleepTime = r.Next(500, 2000); break;
378                 case 2: SleepTime = r.Next(500, 4000); break;
379                 case 3: SleepTime = r.Next(500, 8000); break;
380             }
381             button1.Enabled = true;
382         }
383 
384         private void Form1_Load(object sender, EventArgs e)
385         {
386             using (StreamReader reader = new StreamReader(Application.StartupPath + "\\config.txt"))
387             {
388                 string _name = reader.ReadToEnd().Trim();
389                 if (_name.Length > 0)
390                     gamename = reader.ReadToEnd();
391             }
392             LianLianHelp.RegisterHotKey(this.Handle, 800, 0, Keys.F10);
393             LianLianHelp.RegisterHotKey(this.Handle, 801, 0, Keys.F11);
394             LianLianHelp.RegisterHotKey(this.Handle, 802, 0, Keys.F6);
395             LianLianHelp.RegisterHotKey(this.Handle, 803, 0, Keys.F7);
396         }
397 
398         protected override void WndProc(ref Message m)
399         {
400             switch (m.Msg)
401             {
402                 case 0x0312:    //这个是window消息定义的注册的热键消息 
403                     if (m.WParam.ToString().Equals("800"))
404                     {
405                         if (!isstart)
406                         {
407                             isstart = true;
408                             this.button1.Enabled = false;
409                             // Start();
410                             Thread th = new Thread(Start);
411                             th.IsBackground = true;
412                             th.Start();
413                         }
414                     }
415                     else if (m.WParam.ToString().Equals("801"))
416                     {
417                         isstop = true;
418                     }
419                     else if (m.WParam.ToString().Equals("802"))
420                     {
421                         this.Hide();
422                     }
423                     else if (m.WParam.ToString().Equals("803"))
424                     {
425                         this.Show();
426                     }
427 
428                     break;
429             }
430             base.WndProc(ref m);
431         }
432 
433         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
434         {
435             LianLianHelp.UnregisterHotKey(this.Handle, 800);
436             LianLianHelp.UnregisterHotKey(this.Handle, 801);
437             LianLianHelp.UnregisterHotKey(this.Handle, 802);
438             LianLianHelp.UnregisterHotKey(this.Handle, 803);
439         }
440     }
441 
442 }

View Code

  1 namespace LianLianHelp
  2 {
  3     partial class Form1
  4     {
  5         /// <summary>
  6         /// 設計工具所需的變數。
  7         /// </summary>
  8         private System.ComponentModel.IContainer components = null;
  9 
 10         /// <summary>
 11         /// 清除任何使用中的資源。
 12         /// </summary>
 13         /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param>
 14         protected override void Dispose(bool disposing)
 15         {
 16             if (disposing && (components != null))
 17             {
 18                 components.Dispose();
 19             }
 20             base.Dispose(disposing);
 21         }
 22 
 23         #region Windows Form 設計工具產生的程式碼
 24 
 25         /// <summary>
 26         /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器
 27         /// 修改這個方法的內容。
 28         /// </summary>
 29         private void InitializeComponent()
 30         {
 31             this.button1 = new System.Windows.Forms.Button();
 32             this.radioButton1 = new System.Windows.Forms.RadioButton();
 33             this.radioButton2 = new System.Windows.Forms.RadioButton();
 34             this.radioButton3 = new System.Windows.Forms.RadioButton();
 35             this.radioButton4 = new System.Windows.Forms.RadioButton();
 36             this.button2 = new System.Windows.Forms.Button();
 37             this.groupBox1 = new System.Windows.Forms.GroupBox();
 38             this.groupBox2 = new System.Windows.Forms.GroupBox();
 39             this.label4 = new System.Windows.Forms.Label();
 40             this.label3 = new System.Windows.Forms.Label();
 41             this.label2 = new System.Windows.Forms.Label();
 42             this.label1 = new System.Windows.Forms.Label();
 43             this.groupBox1.SuspendLayout();
 44             this.groupBox2.SuspendLayout();
 45             this.SuspendLayout();
 46             // 
 47             // button1
 48             // 
 49             this.button1.Enabled = false;
 50             this.button1.Location = new System.Drawing.Point(42, 136);
 51             this.button1.Name = "button1";
 52             this.button1.Size = new System.Drawing.Size(75, 23);
 53             this.button1.TabIndex = 0;
 54             this.button1.Text = "开始";
 55             this.button1.UseVisualStyleBackColor = true;
 56             this.button1.Click += new System.EventHandler(this.button1_Click);
 57             // 
 58             // radioButton1
 59             // 
 60             this.radioButton1.AutoSize = true;
 61             this.radioButton1.Location = new System.Drawing.Point(9, 20);
 62             this.radioButton1.Name = "radioButton1";
 63             this.radioButton1.Size = new System.Drawing.Size(47, 16);
 64             this.radioButton1.TabIndex = 1;
 65             this.radioButton1.Tag = "0";
 66             this.radioButton1.Text = "闪电";
 67             this.radioButton1.UseVisualStyleBackColor = true;
 68             this.radioButton1.Click += new System.EventHandler(this.radioButton2_Click);
 69             // 
 70             // radioButton2
 71             // 
 72             this.radioButton2.AutoSize = true;
 73             this.radioButton2.Checked = true;
 74             this.radioButton2.Location = new System.Drawing.Point(72, 20);
 75             this.radioButton2.Name = "radioButton2";
 76             this.radioButton2.Size = new System.Drawing.Size(47, 16);
 77             this.radioButton2.TabIndex = 2;
 78             this.radioButton2.TabStop = true;
 79             this.radioButton2.Tag = "1";
 80             this.radioButton2.Text = "烈马";
 81             this.radioButton2.UseVisualStyleBackColor = true;
 82             this.radioButton2.Click += new System.EventHandler(this.radioButton2_Click);
 83             // 
 84             // radioButton3
 85             // 
 86             this.radioButton3.AutoSize = true;
 87             this.radioButton3.Location = new System.Drawing.Point(135, 20);
 88             this.radioButton3.Name = "radioButton3";
 89             this.radioButton3.Size = new System.Drawing.Size(47, 16);
 90             this.radioButton3.TabIndex = 3;
 91             this.radioButton3.Tag = "2";
 92             this.radioButton3.Text = "脱兔";
 93             this.radioButton3.UseVisualStyleBackColor = true;
 94             this.radioButton3.Click += new System.EventHandler(this.radioButton2_Click);
 95             // 
 96             // radioButton4
 97             // 
 98             this.radioButton4.AutoSize = true;
 99             this.radioButton4.Location = new System.Drawing.Point(198, 21);
100             this.radioButton4.Name = "radioButton4";
101             this.radioButton4.Size = new System.Drawing.Size(47, 16);
102             this.radioButton4.TabIndex = 4;
103             this.radioButton4.Tag = "3";
104             this.radioButton4.Text = "蜗牛";
105             this.radioButton4.UseVisualStyleBackColor = true;
106             this.radioButton4.Click += new System.EventHandler(this.radioButton2_Click);
107             // 
108             // button2
109             // 
110             this.button2.Location = new System.Drawing.Point(153, 136);
111             this.button2.Name = "button2";
112             this.button2.Size = new System.Drawing.Size(75, 23);
113             this.button2.TabIndex = 5;
114             this.button2.Text = "退出";
115             this.button2.UseVisualStyleBackColor = true;
116             this.button2.Click += new System.EventHandler(this.button2_Click);
117             // 
118             // groupBox1
119             // 
120             this.groupBox1.Controls.Add(this.radioButton4);
121             this.groupBox1.Controls.Add(this.radioButton1);
122             this.groupBox1.Controls.Add(this.radioButton2);
123             this.groupBox1.Controls.Add(this.radioButton3);
124             this.groupBox1.Location = new System.Drawing.Point(7, 6);
125             this.groupBox1.Name = "groupBox1";
126             this.groupBox1.Size = new System.Drawing.Size(260, 45);
127             this.groupBox1.TabIndex = 6;
128             this.groupBox1.TabStop = false;
129             this.groupBox1.Text = "速度";
130             // 
131             // groupBox2
132             // 
133             this.groupBox2.Controls.Add(this.label4);
134             this.groupBox2.Controls.Add(this.label3);
135             this.groupBox2.Controls.Add(this.label2);
136             this.groupBox2.Controls.Add(this.label1);
137             this.groupBox2.Location = new System.Drawing.Point(5, 58);
138             this.groupBox2.Name = "groupBox2";
139             this.groupBox2.Size = new System.Drawing.Size(260, 72);
140             this.groupBox2.TabIndex = 7;
141             this.groupBox2.TabStop = false;
142             this.groupBox2.Text = "热键";
143             // 
144             // label4
145             // 
146             this.label4.AutoSize = true;
147             this.label4.Location = new System.Drawing.Point(135, 45);
148             this.label4.Name = "label4";
149             this.label4.Size = new System.Drawing.Size(59, 12);
150             this.label4.TabIndex = 3;
151             this.label4.Text = "停止:F11";
152             // 
153             // label3
154             // 
155             this.label3.AutoSize = true;
156             this.label3.Location = new System.Drawing.Point(13, 45);
157             this.label3.Name = "label3";
158             this.label3.Size = new System.Drawing.Size(59, 12);
159             this.label3.TabIndex = 2;
160             this.label3.Text = "开始:F10";
161             // 
162             // label2
163             // 
164             this.label2.AutoSize = true;
165             this.label2.Location = new System.Drawing.Point(135, 22);
166             this.label2.Name = "label2";
167             this.label2.Size = new System.Drawing.Size(53, 12);
168             this.label2.TabIndex = 1;
169             this.label2.Text = "呼出:F7";
170             // 
171             // label1
172             // 
173             this.label1.AutoSize = true;
174             this.label1.Location = new System.Drawing.Point(11, 22);
175             this.label1.Name = "label1";
176             this.label1.Size = new System.Drawing.Size(53, 12);
177             this.label1.TabIndex = 0;
178             this.label1.Text = "隐藏:F6";
179             // 
180             // Form1
181             // 
182             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
183             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
184             this.ClientSize = new System.Drawing.Size(271, 171);
185             this.Controls.Add(this.groupBox2);
186             this.Controls.Add(this.groupBox1);
187             this.Controls.Add(this.button2);
188             this.Controls.Add(this.button1);
189             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
190             this.Name = "Form1";
191             this.Text = "QQ连连看游戏辅助";
192             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
193             this.Load += new System.EventHandler(this.Form1_Load);
194             this.groupBox1.ResumeLayout(false);
195             this.groupBox1.PerformLayout();
196             this.groupBox2.ResumeLayout(false);
197             this.groupBox2.PerformLayout();
198             this.ResumeLayout(false);
199 
200         }
201 
202         #endregion
203 
204         private System.Windows.Forms.Button button1;
205         private System.Windows.Forms.RadioButton radioButton1;
206         private System.Windows.Forms.RadioButton radioButton2;
207         private System.Windows.Forms.RadioButton radioButton3;
208         private System.Windows.Forms.RadioButton radioButton4;
209         private System.Windows.Forms.Button button2;
210         private System.Windows.Forms.GroupBox groupBox1;
211         private System.Windows.Forms.GroupBox groupBox2;
212         private System.Windows.Forms.Label label4;
213         private System.Windows.Forms.Label label3;
214         private System.Windows.Forms.Label label2;
215         private System.Windows.Forms.Label label1;
216     }
217 }

View Code

HelpSource 保存一些数据

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.Drawing;
 5 
 6 namespace LianLianHelp
 7 {
 8     class HelpSource
 9     {
10         /// <summary>
11         /// 游戏区域相对于窗口偏移
12         /// </summary>
13         public static Point game_offset = new Point(15, 182);
14         /// <summary>
15         /// 游戏区域大小
16         /// </summary>
17         public static Size gameSize = new Size(589, 385);
18         /// <summary>
19         /// 每个方块大小
20         /// </summary>
21         public static Size pieceSize = new Size(31, 35);
22     }
23 }

View Code

LianLianClass 游戏小方格类

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.Drawing;
 5 
 6 namespace LianLianHelp
 7 {
 8     class LianLianClass
 9     {
10         private int[] colorNumCount=new int[9]; 
11         /// <summary>
12         /// 颜色值
13         /// </summary>
14         public int[] ColorNumCount
15         {
16             get { return colorNumCount; }
17             set { colorNumCount = value; }
18         }
19 
20         private bool isBackgrpund = false;
21         /// <summary>
22         /// 是否是背景
23         /// </summary>
24         public bool IsBackgrpund
25         {
26             get { return isBackgrpund; }
27             set { isBackgrpund = value; }
28         }
29 
30         private Point thisPoint;
31         /// <summary>
32         /// 方块位置
33         /// </summary>
34         public Point ThisPoint
35         {
36             get { return thisPoint; }
37             set { thisPoint = value; }
38         }
39 
40         private Point listPoint;
41         /// <summary>
42         /// 数组中的位置
43         /// </summary>
44         public Point ListPoint
45         {
46             get { return listPoint; }
47             set { listPoint = value; }
48         }private bool ismove = false;
49         /// <summary>
50         /// 是否移除了
51         /// </summary>
52         public bool Ismove
53         {
54             get { return ismove; }
55             set { ismove = value; }
56         }
57 
58         private TODIRECTION toDirection = TODIRECTION.RIGHT;
59 
60         internal TODIRECTION ToDirection
61         {
62             get { return toDirection; }
63             set { toDirection = value; }
64         }
65     }
66 }

View Code

LianLianHelp  游戏辅助类

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Drawing;
  5 using System.Windows.Forms;
  6 using System.Runtime.InteropServices;
  7 using System.Diagnostics;
  8 
  9 namespace LianLianHelp
 10 {
 11     enum TODIRECTION
 12     {
 13         LEFT,
 14         RIGHT,
 15         UP,
 16         DOWN
 17     }
 18 
 19     enum NODETYPE
 20     {
 21         SOURCENODE,
 22         OTHERNODE
 23     }
 24 
 25     class LianLianHelp
 26     {
 27         private static LianLianHelp lianLelp;
 28 
 29         public static LianLianHelp LianLelp
 30         {
 31             get
 32             {
 33                 if (lianLelp == null)
 34                 {
 35                     lianLelp = new LianLianHelp();
 36                 }
 37                 return LianLianHelp.lianLelp;
 38             }
 39         }
 40 
 41         private LianLianHelp()
 42         {
 43 
 44         }
 45 
 46         public void ClearList()
 47         {
 48             LianList.Clear();
 49         }
 50 
 51         List<List<LianLianClass>> lianList = new List<List<LianLianClass>>();
 52         /// <summary>
 53         /// 方块列表
 54         /// </summary>
 55         public List<List<LianLianClass>> LianList
 56         {
 57             get { return lianList; }
 58             set { lianList = value; }
 59         }
 60 
 61 
 62         public bool Isalike(LianLianClass c1, LianLianClass c2)
 63         {
 64 
 65             for (int i = 0; i < 9; i++)
 66             {
 67                 if (Math.Abs(c1.ColorNumCount[i] - c2.ColorNumCount[i]) > 20)
 68                     return false;
 69             }
 70             return true;
 71         }
 72 
 73         public LianLianClass GetLLC(int thisx, int thisy, TODIRECTION toDirection)
 74         {
 75             LianLianClass lc = GetNextLLC(thisx, thisy, toDirection);
 76             if (lc.Ismove == true || lc.IsBackgrpund == true)
 77                 lc = GetLLC(lc.ListPoint.X, lc.ListPoint.Y, toDirection);
 78             return lc;
 79         }
 80 
 81         public LianLianClass GetNextLLC(int thisx, int thisy, TODIRECTION toDirection)
 82         {
 83             LianLianClass lc = null;
 84             switch (toDirection)
 85             {
 86                 case TODIRECTION.LEFT:
 87                     if (thisx == 0)
 88                         return null;
 89                     else
 90                     {
 91                         lc = LianList[thisx - 1][thisy];
 92                     }
 93                     break;
 94                 case TODIRECTION.RIGHT:
 95                     if (thisx == 18)
 96                         return null;
 97                     else
 98                     {
 99                         lc = LianList[thisx + 1][thisy];
100                     }
101                     break;
102                 case TODIRECTION.UP:
103                     if (thisy == 0)
104                         return null;
105                     else
106                     {
107                         lc = LianList[thisx][thisy - 1];
108 
109                     }
110                     break;
111                 case TODIRECTION.DOWN:
112                     if (thisy == 10)
113                         return null;
114                     else
115                     {
116                         lc = LianList[thisx][thisy + 1];
117                     }
118                     break;
119             }
120             return lc;
121         }
122 
123         public bool CheckISOK()
124         {
125             for (int x = 0; x < 19; x++)
126             {
127                 for (int y = 0; y < 11; y++)
128                 {
129                     LianLianClass llc = LianList[x][y];
130                     if (llc.IsBackgrpund)
131                     {
132                         continue;
133                     }
134                     if (!llc.Ismove)
135                     {
136                         return false;
137                     }
138                 }
139             }
140             return true;
141         }
142 
143 
144         public void PrintScreen(string file)
145         {
146             Bitmap bit = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
147             Graphics g = Graphics.FromImage(bit);
148             g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);
149             bit.Save(file);
150             g.Dispose();
151             bit.Dispose();
152         }
153 
154         #region 鼠标
155         const int MOUSEEVENTF_MOVE = 0x0001;     // 移动鼠标 
156         const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下 
157         const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起 
158         const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下 
159         const int MOUSEEVENTF_RIGHTUP = 0x0010; //模拟鼠标右键抬起 
160         const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;// 模拟鼠标中键按下 
161         const int MOUSEEVENTF_MIDDLEUP = 0x0040; //模拟鼠标中键抬起 
162         const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采用绝对坐标 
163 
164         [DllImport("user32.dll", EntryPoint = "GetCursorPos")]//获取鼠标坐标
165         private static extern int GetCursorPos(
166             ref POINTAPI lpPoint
167         );
168 
169         [System.Runtime.InteropServices.DllImport("user32")]
170         private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
171 
172         public static void LeftClick(int x, int y)
173         {
174             mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, x * 65535 / Screen.PrimaryScreen.Bounds.Width, y * 65535 / Screen.PrimaryScreen.Bounds.Height, 0, 0);//点击
175             mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, x * 65535 / Screen.PrimaryScreen.Bounds.Width, y * 65535 / Screen.PrimaryScreen.Bounds.Height, 0, 0);//抬起
176         }
177 
178         public static void MoveMouse(int x, int y)
179         {
180             mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x * 65535 / Screen.PrimaryScreen.Bounds.Width, y * 65535 / Screen.PrimaryScreen.Bounds.Height, 0, 0);
181         }
182 
183         [StructLayout(LayoutKind.Sequential)]//定义与API相兼容结构体,实际上是一种内存转换
184         private struct POINTAPI
185         {
186             public int X;
187             public int Y;
188         }
189 
190         public static Point GetMousePoint()
191         {
192             LianLianHelp.POINTAPI pointapi = new LianLianHelp.POINTAPI();
193             LianLianHelp.GetCursorPos(ref pointapi);
194             return new Point(pointapi.X, pointapi.Y);
195         }
196         #endregion
197 
198         #region 窗体
199         public const int SW_HIDE = 0;
200         public const int SW_SHOWNORMAL = 1;
201         public const int SW_SHOWMINIMIZED = 2;
202         public const int SW_SHOWMAXIMIZED = 3;
203         public const int SW_MAXIMIZE = 3;
204         public const int SW_SHOWNOACTIVATE = 4;
205         public const int SW_SHOW = 5;
206         public const int SW_MINIMIZE = 6;
207         public const int SW_SHOWMINNOACTIVE = 7;
208         public const int SW_SHOWNA = 8;
209         public const int SW_RESTORE = 9;
210 
211         [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
212         public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
213         [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
214         public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体
215         [DllImport("user32.dll")]
216         [return: MarshalAs(UnmanagedType.Bool)]
217         private static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
218 
219         [StructLayout(LayoutKind.Sequential)]
220         private struct RECT
221         {
222             public int Left; //最左坐标
223             public int Top; //最上坐标
224             public int Right; //最右坐标
225             public int Bottom; //最下坐标
226         }
227 
228         [DllImport("user32.dll", CharSet = CharSet.Auto)]
229         public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);
230 
231         public static int SetWindowSize(IntPtr hWnd, int x, int y, int width, int height)
232         {
233             return MoveWindow(hWnd, x, y, width, height, false);
234         }
235 
236         public static int GetWindowHandle(string name)
237         {
238             Process[] ps = Process.GetProcessesByName(name);
239             return ps[0].MainWindowHandle.ToInt32();
240         }
241 
242         public static void GetWindowRects(IntPtr hWnd, ref int x1, ref int y1, ref int x2, ref int y2)
243         {
244             RECT rect = new RECT();
245             GetWindowRect(hWnd, ref rect);
246             x1 = rect.Left;
247             y1 = rect.Top;
248             x2 = rect.Right;
249             y2 = rect.Bottom;
250         }
251 
252 
253         #endregion
254 
255         #region 热键
256         //注册热键的api 
257         [DllImport("user32.dll")]
258         public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
259         [DllImport("user32.dll")]
260         public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
261           
262        
263         #endregion
264     }
265 }

View Code

 

游戏效果:如果ClickNode不添加时间间隔,瞬间全消

 

版权声明:本文为bfyx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/bfyx/p/4047601.html