public GemBoard readScreen() { GemBoard gemBoard = new GemBoard(); int width = boardPosition.getWidth(); int height = boardPosition.getHeight(); int x1 = boardPosition.getX1(); int y1 = boardPosition.getY1(); using (sDrawing.Bitmap screenBmp = new sDrawing.Bitmap(width, height + 50, sDrawing.Imaging.PixelFormat.Format32bppArgb)) { using (sDrawing.Graphics bmpGraphics = sDrawing.Graphics.FromImage(screenBmp)) { bmpGraphics.CopyFromScreen(x1, y1, 0, 0, screenBmp.Size); } for (int gridX = 0; gridX < 8; gridX++) { for (int gridY = 0; gridY < 8; gridY++) { int screenX; int screenY; boardPosition.gridToScreenOffset(gridX, gridY, out screenX, out screenY); wMedia.Color color = colorFromBitmap(screenBmp, screenX, screenY); gemBoard.setColor(gridX, gridY, color); } } } return(gemBoard); }
private void displayColorGrid(GemBoard gemBoard) { for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Rectangle currentRectangle = (Rectangle)FindName("R" + x + "x" + y); TextBlock currentTextBlock = (TextBlock)FindName("T" + x + "x" + y); currentRectangle.Fill = new SolidColorBrush(gemBoard.getColor(x, y)); string type = GemInfo.gemToString(gemBoard.getGem(x, y)); currentTextBlock.Text = type; } } }
private void dispatcherTimer_Tick(object sender, EventArgs e) { if (point1Assigned && point2Assigned) { if (running) { int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; GemBoard gemBoard = screenReader.readScreen(); displayColorGrid(gemBoard); if (gemBoard.findMove(ref x1, ref y1, ref x2, ref y2)) { mouseController.matchTwo(x1, y1, x2, y2); } } else { displayColorGrid(screenReader.readScreen()); } } }