public override void Draw() { int size = _mode.SquareSize, x = 0, y = 0; var p = _properties; // draw information bar InformationBar.Draw(_stopWatch.GetTime(), (_mode.Board as MinesweeperBoard).Flag); // draw each squares on the board foreach (string representativeChar in _mode.Board.DrawableBoard) { // draw the whole square Bitmap image = BitmapList.GetBitmap(representativeChar); // x and y must all be substracted with its respective offsets SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), image, p.MarginLeft + x * size - p.SquareOffsetX, p.MarginTop + y * size - p.SquareOffsetY, p.SquareOptions ); // advances to another row if (x++ == _mode.Board.Width - 1) { x = 0; y++; } } }
/// <summary> /// Modularization from main draw method /// </summary> private static void DrawSmaller(Component.Text timer, Component.Text flags, int screenWidth, int marginLeft) { // pre-calculated values for information bar double quartX = screenWidth * 0.25, centerX = screenWidth * 0.5, centerY = Constants.INFORMATION_BAR_HEIGHT * 0.5; Bitmap clockIcon = BitmapList.GetBitmap(CLOCK), flagIcon = BitmapList.GetBitmap(FLAG); DrawingOptions cOpts = SMALL_CLOCK_ICON_OPTIONS, fOpts = SMALL_FLAG_ICON_OPTIONS; // adjust the margin marginLeft -= 15; // for smaller sized window timer.X = (float)(centerX + quartX / 2 + marginLeft); timer.Y = (float)(centerY / 4); flags.X = (float)(centerX + quartX / 2 + marginLeft); flags.Y = (float)(centerY * 0.9); // draw information bar // draw clock icon and its timer value SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), clockIcon, centerX - quartX / 2 + marginLeft - clockIcon.Width * (1 - cOpts.ScaleX) / 2, centerY / 4 - clockIcon.Height * (1 - cOpts.ScaleY) / 2, cOpts ); timer.Draw(); // draw flag icon and flags value from MinesweeperBoard SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), flagIcon, centerX - quartX / 2 + marginLeft - flagIcon.Width * (1 - fOpts.ScaleX) / 2, centerY * 0.9 - flagIcon.Width * (1 - fOpts.ScaleY) / 2, fOpts ); flags.Draw(); }
/// <summary> /// Modularization for drawing simplified board /// </summary> /// <param name="board">Stringified minesweeper board</param> /// <param name="rotate90Deg">Rotates the board 90 degrees (but the squares aren't)</param> private void DrawBoard(string[] board, bool rotate90Deg = false) { int x = 0, y = 0; var props = rotate90Deg ? _opponentProps : _playerProps; // draw each squares on the board foreach (string representativeChar in board) { // draw the whole square Bitmap image = BitmapList.GetBitmap(representativeChar); // x and y must all be substracted with its respective offsets SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), image, props.MarginLeft + x * props.SquareSize - props.SquareOffsetX, props.MarginTop + y * props.SquareSize - props.SquareOffsetY, props.SquareOptions ); // advances to another row // player if (!rotate90Deg) { x++; if (x == _settings.BoardWidth) { x = 0; y++; } continue; } // opponent y++; if (y == _settings.BoardWidth) { y = 0; x++; } } }
/// <summary> /// Modularization from main draw method /// </summary> private static void DrawNormal(Component.Text timer, Component.Text flags, int screenWidth) { // pre-calculated values for information bar double quartX = screenWidth * 0.25, centerX = screenWidth * 0.5, centerY = Constants.INFORMATION_BAR_HEIGHT * 0.5; Bitmap clockIcon = BitmapList.GetBitmap(CLOCK), flagIcon = BitmapList.GetBitmap(FLAG); Size flagsTextSize = flags.GetTextSize(); timer.X = (float)(centerX - quartX + clockIcon.Width + 10); timer.Y = (float)(centerY - timer.GetTextSize().Height / 2); flags.X = (float)(centerX + quartX); flags.Y = (float)(centerY - flagsTextSize.Height / 2); // draw information bar // draw clock icon and its timer value SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), clockIcon, centerX - quartX, centerY - clockIcon.Height / 2, CLOCK_ICON_OPTIONS ); timer.Draw(); // draw flag icon and flags value from MinesweeperBoard SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), flagIcon, centerX + quartX - 110, centerY - flagIcon.Height / 2, FLAG_ICON_OPTIONS ); flags.Draw(); }