public GameResult GetGameResult()
        {
            Bitmap frame      = GetGameFrame_Global();
            Bitmap victoryLoc = frame.Clone(CONST_VICTORY_SCAN_REGION, frame.PixelFormat);

            if (Bitmap_CV.HaystackContainsNeedle(victoryLoc, Properties.Resources.game8_victory))
            {
                victoryLoc.Dispose();
                frame.Dispose();
                return(GameResult.Victory);
            }
            Bitmap defeatLoc = frame.Clone(CONST_DEFEAT_SCAN_REGION, frame.PixelFormat);

            if (Bitmap_CV.HaystackContainsNeedle(defeatLoc, Properties.Resources.game8_defeat))
            {
                defeatLoc.Dispose();
                frame.Dispose();
                return(GameResult.Defeat);
            }

            frame.Dispose();
            victoryLoc.Dispose();
            defeatLoc.Dispose();
            return(GameResult.Unknown);
        }
        public Rectangle Find_GainPowerButton()
        {
            Bitmap frame = GetGameFrame_Global();

            TemplateMatch[] matches = Bitmap_CV.FindAllNeedles(frame, Properties.Resources.gain_power, 0.925f);
            if (matches.Length == 0)
            {
                return(Rectangle.Empty);
            }
            return(matches[0].Rectangle);
        }
        public Rectangle Find_StartButton()
        {
            Bitmap frame = GetGameFrame_Global();

            TemplateMatch[] matches = Bitmap_CV.FindAllNeedles(frame, Properties.Resources.start_fullscreen, 0.925f);
            if (matches.Length == 0)
            {
                return(Rectangle.Empty);
            }
            return(matches[0].Rectangle);
        }
        public CurrencyType RecognizeCardType(Bitmap cardImage) // cardImage = haystack
        {
            CurrencyType currencyType = CurrencyType.Unknown;

            foreach (KeyValuePair <CurrencyType, System.Drawing.Image> kvp in CONST_KNOWN_CARD_TYPES)
            {
                if (Bitmap_CV.HaystackContainsNeedle(cardImage, (Bitmap)kvp.Value))
                {
                    currencyType = kvp.Key;
                    break;
                }
            }
            Console.WriteLine($"[MemoryGame] RecognizeCardType: Recognized card as {currencyType}");
            return(currencyType);
        }
예제 #5
0
        private void FindDroppingCoins(Bitmap bitmap)
        {
            List <Thread> threads = new List <Thread>();

            foreach (KeyValuePair <DroppingCoinType, System.Drawing.Image> coinType in CONST_KNOWN_COIN_TYPES)
            {
                Bitmap bitmapCopy = bitmap.Clone(CONST_SCAN_REGION, bitmap.PixelFormat);
                Thread th         = new Thread(new ThreadStart(() =>
                {
                    Stopwatch s = new Stopwatch();
                    s.Start();
                    TemplateMatch[] coinType_matches = Bitmap_CV.FindAllNeedles(bitmapCopy, (Bitmap)coinType.Value, 0.8f);
                    s.Stop();
                    Console.WriteLine($"SCAN TIME: {s.ElapsedMilliseconds}ms");
                    bitmapCopy.Dispose();
                    foreach (TemplateMatch coinType_match in coinType_matches)
                    {
                        Detections.Add(new DroppingCoin(coinType.Key, new Rectangle(CONST_SCAN_REGION.X + coinType_match.Rectangle.X, CONST_SCAN_REGION.Y + coinType_match.Rectangle.Y
                                                                                    , coinType_match.Rectangle.Width, coinType_match.Rectangle.Height)));
                    }
                    Console.WriteLine($"[DropperGame] Detected {coinType_matches.Length} coins of type {coinType.Key}");
                }));
                th.IsBackground = true;
                threads.Add(th);
                th.Start();
            }

            bool threadsExited = false;

            while (!threadsExited)
            {
                bool exited = true;
                foreach (Thread th in threads)
                {
                    if (th.IsAlive)
                    {
                        exited = false;
                    }
                }
                threadsExited = exited;
                Thread.Sleep(50);
            }
        }