Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Idon_tevenknow
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- numericUpDown1.Value = 2;
- numericUpDown1.Select();
- label1.Visible = label2.Visible = label3.Visible = label9.Visible = label10.Visible = label11.Visible = label6.Visible = label7.Visible = false;
- }
- int i = 0;
- bool flag = true;
- Stack<Label> FirstStack = new Stack<Label>();
- Stack<Label> SecondStack = new Stack<Label>();
- Stack<Label> ThirdStack = new Stack<Label>();
- int pol = 427;
- int potolok1 = 70;
- int potolok3;
- int ukaz1, ukaz2 = 0, ukaz3 = 0;
- private void button1_Click(object sender, EventArgs e)
- {
- Label[] labelarray = new Label[6] { label1, label2, label3, label9, label10, label11 };
- int n = Convert.ToInt32(numericUpDown1.Value);
- ukaz1 = n;
- HB(n, 1, 2, 3);
- //int height = 20;
- for (int j = 0; j < n; j++)
- {
- labelarray[j].Visible = true;
- }
- if (label1.Visible) FirstStack.Push(label1);
- if (label2.Visible) FirstStack.Push(label2);
- if (label3.Visible) FirstStack.Push(label3);
- if (label9.Visible) FirstStack.Push(label9);
- if (label10.Visible) FirstStack.Push(label10);
- if (label11.Visible) FirstStack.Push(label11);
- label6.Visible = label7.Visible = true;
- timer1.Interval = 1;
- timer1.Start();
- }
- public void HB(int n, int x, int y, int z)
- {
- if (n != 0)
- {
- HB(n - 1, x, z, y);
- listBox1.Items.Add($"{x} -> {y}");
- HB(n - 1, z, y, x);
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown1.Minimum = 2;
- numericUpDown1.Maximum = 6;
- }
- public void moving()
- {
- int height = 40-8;
- if (listBox1.Items[i].ToString() == "1 -> 2")
- {
- int potolok2 = (label6.Location.X - (FirstStack.Peek().Width / 2));
- if (FirstStack.Peek().Location.X == FirstStack.Peek().Location.X && FirstStack.Peek().Location.Y > potolok1 && flag) FirstStack.Peek().Top -= 5;
- else if (FirstStack.Peek().Location.Y == FirstStack.Peek().Location.Y && FirstStack.Peek().Location.X <= potolok2)
- {
- FirstStack.Peek().Left += 5;
- flag = false;
- }
- else if (FirstStack.Peek().Location.X > potolok2 && FirstStack.Peek().Bottom + (height + (height / 2)) < pol - (height * ukaz2)) FirstStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz1--;
- ukaz2++;
- i++;
- label8.Text = i.ToString();
- SecondStack.Push(FirstStack.Peek());
- FirstStack.Pop();
- }
- }
- else if (listBox1.Items[i].ToString() == "1 -> 3")
- {
- int potolok3 = (label7.Location.X - (FirstStack.Peek().Width / 2));
- if (FirstStack.Peek().Location.X == FirstStack.Peek().Location.X && FirstStack.Peek().Location.Y >= potolok1 && flag) FirstStack.Peek().Top -= 5;
- else if (FirstStack.Peek().Location.Y == FirstStack.Peek().Location.Y && FirstStack.Peek().Location.X <= potolok3)
- {
- FirstStack.Peek().Left += 5;
- flag = false;
- }
- else if (FirstStack.Peek().Location.X > potolok3 && FirstStack.Peek().Bottom + (height + (height / 2)) <= pol - (height * ukaz3)) FirstStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz1--;
- ukaz3++;
- i++;
- label8.Text = i.ToString();
- ThirdStack.Push(FirstStack.Peek());
- FirstStack.Pop();
- }
- }
- else if (listBox1.Items[i].ToString() == "2 -> 3")
- {
- int potolok3 = (label7.Location.X - (SecondStack.Peek().Width / 2));
- if (SecondStack.Peek().Location.X == SecondStack.Peek().Location.X && SecondStack.Peek().Location.Y >= potolok1 && flag) SecondStack.Peek().Top -= 5;
- else if (SecondStack.Peek().Location.Y == SecondStack.Peek().Location.Y && SecondStack.Peek().Location.X <= potolok3)
- {
- SecondStack.Peek().Left += 5;
- flag = false;
- }
- else if (SecondStack.Peek().Location.X >= potolok3 && SecondStack.Peek().Bottom + (height + (height / 2)) <= pol - (height * ukaz3)) SecondStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz2--;
- ukaz3++;
- i++;
- label8.Text = i.ToString();
- ThirdStack.Push(SecondStack.Peek());
- SecondStack.Pop();
- }
- }
- else if (listBox1.Items[i].ToString() == "2 -> 1")
- {
- int potolok3 = (label5.Location.X - (SecondStack.Peek().Width / 2));
- if (SecondStack.Peek().Location.X == SecondStack.Peek().Location.X && SecondStack.Peek().Location.Y >= potolok1 && flag) SecondStack.Peek().Top -= 5;
- else if (SecondStack.Peek().Location.Y == SecondStack.Peek().Location.Y && SecondStack.Peek().Location.X >= potolok3)
- {
- SecondStack.Peek().Left -= 5;
- flag = false;
- }
- else if (SecondStack.Peek().Location.X <= potolok3 && SecondStack.Peek().Bottom + (height + (height / 2)) <= pol - (height * ukaz3)) SecondStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz2--;
- ukaz1++;
- i++;
- label8.Text = i.ToString();
- FirstStack.Push(SecondStack.Peek());
- SecondStack.Pop();
- }
- }
- else if (listBox1.Items[i].ToString() == "3 -> 1")
- {
- int potolok3 = (label5.Location.X - (ThirdStack.Peek().Width / 2));
- if (ThirdStack.Peek().Location.X == ThirdStack.Peek().Location.X && ThirdStack.Peek().Location.Y >= potolok1 && flag) ThirdStack.Peek().Top -= 5;
- else if (ThirdStack.Peek().Location.Y == ThirdStack.Peek().Location.Y && ThirdStack.Peek().Location.X >= potolok3)
- {
- ThirdStack.Peek().Left -= 5;
- flag = false;
- }
- else if (ThirdStack.Peek().Location.X <= potolok3 && ThirdStack.Peek().Bottom + (height + (height / 2)) <= pol - (height * ukaz1)) ThirdStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz3--;
- ukaz1++;
- i++;
- label8.Text = i.ToString();
- FirstStack.Push(ThirdStack.Peek());
- ThirdStack.Pop();
- }
- }
- else if (listBox1.Items[i].ToString() == "3 -> 2")
- {
- int potolok3 = (label6.Location.X - (ThirdStack.Peek().Width / 2));
- if (ThirdStack.Peek().Location.X == ThirdStack.Peek().Location.X && ThirdStack.Peek().Location.Y >= potolok1 && flag) ThirdStack.Peek().Top -= 5;
- else if (ThirdStack.Peek().Location.Y == ThirdStack.Peek().Location.Y && ThirdStack.Peek().Location.X >= potolok3)
- {
- ThirdStack.Peek().Left -= 5;
- flag = false;
- }
- else if (ThirdStack.Peek().Location.X <= potolok3 && ThirdStack.Peek().Bottom + (height + 20) <= pol - (height * ukaz2)) ThirdStack.Peek().Top += 5;
- else
- {
- flag = true;
- ukaz3--;
- ukaz2++;
- i++;
- label8.Text = i.ToString();
- SecondStack.Push(ThirdStack.Peek());
- ThirdStack.Pop();
- }
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (i == listBox1.Items.Count) timer1.Stop();
- else moving();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement