Ejemplo n.º 1
0
 private void SmileGuy_MouseUp(object sender, EventArgs e)
 {
     SmileGuy.BackgroundImage = ImageLibrary[100];
     SetVariables(Rows, Columns, NumberOfMines);
     PlayArea.Dispose();
     SetMineCells();
     FlagsRemainingLabel.Text = FlagsRemaining.ToString();
     PlayArea.Invalidate();
 }
Ejemplo n.º 2
0
 private void EndGame(bool isWon)
 {
     ShowAllMines(isWon);
     SmileGuy.BackgroundImage = (isWon) ? ImageLibrary[102] : ImageLibrary[103];
     if (isWon)
     {
         FlagsRemaining           = 0;
         FlagsRemainingLabel.Text = FlagsRemaining.ToString();
     }
     PlayArea.MouseUp   -= MineCells_MouseUp;
     PlayArea.MouseDown -= MineCells_MouseDown;
     PlayArea.Invalidate();
 }
Ejemplo n.º 3
0
 private void OnRightMouseClick(int y, int x)
 {
     if (MineCells[y, x].IsMarked)
     {
         MineCells[y, x].IsMarked = false;
         MineCells[y, x].Picture  = ImageLibrary[-1];
         FlagsRemaining++;
         FlagsRemainingLabel.Text = FlagsRemaining.ToString();
     }
     else if (!MineCells[y, x].IsClicked)
     {
         MineCells[y, x].IsMarked = true;
         MineCells[y, x].Picture  = ImageLibrary[11];
         FlagsRemaining--;
         FlagsRemainingLabel.Text = FlagsRemaining.ToString();
     }
     PlayArea.Invalidate(new Rectangle(Points[y, x], MineCellSize));
 }
Ejemplo n.º 4
0
 private void OnLeftMouseClick(int y, int x)
 {
     if (FirstClick)
     {
         SetMinesToMineCells(y, x);
         SetNumbersToAllMineCells();
         FirstClick = false;
     }
     if (!MineCells[y, x].IsClicked && !MineCells[y, x].IsMarked)
     {
         SmileGuy.BackgroundImage = ImageLibrary[100];
         if (MineCells[y, x].IsMined)
         {
             EndGame(false);
             MineCells[y, x].Picture = ImageLibrary[13];
         }
         else
         {
             MineCells[y, x].IsClicked = true;
             MineCells[y, x].Picture   = ImageLibrary[MineCells[y, x].MinesNearby];
             if (MineCells[y, x].IsMarked)
             {
                 MineCells[y, x].IsMarked = false;
                 FlagsRemaining++;
                 FlagsRemainingLabel.Text = FlagsRemaining.ToString();
             }
             if (MineCells[y, x].MinesNearby == 0)
             {
                 ClickEveryMineCellAround(y, x);
             }
             SafeMineCellsClicked++;
             if (SafeMineCellsClicked == Columns * Rows - NumberOfMines)
             {
                 EndGame(true);
             }
         }
     }
     PlayArea.Invalidate();
 }
Ejemplo n.º 5
0
        private void SetUpperBarControls()
        {
            SmileGuy = new Button
            {
                Size            = new Size(40, 40),
                Location        = new Point(ClientSize.Width / 2 - 20, 5),
                TabStop         = false,
                FlatStyle       = FlatStyle.Flat,
                BackgroundImage = ImageLibrary[100]
            };
            SmileGuy.FlatAppearance.BorderSize = 0;
            SmileGuy.MouseUp   += SmileGuy_MouseUp;
            SmileGuy.MouseDown += SmileGuy_MouseDown;
            Controls.Add(SmileGuy);

            FlagsRemainingLabel = new Label()
            {
                Size      = new Size(100, 40),
                Location  = new Point(ClientSize.Width - 105, 5),
                BackColor = Color.Black,
                ForeColor = Color.Red,
                Font      = new Font(FontFamily.GenericSansSerif, 24, FontStyle.Bold),
                Text      = FlagsRemaining.ToString(),
                TextAlign = ContentAlignment.MiddleRight
            };
            Controls.Add(FlagsRemainingLabel);

            Settings = new Button
            {
                Location = new Point(5, upperBarHeight / 2 - 15),
                Size     = new Size(FlagsRemainingLabel.Size.Width, 30),
                Text     = "Settings"
            };
            Settings.Click += Settings_Click;
            Controls.Add(Settings);
        }