Presario Опубликовано 20 февраля, 2018 Поделиться Опубликовано 20 февраля, 2018 Привет.По задумке программа должна работать так...каждые 40-50 м/с программа пермещается по координатам и сканирует их наличие определенного цвета,если цвет найден то программа кликает на него и всё,программа создавалась для игры piano tiles,чтобы она кликала по плиткам,которые идут с вверху в низ. Сама игра (gameplay) Спойлер Но у меня что то не так..по координатам она перемещается (сканирует) но когда она видит плитку она на него не кликает,помогите найти ошибку в моем коде. Spoiler using System; using System.Linq; using System.Runtime.InteropServices; using System.Drawing; using System.Threading; using System.Drawing.Drawing2D; using System.Windows.Forms; public static class Program { public static int Rset; //R Input public static int Gset; //G Input public static int Bset; //B Input public static int DefaultSpeed = 0; //Speed.Defult 0 % public static int SaveCoordsw1X; public static int SaveCoordsw1Y; public static int SaveCoordsw2X; public static int SaveCoordsw2Y; //Coords save public static int SaveCoordsw3X; public static int SaveCoordsw3Y; public static int SaveCoordsw4X; public static int SaveCoordsw4Y; //// static void StartTime() //Timeout // { // Console.WriteLine("Выполнения программы начнется через 5"); // Thread.Sleep(1000); // Console.WriteLine("Выполнения программы начнется через 4"); // Thread.Sleep(1000); // Console.WriteLine("Выполнения программы начнется через 3"); // Thread.Sleep(1000); // Console.WriteLine("Выполнения программы начнется через 2"); // Thread.Sleep(1000); // Console.WriteLine("Выполнения программы начнется через 1"); // Thread.Sleep(1000); // } [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); [DllImport("gdi32.dll")] static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); public const int MOUSEEVENTF_LEFTDOWN = 0x02; public const int MOUSEEVENTF_LEFTUP = 0x04; public static void LeftMouseClick(int xpos, int ypos) { mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0); //mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0); } public static void ColorLoad() { Console.WriteLine("Введите номер Red"); Rset = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите номер Green"); Gset = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите номер Blue"); Bset = Convert.ToInt32(Console.ReadLine()); } public static void SpeedSet() { Console.WriteLine("Введите скорость в миллисекундах"); DefaultSpeed = Convert.ToInt32(Console.ReadLine()); } static void Main() { ColorLoad(); SpeedSet(); // StartTime(); Console.Clear(); Point tmp = new Point(); GetCursorPos(out tmp); while (true) { Point curPoint = new Point(); GetCursorPos(out curPoint); // Console.WriteLine("X {0} Y {1}", curPoint.X, curPoint.Y); IntPtr hDC = GetDC(IntPtr.Zero); uint pixel = GetPixel(hDC, curPoint.X, curPoint.Y); ReleaseDC(IntPtr.Zero, hDC); byte r = (byte)(pixel & 0x000000FF); byte g = (byte)((pixel & 0x0000FF00) >> 8); byte b = (byte)((pixel & 0x00FF0000) >> 16); // Console.Clear(); // Console.WriteLine(r); // Console.WriteLine(g); // Console.WriteLine(b); SaveOneCoord(); Thread.Sleep(DefaultSpeed); SaveTwoCoord(); Thread.Sleep(DefaultSpeed); SaveTreeCords(); Thread.Sleep(DefaultSpeed); SaveFoocords(); if (r == Rset && Gset == g && Bset ==b ) //Если на координатах найден нужный цвет то выполняем щелчок { LeftMouseClick(curPoint.X, curPoint.Y); } // LeftMouseClick(1026, 31); } } public static void SaveOneCoord() //Предотвращение повторного выполнения { if (SaveCoordsw1X != 0 && SaveCoordsw1Y != 0) { SetCursorPos(SaveCoordsw1X, SaveCoordsw1Y); } else { Console.WriteLine("ШАГ 1! Введите координаты X И Y: "); SaveCoordsw1X = Convert.ToInt32(Console.ReadLine()); SaveCoordsw1Y = Convert.ToInt32(Console.ReadLine()); } } public static void SaveTwoCoord() { if (SaveCoordsw2X != 0 && SaveCoordsw2Y != 0) { SetCursorPos(SaveCoordsw2X, SaveCoordsw2Y); } else { Console.WriteLine("ШАГ 2! Введите координаты X И Y: "); SaveCoordsw2X = Convert.ToInt32(Console.ReadLine()); SaveCoordsw2Y = Convert.ToInt32(Console.ReadLine()); } } public static void SaveTreeCords() { if (SaveCoordsw3X != 0 && SaveCoordsw3Y != 0) { SetCursorPos(SaveCoordsw3X, SaveCoordsw3Y); } else { Console.WriteLine("ШАГ 3! Введите координаты X И Y: "); SaveCoordsw3X = Convert.ToInt32(Console.ReadLine()); SaveCoordsw3Y = Convert.ToInt32(Console.ReadLine()); } } public static void SaveFoocords() { if (SaveCoordsw4X != 0 && SaveCoordsw4Y != 0) { Thread.Sleep(20); SetCursorPos(SaveCoordsw4X, SaveCoordsw4Y); } else { Console.WriteLine("ШАГ 4! Введите координаты X И Y:"); SaveCoordsw4X = Convert.ToInt32(Console.ReadLine()); SaveCoordsw4Y = Convert.ToInt32(Console.ReadLine()); } } } // прошу обратить внимание на правила оформления тем, в частности п. 1.3 и п. 1.5. Ссылка на комментарий Поделиться на другие сайты Поделиться
Рекомендуемые сообщения