Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Hledani_min
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- Array Array = new Array();
- public int mouseX, mouseY;
- public class MyDisplay : Panel
- {
- public MyDisplay()
- {
- this.DoubleBuffered = true;
- // or
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- UpdateStyles();
- }
- }
- private void but_Generate_Click(object sender, EventArgs e)
- {
- for (int a = 0; a < Array.x; a++)
- {
- for (int b = 0; b < Array.y; b++)
- {
- Array.pole[a, b] = 0; //neodhaleno
- }
- }
- Array.Obsazovani();
- panel1.Refresh();
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- Graphics kp = e.Graphics;
- if (Array.obsazeno == true)
- {
- Color cerna = Color.Black;
- Color gray = Color.Gray;
- Color lgray = Color.LightGray;
- Color red = Color.Red;
- Pen kostka = new Pen(cerna, 1);
- Pen kostkaneodhaleno = new Pen(gray, 10); //neodhaleno
- Brush kostkafull = new SolidBrush(cerna);//miny
- Brush kostkafullflag = new SolidBrush(red); //vlajka
- Brush kostkaneodhalenob = new SolidBrush(gray);
- Brush kostkaodhaleno = new SolidBrush(lgray);// neodhalene
- for (int a = 0; a < Array.x; a++)
- {
- for (int b = 0; b < Array.y; b++)
- {
- if (Array.pole[a, b] == 0) //neodhaleno
- {
- kp.FillRectangle(kostkaneodhalenob, 20 * a, 20 * b, 20, 20);
- kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
- }
- else if (Array.pole[a, b] == 1) //neodhaleno mina
- {
- // kp.FillRectangle(kostkafull, 20 * a, 20 * b, 20, 20);
- kp.FillRectangle(kostkaneodhalenob, 20 * a, 20 * b, 20, 20);
- kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
- }
- else if (Array.pole[a, b] == 2) //odhaleno mina
- {
- kp.FillRectangle(kostkafull, 20 * a, 20 * b, 20, 20);
- }
- else if (Array.pole[a, b] == 3) //vlajecka na mine
- {
- kp.FillRectangle(kostkafullflag, 20 * a, 20 * b, 20, 20);
- kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
- }
- else if (Array.pole[a, b] == 4) //odhaleno normal
- {
- kp.FillRectangle(kostkaodhaleno, 20 * a, 20 * b, 20, 20);
- kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
- }
- else if (Array.pole[a, b] == 5) //vlajecka na normal
- {
- kp.FillRectangle(kostkafullflag, 20 * a, 20 * b, 20, 20);
- kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
- }
- }
- }
- }
- }
- private void panel1_MouseDown(object sender, MouseEventArgs e)
- {
- mouseX = (e.X) / 20;
- mouseY = (e.Y) / 20;
- textBox1.Text = mouseX.ToString() + "," + mouseY.ToString();
- for (int a = 0; a < Array.x; a++)
- {
- for (int b = 0; b < Array.y; b++)
- {
- if (((mouseX > a && mouseX < a + 20) && (mouseY > b && mouseY < b + 20)) && (e.Button == MouseButtons.Left))
- {
- if (Array.pole[mouseX, mouseY] == 0) //neodhaleno
- {
- Array.pole[mouseX, mouseY] = 4; // odhaleno
- }
- else if (Array.pole[mouseX, mouseY] == 1) //mina
- {
- Array.pole[mouseX, mouseY] = 2; // odhaleno mina
- }
- else if (Array.pole[mouseX, mouseY] == 5) // vlajecka na normal
- {
- Array.pole[mouseX, mouseY] = 4; // odhaleno
- }
- }
- if (((mouseX > a && mouseX < a + 20) && (mouseY > b && mouseY < b + 20)) && (e.Button == MouseButtons.Right))
- {
- if (Array.pole[mouseX, mouseY] == 0) //neodhaleno
- {
- Array.pole[mouseX, mouseY] = 5; // vlajecka na normal
- }
- else if (Array.pole[mouseX, mouseY] == 1) //mina
- {
- Array.pole[mouseX, mouseY] = 3; //vlajecka na mine
- }
- else if (Array.pole[mouseX, mouseY] == 5) // vlajecka na normal
- {
- Array.pole[mouseX, mouseY] = 0; // neodhaleno
- }
- }
- }
- }
- }
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- panel1.Refresh();
- }
- private void panel1_MouseClick(object sender, MouseEventArgs e)
- {
- textBox2.Text = Array.pole[mouseX, mouseY].ToString();
- panel1.Refresh();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement