Advertisement
Guest User

Form1.cs

a guest
Jun 24th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Hledani_min
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. Array Array = new Array();
  20. public int mouseX, mouseY;
  21.  
  22.  
  23. public class MyDisplay : Panel
  24. {
  25. public MyDisplay()
  26. {
  27. this.DoubleBuffered = true;
  28.  
  29. // or
  30.  
  31. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  32. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  33. UpdateStyles();
  34. }
  35. }
  36.  
  37.  
  38.  
  39. private void but_Generate_Click(object sender, EventArgs e)
  40. {
  41.  
  42. for (int a = 0; a < Array.x; a++)
  43. {
  44. for (int b = 0; b < Array.y; b++)
  45. {
  46.  
  47. Array.pole[a, b] = 0; //neodhaleno
  48.  
  49.  
  50. }
  51. }
  52.  
  53.  
  54. Array.Obsazovani();
  55. panel1.Refresh();
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
  62. private void panel1_Paint(object sender, PaintEventArgs e)
  63. {
  64. Graphics kp = e.Graphics;
  65.  
  66. if (Array.obsazeno == true)
  67. {
  68.  
  69.  
  70. Color cerna = Color.Black;
  71. Color gray = Color.Gray;
  72. Color lgray = Color.LightGray;
  73. Color red = Color.Red;
  74. Pen kostka = new Pen(cerna, 1);
  75. Pen kostkaneodhaleno = new Pen(gray, 10); //neodhaleno
  76. Brush kostkafull = new SolidBrush(cerna);//miny
  77. Brush kostkafullflag = new SolidBrush(red); //vlajka
  78. Brush kostkaneodhalenob = new SolidBrush(gray);
  79. Brush kostkaodhaleno = new SolidBrush(lgray);// neodhalene
  80.  
  81.  
  82. for (int a = 0; a < Array.x; a++)
  83. {
  84. for (int b = 0; b < Array.y; b++)
  85. {
  86.  
  87. if (Array.pole[a, b] == 0) //neodhaleno
  88. {
  89. kp.FillRectangle(kostkaneodhalenob, 20 * a, 20 * b, 20, 20);
  90. kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
  91. }
  92.  
  93. else if (Array.pole[a, b] == 1) //neodhaleno mina
  94. {
  95. // kp.FillRectangle(kostkafull, 20 * a, 20 * b, 20, 20);
  96. kp.FillRectangle(kostkaneodhalenob, 20 * a, 20 * b, 20, 20);
  97. kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
  98. }
  99. else if (Array.pole[a, b] == 2) //odhaleno mina
  100. {
  101.  
  102. kp.FillRectangle(kostkafull, 20 * a, 20 * b, 20, 20);
  103. }
  104. else if (Array.pole[a, b] == 3) //vlajecka na mine
  105. {
  106.  
  107. kp.FillRectangle(kostkafullflag, 20 * a, 20 * b, 20, 20);
  108. kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
  109. }
  110. else if (Array.pole[a, b] == 4) //odhaleno normal
  111. {
  112.  
  113. kp.FillRectangle(kostkaodhaleno, 20 * a, 20 * b, 20, 20);
  114. kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
  115. }
  116.  
  117. else if (Array.pole[a, b] == 5) //vlajecka na normal
  118. {
  119.  
  120. kp.FillRectangle(kostkafullflag, 20 * a, 20 * b, 20, 20);
  121. kp.DrawRectangle(kostka, 20 * a, 20 * b, 20, 20);
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128. }
  129.  
  130.  
  131. }
  132.  
  133. }
  134. }
  135.  
  136. private void panel1_MouseDown(object sender, MouseEventArgs e)
  137. {
  138.  
  139.  
  140.  
  141.  
  142. mouseX = (e.X) / 20;
  143. mouseY = (e.Y) / 20;
  144. textBox1.Text = mouseX.ToString() + "," + mouseY.ToString();
  145.  
  146. for (int a = 0; a < Array.x; a++)
  147. {
  148.  
  149.  
  150. for (int b = 0; b < Array.y; b++)
  151. {
  152.  
  153.  
  154. if (((mouseX > a && mouseX < a + 20) && (mouseY > b && mouseY < b + 20)) && (e.Button == MouseButtons.Left))
  155. {
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. if (Array.pole[mouseX, mouseY] == 0) //neodhaleno
  164. {
  165.  
  166. Array.pole[mouseX, mouseY] = 4; // odhaleno
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. }
  175.  
  176. else if (Array.pole[mouseX, mouseY] == 1) //mina
  177. {
  178.  
  179. Array.pole[mouseX, mouseY] = 2; // odhaleno mina
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. }
  187.  
  188. else if (Array.pole[mouseX, mouseY] == 5) // vlajecka na normal
  189. {
  190.  
  191. Array.pole[mouseX, mouseY] = 4; // odhaleno
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. }
  199.  
  200.  
  201.  
  202.  
  203.  
  204. }
  205.  
  206. if (((mouseX > a && mouseX < a + 20) && (mouseY > b && mouseY < b + 20)) && (e.Button == MouseButtons.Right))
  207. {
  208.  
  209. if (Array.pole[mouseX, mouseY] == 0) //neodhaleno
  210. {
  211.  
  212.  
  213.  
  214.  
  215.  
  216. Array.pole[mouseX, mouseY] = 5; // vlajecka na normal
  217.  
  218.  
  219.  
  220. }
  221.  
  222. else if (Array.pole[mouseX, mouseY] == 1) //mina
  223. {
  224.  
  225.  
  226.  
  227.  
  228. Array.pole[mouseX, mouseY] = 3; //vlajecka na mine
  229.  
  230.  
  231.  
  232. }
  233.  
  234. else if (Array.pole[mouseX, mouseY] == 5) // vlajecka na normal
  235. {
  236.  
  237.  
  238.  
  239.  
  240. Array.pole[mouseX, mouseY] = 0; // neodhaleno
  241.  
  242.  
  243.  
  244. }
  245.  
  246.  
  247.  
  248. }
  249.  
  250.  
  251.  
  252.  
  253. }
  254. }
  255.  
  256.  
  257. }
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. private void Form1_MouseClick(object sender, MouseEventArgs e)
  265. {
  266. panel1.Refresh();
  267. }
  268.  
  269. private void panel1_MouseClick(object sender, MouseEventArgs e)
  270. {
  271. textBox2.Text = Array.pole[mouseX, mouseY].ToString();
  272. panel1.Refresh();
  273. }
  274.  
  275.  
  276. }
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement