Exemplo n.º 1
0
        private void StartStopButton_Click(object sender, EventArgs e)
        {
            if (IsActive)
            {
                IsActive             = false;
                StartStopButton.Text = "START";
            }
            else
            {
                IsActive             = true;
                StartStopButton.Text = "STOP";

                GameWindowHandle = ScreenUtilities.GetGameWindow();
                if (GameWindowHandle == default)
                {
                    MessageBox.Show("Can't find browser window");
                    Application.Exit();
                }

                ScreenUtilities.GetWindowRect(GameWindowHandle, ref GameWindowPosition);

                Thread child = new Thread(new ThreadStart(this.TimerLoop));
                child.Start();
            }
        }
Exemplo n.º 2
0
        private void TimerLoop()
        {
            while (true)
            {
                AddOutput("Analyzing screenshot");

                using (var image = ScreenUtilities.CaptureWindow(GameWindowHandle))
                {
                    screen_rgb  = image.ToMat();
                    screen_gray = screen_rgb.CvtColor(ColorConversionCodes.BGRA2GRAY);

                    if (!IsActive)
                    {
                        return;
                    }
                    if (Cycle % 10 == 0)
                    {
                        CheckForAds();
                    }

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForBalloon();

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForLevelup();

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForDailyReward();

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForBox();

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForBonus();

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForTrains();
                    if (Cycle % 5 == 0)
                    {
                        CheckForTrains(true);
                    }

                    if (!IsActive)
                    {
                        return;
                    }
                    CheckForWhistle();

                    if (!IsActive)
                    {
                        return;
                    }
                    DoOCR();

                    //SaveImage(@"c:\Projects\C#\TrainStationBot\TrainStationBot\images\output\screen-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg");

                    screen_rgb.Dispose();
                    screen_gray.Dispose();
                }

                Application.DoEvents();
                if (!IsActive)
                {
                    return;
                }

                Cycle++;
            }
        }