Advertisement
al33kappa

hanoi numeric updown

May 16th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Idon_tevenknow
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. numericUpDown1.Value = 2;
  19. label1.Visible = label2.Visible = label3.Visible = label9.Visible = label10.Visible = label11.Visible = label6.Visible = label7.Visible = false;
  20. }
  21. int i = 0;
  22. bool flag = true;
  23. Stack<Label> FirstStack = new Stack<Label>();
  24. Stack<Label> SecondStack = new Stack<Label>();
  25. Stack<Label> ThirdStack = new Stack<Label>();
  26. int pol = 427;
  27. int potolok1 = 70;
  28. int potolok3;
  29. int ukaz1 = 3, ukaz2 = 0, ukaz3 = 0;
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. Label[] labelarray = new Label[6] { label1, label2, label3, label9, label10, label11 };
  33. int n = Convert.ToInt32(numericUpDown1.Value);
  34. HB(n, 1, 2, 3);
  35. for (int j = 0; j < n; j++)
  36. {
  37. labelarray[j].Visible = true;
  38. }
  39.  
  40. if (label1.Visible) FirstStack.Push(label1);
  41. if (label2.Visible) FirstStack.Push(label2);
  42. if (label3.Visible) FirstStack.Push(label3);
  43. if (label9.Visible) FirstStack.Push(label9);
  44. if (label10.Visible) FirstStack.Push(label10);
  45. if (label11.Visible) FirstStack.Push(label11);
  46. label6.Visible = label7.Visible = true;
  47. timer1.Interval = 1;
  48. timer1.Start();
  49. }
  50. public void HB(int n, int x, int y, int z)
  51. {
  52. if (n != 0)
  53. {
  54. HB(n - 1, x, z, y);
  55. listBox1.Items.Add($"{x} -> {y}");
  56. HB(n - 1, z, y, x);
  57. }
  58. }
  59.  
  60. private void Form1_Load(object sender, EventArgs e)
  61. {
  62. //HB(3, 1, 2, 3);
  63. }
  64.  
  65. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  66. {
  67. numericUpDown1.Minimum = 2;
  68. numericUpDown1.Maximum = 6;
  69.  
  70. }
  71.  
  72. private void label1_Click(object sender, EventArgs e)
  73. {
  74.  
  75. }
  76.  
  77. private void label2_Click(object sender, EventArgs e)
  78. {
  79.  
  80. }
  81.  
  82. private void label3_Click(object sender, EventArgs e)
  83. {
  84.  
  85. }
  86.  
  87. private void label9_Click(object sender, EventArgs e)
  88. {
  89.  
  90. }
  91.  
  92. private void label10_Click(object sender, EventArgs e)
  93. {
  94.  
  95. }
  96.  
  97. private void label11_Click(object sender, EventArgs e)
  98. {
  99.  
  100. }
  101.  
  102. private void label5_Click(object sender, EventArgs e)
  103. {
  104.  
  105. }
  106.  
  107. private void label6_Click(object sender, EventArgs e)
  108. {
  109.  
  110. }
  111.  
  112. private void label7_Click(object sender, EventArgs e)
  113. {
  114.  
  115. }
  116.  
  117. public void moving()
  118. {
  119. if (listBox1.Items[i].ToString() == "1 -> 2")
  120. {
  121. int potolok2 = (label6.Location.X - (FirstStack.Peek().Width / 2));
  122. if (FirstStack.Peek().Location.X == FirstStack.Peek().Location.X && FirstStack.Peek().Location.Y > potolok1 && flag) FirstStack.Peek().Top -= 5;
  123. else if (FirstStack.Peek().Location.Y == FirstStack.Peek().Location.Y && FirstStack.Peek().Location.X < potolok2)
  124. {
  125. FirstStack.Peek().Left += 5;
  126. flag = false;
  127. }
  128. else if (FirstStack.Peek().Location.X > potolok2 && FirstStack.Peek().Bottom + (FirstStack.Peek().Height + FirstStack.Peek().Height / 2) < pol - (label1.Height * ukaz2)) FirstStack.Peek().Top += 5;
  129. else
  130. {
  131. flag = true;
  132. ukaz1--;
  133. ukaz2++;
  134. i++;
  135. label8.Text = i.ToString();
  136. SecondStack.Push(FirstStack.Peek());
  137. FirstStack.Pop();
  138. }
  139.  
  140.  
  141. }
  142. else if (listBox1.Items[i].ToString() == "1 -> 3")
  143. {
  144.  
  145. int potolok3 = (label7.Location.X - (FirstStack.Peek().Width / 2));
  146. if (FirstStack.Peek().Location.X == FirstStack.Peek().Location.X && FirstStack.Peek().Location.Y > potolok1 && flag) FirstStack.Peek().Top -= 5;
  147. else if (FirstStack.Peek().Location.Y == FirstStack.Peek().Location.Y && FirstStack.Peek().Location.X < potolok3)
  148. {
  149. FirstStack.Peek().Left += 5;
  150. flag = false;
  151. }
  152. else if (FirstStack.Peek().Location.X > potolok3 && FirstStack.Peek().Bottom + (FirstStack.Peek().Height + FirstStack.Peek().Height / 2) < pol - (label1.Height * ukaz3)) FirstStack.Peek().Top += 5;
  153. else
  154. {
  155. flag = true;
  156. ukaz1--;
  157. ukaz3++;
  158. i++;
  159. label8.Text = i.ToString();
  160. ThirdStack.Push(FirstStack.Peek());
  161. FirstStack.Pop();
  162. }
  163.  
  164. }
  165. else if (listBox1.Items[i].ToString() == "2 -> 3")
  166. {
  167.  
  168. int potolok3 = (label7.Location.X - (SecondStack.Peek().Width / 2));
  169. if (SecondStack.Peek().Location.X == SecondStack.Peek().Location.X && SecondStack.Peek().Location.Y > potolok1 && flag) SecondStack.Peek().Top -= 5;
  170. else if (SecondStack.Peek().Location.Y == SecondStack.Peek().Location.Y && SecondStack.Peek().Location.X < potolok3)
  171. {
  172. SecondStack.Peek().Left += 5;
  173. flag = false;
  174. }
  175. else if (SecondStack.Peek().Location.X <= potolok3 && SecondStack.Peek().Bottom + (SecondStack.Peek().Height + SecondStack.Peek().Height / 2) < pol - (label1.Height * ukaz3)) SecondStack.Peek().Top += 5;
  176. else
  177. {
  178. flag = true;
  179. ukaz2--;
  180. ukaz3++;
  181. i++;
  182. label8.Text = i.ToString();
  183. ThirdStack.Push(SecondStack.Peek());
  184. SecondStack.Pop();
  185. }
  186.  
  187. }
  188. else if (listBox1.Items[i].ToString() == "2 -> 1")
  189. {
  190.  
  191. int potolok3 = (label5.Location.X - (SecondStack.Peek().Width / 2));
  192. if (SecondStack.Peek().Location.X == SecondStack.Peek().Location.X && SecondStack.Peek().Location.Y > potolok1 && flag) SecondStack.Peek().Top -= 5;
  193. else if (SecondStack.Peek().Location.Y == SecondStack.Peek().Location.Y && SecondStack.Peek().Location.X < potolok3)
  194. {
  195. SecondStack.Peek().Left -= 5;
  196. flag = false;
  197. }
  198. else if (SecondStack.Peek().Location.X <= potolok3 && SecondStack.Peek().Bottom + (SecondStack.Peek().Height + SecondStack.Peek().Height / 2) < pol - (label1.Height * ukaz3)) SecondStack.Peek().Top += 5;
  199. else
  200. {
  201. flag = true;
  202. ukaz2--;
  203. ukaz1++;
  204. i++;
  205. label8.Text = i.ToString();
  206. FirstStack.Push(SecondStack.Peek());
  207. SecondStack.Pop();
  208. }
  209.  
  210. }
  211. else if (listBox1.Items[i].ToString() == "3 -> 1")
  212. {
  213.  
  214. int potolok3 = (label5.Location.X - (ThirdStack.Peek().Width / 2));
  215. if (ThirdStack.Peek().Location.X == ThirdStack.Peek().Location.X && ThirdStack.Peek().Location.Y > potolok1 && flag) ThirdStack.Peek().Top -= 5;
  216. else if (ThirdStack.Peek().Location.Y == ThirdStack.Peek().Location.Y && ThirdStack.Peek().Location.X > potolok3)
  217. {
  218. ThirdStack.Peek().Left -= 5;
  219. flag = false;
  220. }
  221. else if (ThirdStack.Peek().Location.X <= potolok3 && ThirdStack.Peek().Bottom + (ThirdStack.Peek().Height + ThirdStack.Peek().Height / 2) < pol - (label1.Height * ukaz1)) ThirdStack.Peek().Top += 5;
  222. else
  223. {
  224. flag = true;
  225. ukaz3--;
  226. ukaz1++;
  227. i++;
  228. label8.Text = i.ToString();
  229. FirstStack.Push(ThirdStack.Peek());
  230. ThirdStack.Pop();
  231. }
  232.  
  233. }
  234. else if (listBox1.Items[i].ToString() == "3 -> 2")
  235. {
  236. int potolok3 = (label6.Location.X - (ThirdStack.Peek().Width / 2));
  237. if (ThirdStack.Peek().Location.X == ThirdStack.Peek().Location.X && ThirdStack.Peek().Location.Y > potolok1 && flag) ThirdStack.Peek().Top -= 5;
  238. else if (ThirdStack.Peek().Location.Y == ThirdStack.Peek().Location.Y && ThirdStack.Peek().Location.X > potolok3)
  239. {
  240. ThirdStack.Peek().Left -= 5;
  241. flag = false;
  242. }
  243. else if (ThirdStack.Peek().Location.X <= potolok3 && ThirdStack.Peek().Bottom + (ThirdStack.Peek().Height + ThirdStack.Peek().Height / 2) < pol - (label1.Height * ukaz2)) ThirdStack.Peek().Top += 5;
  244. else
  245. {
  246. flag = true;
  247. ukaz3--;
  248. ukaz2++;
  249. i++;
  250. label8.Text = i.ToString();
  251. SecondStack.Push(ThirdStack.Peek());
  252. ThirdStack.Pop();
  253. }
  254.  
  255. }
  256. }
  257.  
  258. private void timer1_Tick(object sender, EventArgs e)
  259. {
  260. if (i == listBox1.Items.Count) timer1.Stop();
  261. else moving();
  262. }
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement