Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void UncoverTile(Button btn)
- {
- //Checks if theres a mine under the tile you pressed
- if (minedNodes.Contains(btn.Name))
- {
- //This is simply to show all the mines once the game is finished (either a win or a loss). Only coded for a loss so far.
- foreach (string button in minedNodes)
- {
- Button buttonName = StringToButton(button);
- buttonName.Image = new Bitmap(dir + "mine.png");
- }
- DialogResult playAgain = MessageBox.Show("You hit a mine! Do you want to play again?", "You hit a mine :(", MessageBoxButtons.YesNo);
- if (playAgain == DialogResult.Yes)
- {
- playButton_Click(this, null);
- }
- else
- {
- stopButton_Click(this, null);
- }
- }
- //If there isn't then we do the actual logic here.
- else
- {
- string buttonName = btn.Name;
- //USE LOOPS LATER TO SIMPLIFY THE CODE
- //set up the variables for the logic
- //Calculates all 8 adjacent tiles
- char btnLetter = Convert.ToChar(buttonName.Substring(0, buttonName.Length - 1));
- char aboveLetter = btnLetter; aboveLetter--;
- char belowLetter = aboveLetter; belowLetter++; belowLetter++;
- int upDown = Convert.ToInt32(buttonName.Substring(1));
- int leftSide = Convert.ToInt32(buttonName.Substring(1)) - 1;
- int rightSide = Convert.ToInt32(buttonName.Substring(1)) + 1;
- //Clear the list by making a new list before adding the new values as to not overlap.
- adjacence = new List<String>();
- //Put all adjacent sides in to a list
- adjacence.Add(Convert.ToString(btnLetter.ToString() + leftSide));
- adjacence.Add(Convert.ToString(btnLetter.ToString() + rightSide));
- adjacence.Add(Convert.ToString(aboveLetter.ToString() + leftSide));
- adjacence.Add(Convert.ToString(aboveLetter.ToString() + rightSide));
- adjacence.Add(Convert.ToString(belowLetter.ToString() + leftSide));
- adjacence.Add(Convert.ToString(belowLetter.ToString() + rightSide));
- adjacence.Add(Convert.ToString(aboveLetter.ToString() + upDown));
- adjacence.Add(Convert.ToString(belowLetter.ToString() + upDown));
- foreach (string i in adjacence)
- {
- if (minedNodes.Contains(i))
- {
- adjacentMines += 1;
- }
- }
- btn.Text = Convert.ToString(adjacentMines);
- btn.BackColor = System.Drawing.Color.White;
- //Do stuff to uncover the tiles
- adjacentMines = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment