Beispiel #1
0
        public BlockParser()
        {
            imgGuess = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/one.png")));
            imgTwo   = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/three.png")));
            imgFour  = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/five.png")));
            imgSix   = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/seven.png")));
        }
Beispiel #2
0
        private void setOffset(DataStream gs)
        {
            PixelColor[,] test = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://application:,,,/MinesweeperSolver;component/Images/test.png")));

            int testWidth  = 5;
            int testHeight = 5;

            byte[] buffer = new byte[testWidth * 4 * testHeight];
            PixelColor[,] pixels = new PixelColor[testWidth, testHeight];
            for (int x = 0; x < screenWidth - 5; x += 5)
            {
                for (int y = 0; y < screenHeight - 5; y += 5)
                {
                    for (int line = 0; line < testHeight; line++)
                    {
                        gs.Position = (line + y) * screenWidth * 4 + x * 4;
                        gs.Read(buffer, testWidth * 4 * line, testWidth * 4);
                    }

                    for (int a = 0; a < testWidth; a++)
                    {
                        for (int b = 0; b < testHeight; b++)
                        {
                            int offset = b * testWidth * 4 + (a * 4);
                            pixels[b, a].Red   = buffer[offset + 2];
                            pixels[b, a].Green = buffer[offset + 1];
                            pixels[b, a].Blue  = buffer[offset + 0];
                        }
                    }

                    if (BlockParser.CompareImages(pixels, test))
                    {
                        int    finalX;
                        int    finalY;
                        byte[] pixel = new byte[4];
                        for (finalX = x; finalX > 0; finalX--)
                        {
                            gs.Position = y * screenWidth * 4 + finalX * 4;
                            gs.Read(pixel, 0, 4);
                            if (compareInt(pixel[0], 58, 9) &&
                                compareInt(pixel[1], 52, 9) &&
                                compareInt(pixel[2], 47, 9))
                            {
                                break;
                            }
                        }
                        for (finalY = y; finalY > 0; finalY--)
                        {
                            gs.Position = finalY * screenWidth * 4 + x * 4;
                            gs.Read(pixel, 0, 4);
                            if (compareInt(pixel[0], 58, 9) &&
                                compareInt(pixel[1], 52, 9) &&
                                compareInt(pixel[2], 47, 9))
                            {
                                break;
                            }
                        }
                        xoffset = finalX - 3;
                        yoffset = finalY - 1;
                        return;
                    }
                }
            }
        }