Advertisement
al33kappa

Hanoi 3 bashni zadannye

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