/// <summary> /// Create the grid of gem slots /// </summary> /// <param name="playAreaResolution">The resolution of the game</param> /// <returns>The grid of gem slots in the [row,column] format</returns> public GemSlot[,] CreateGemslots(Size playAreaResolution) { GemSlot[,] gemSlots = new GemSlot[8,8]; Point baseOffset = Point.Empty; Size gemAreaSize = Size.Empty; if (playAreaResolution.Width == 1024 && playAreaResolution.Height == 768) { baseOffset = new Point(334, 47); gemAreaSize = new Size(82, 82); } else { throw new Exception("Wrong resolution, only 1024x768 is accepted"); } for (int row = 0; row < 8; row++) { for (int column = 0; column < 8; column++) { Point offset = new Point(column * gemAreaSize.Width, row * gemAreaSize.Height); Point topLeft = new Point(baseOffset.X + offset.X, baseOffset.Y + offset.Y); gemSlots[row, column] = new GemSlot(new Rectangle(topLeft, gemAreaSize)); } } return gemSlots; }
/// <summary> /// Extracts each gems rectangle in the image /// </summary> /// <param name="screenshot">An image of the current playing area (without windowborders)</param> /// <returns>A two-dimensional array of images in the [row,column] format</returns> public Image<Bgr,byte>[,] ExtractGemSlots(Image<Bgr,byte> screenshot,GemSlot[,] gemSlots) { Image<Bgr, byte>[,] gemSlotImages = new Image<Bgr, byte>[8,8]; //values are for 1024 by 768 pixels //each gem slot is 82x82 pixels //the top left gem slots top left point is at 334,47 Point baseOffset = new Point(334, 47); Size gemAreaSize = new Size(82, 82); for(int row = 0;row < 8;row++) { for(int column = 0;column < 8;column++) { Rectangle gemSlotRectangle = gemSlots[row, column].Rectangle; gemSlotImages[row, column] = screenshot.Copy(gemSlotRectangle); } } return gemSlotImages; }
public PlayArea(GemSlot[,] gemSlots) { GemSlots = gemSlots; }