示例#1
0
        public void TestRegionPositionMana2()
        {
            CardPositions cp       = new CardPositions(1920, 1080);
            CardRegion    expected = new CardRegion(40, 40, 537, 183);

            Assert.AreEqual(expected, cp.Get(1, RegionType.Mana));
        }
示例#2
0
        public void TestRegionPosition()
        {
            CardPositions cp       = new CardPositions(1920, 1080);
            CardRegion    expected = new CardRegion(0, 0, 384, 489);

            Assert.AreEqual(expected, cp.Get(0, RegionType.Count));
        }
示例#3
0
        public void TestRegionPixelCoordinatesAt1080_1()
        {
            CardPositions cp = new CardPositions(1920, 1080);
            PointF        pf = new PointF(0.039F, 0.169F);
            Point         p  = new Point(296, 183);

            Assert.AreEqual(p, cp.ToPixelCoordinates(pf));
        }
示例#4
0
        public void TestRegionPixelCoordinatesAt1080_2()
        {
            CardPositions cp = new CardPositions(1920, 1080);
            PointF        pf = new PointF(0.043F, 0.285F);
            Point         p  = new Point(302, 308);

            Assert.AreEqual(p, cp.ToPixelCoordinates(pf));
        }
示例#5
0
        public static CardCount Recognize(string file, bool legend = false)
        {
            CardCount count = new CardCount();

            try
            {
                // full screen capture
                var           bmp = new Bitmap(file);
                CardPositions pos = new CardPositions(bmp.Width, bmp.Height);
                // 1 - Check for existence at position 0
                var exists1 = ReadRegion(bmp, pos.Get(0, RegionType.Mana), 90, 360, 0, 1);
                if (exists1)
                {
                    var count1 = ReadRegion(bmp, pos.Get(0, RegionType.Count), 0, 40, 0, 0.4);
                    // 2 - Check for existence at position 1
                    var exists2 = ReadRegion(bmp, pos.Get(1, RegionType.Mana), 90, 360, 0, 1);
                    if (exists2)
                    {
                        var count2 = ReadRegion(bmp, pos.Get(1, RegionType.Count), 0, 40, 0, 0.4);
                        // 2a - true => standard & gold (TODO: special cases)
                        count.Standard = count1 ? 2 : 1;
                        count.Golden   = count2 ? 2 : 1;
                    }
                    else
                    {
                        // 2b - false => position 0 may be gold, check it
                        var goldRegion = pos.Get(0, RegionType.Gold);
                        if (legend)
                        {
                            goldRegion = pos.Get(0, RegionType.GoldLegend);
                        }
                        var gold1 = ReadRegion(bmp, goldRegion, 40, 57, 0.55, 1);
                        if (gold1)
                        {
                            count.Golden = count1 ? 2 : 1;
                        }
                        else
                        {
                            count.Standard = count1 ? 2 : 1;
                        }
                    }
                }
                else
                {
                    // no matches
                    return(count);
                }


                bmp.Dispose(); // TODO: add finally
            }
            catch (FileNotFoundException e)
            {
                Logger.Write("Exception: " + e, "Recognize");
            }
            return(count);
        }