Advertisement
al33kappa

4+1

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