Ejemplo n.º 1
0
        private Image DrawNumber(int n)
        {
            GraphicsItem numberForm = new GraphicsItem(Resources.number0, 3, 1, 26, 46);
            int          t;

            if (n >= 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    t = n % 10;
                    numberForm.DrawItem(_arrayNumber[t], 2 - i, 0);
                    n = (int)Math.Floor((double)n / 10);
                }
            }
            else
            {
                numberForm.DrawItem(Resources.sub, 0, 0);
                n = Math.Abs(n);
                for (int i = 0; i < 2; i++)
                {
                    t = n % 10;
                    numberForm.DrawItem(_arrayNumber[t], 2 - i, 0);
                    n = (int)Math.Floor((double)n / 10);
                }
            }
            return(numberForm.Img);
        }
Ejemplo n.º 2
0
        public MainForm()
        {
            //apply settings
            _appSettings = File.Exists("settings.json") ? JsonConvert.DeserializeObject <AppSettings>(File.ReadAllText("settings.json")) : new AppSettings();

            _arrayMineStatus = new Image[]
            {
                Resources.nomine0,
                Resources.nomine1,
                Resources.nomine2,
                Resources.nomine3,
                Resources.nomine4,
                Resources.nomine5,
                Resources.nomine6,
                Resources.nomine7,
                Resources.nomine8,
                Resources.nolabeled,
                Resources.minelabel,
                Resources.undefinemine,
                Resources.mineclicked,
                Resources.nominecheckmine,
                Resources.mineuncheck
            };
            _arrayNumber = new Image[]
            {
                Resources.number0,
                Resources.number1,
                Resources.number2,
                Resources.number3,
                Resources.number4,
                Resources.number5,
                Resources.number6,
                Resources.number7,
                Resources.number8,
                Resources.number9,
                Resources.sub
            };

            _time       = 0;
            _gameStart  = true;
            _enableTime = false;
            int itemHeight = 32;
            int itemWidth  = 32;

            _ime        = new ImgMouseEventHandler(_appSettings.LatestColumns, _appSettings.LatestRows, itemWidth + .6, itemHeight + .6);
            _ime.Event += ime_IEvent;
            _mb         = new MathBase(_appSettings.LatestColumns, _appSettings.LatestRows, _appSettings.LatestMines)
            {
                Mark =
                    _appSettings.Mark
            };
            _mf = new GraphicsItem(Resources.nolabeled, _appSettings.LatestColumns, _appSettings.LatestRows, itemWidth, itemHeight);
            InitializeComponent();
            #region Initialize Component
            int width  = (int)Math.Ceiling((itemWidth * _appSettings.LatestColumns) / 1.88);
            int height = (int)Math.Ceiling((itemHeight * _appSettings.LatestRows) / 1.92);
            switch (_appSettings.LatestLevel)
            {
            case "Beginner":
                beginnerMenu.Checked = true;
                break;

            case "Intermediate":
                intermediateMenu.Checked = true;
                break;

            case "Expert":
                expertMenu.Checked = true;
                break;

            default:
                customMenu.Checked = true;
                break;
            }

            markMenu.Checked        = _appSettings.Mark;
            topBg.Size              = new Size(width, 12);
            rightTopConner.Location = new Point(width + 11, 0);
            bg1.Size                   = new Size(width, 36);
            rightBg1.Location          = new Point(width + 11, 12);
            middleBg.Size              = new Size(width, 11);
            middleRightConner.Location = new Point(width + 11, 48);
            leftBg2.Size               = new Size(11, height);
            rightBg2.Location          = new Point(width + 11, 59);
            rightBg2.Size              = new Size(7, height);
            leftBottomConner.Location  = new Point(0, height + 59);
            bottomBg.Location          = new Point(12, height + 59);
            bottomBg.Size              = new Size(width - 1, 8);
            rightBottomConner.Location = new Point(width + 11, height + 59);
            face.Location              = new Point((int)Math.Floor(Convert.ToDecimal(width / 2 - 1)), 18);
            clock.Location             = new Point(width - 35, 18);
            tilesPictureBox.Image      = _mf.Img;
            tilesPictureBox.Size       = new Size(width, height);
            ClientSize                 = new Size(width + 35, height + 110);
            remainMine.Image           = DrawNumber(_appSettings.LatestMines);
            clock.Image                = DrawNumber(0);

            //Give space for MenuStrip
            foreach (Control control in Controls)
            {
                control.Top += mainMenuStrip.Size.Height / 2;
            }

            //Properly scales the application
            Scale(new SizeF(1.5f, 1.5f));
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            #endregion
        }