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

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

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

View Code

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