Advertisement
al33kappa

hanoi do 5 gotovo

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