Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- using System.Drawing;
- namespace Pociagi
- {
- class Ludziki
- {
- public bool czyPrawo;
- public int sleep;
- public Thread watek;
- private PictureBox pb;
- public Ludziki(bool czyPrawo, int sleep)
- {
- this.czyPrawo = czyPrawo;
- this.sleep = sleep;
- this.pb = new PictureBox();
- if (czyPrawo)
- this.pb.Location = new Point(867, 262);
- else
- this.pb.Location = new Point(-20, 262);
- this.pb.Width = 28;//32; 61
- this.pb.Height = 29;
- this.pb.Image = global::Pociagi.Properties.Resources.Ludzik;
- this.pb.Visible = true;
- Pociag.form.Controls.Add(this.pb);
- this.watek = new Thread(new ThreadStart(this.NaPiechote));
- // this.watek = new Thread(new ParameterizedThreadStart(Poruszaj_Samochod));
- this.watek.Start();
- }
- public void NaPiechote()
- {
- if (Thread.CurrentThread == this.watek)
- {
- if (this.czyPrawo)
- {
- for (int i = 867; i > -30; i--)
- {
- if (Pociag.Rogatka==false)//dol
- {
- if (i == 483)//420
- {
- i++;
- }
- // else if (i < 420 && i > 205)
- // i -= 3;
- }
- Thread.Sleep(this.sleep);
- if (this.pb != null && i < 866)
- {
- this.pb.BeginInvoke(new Action(() => { this.pb.Location = new Point(i,262); }));
- //this.pb.BeginInvoke(new Action(() => { this.pb.Top = i; }));
- // this.pb.BeginInvoke(new Action(() => this.pb.BringToFront()));
- }
- }
- }
- else//gora
- {
- for (int i = -88; i < Pociag.form.ClientSize.Height; i++)
- {
- if (Pociag.Rogatka)
- {
- if (i == 205)
- i--;
- else
- if (i < 420 && i > 205)
- i += 3;
- }
- Thread.Sleep(this.sleep);
- if (this.pb != null)
- {
- this.pb.BeginInvoke(new Action(() => { this.pb.Top = i; }));
- this.pb.BeginInvoke(new Action(() => this.pb.BringToFront()));
- }
- }
- }
- Pociag.ludki.Remove(this);
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- namespace Pociagi
- {
- public partial class Form1 : Form
- {
- public Thread train;
- bool czyStart;
- public Form1()
- {
- InitializeComponent();
- Pociag.form = this;
- }
- void Poruszaj()
- {
- if (Thread.CurrentThread == train)
- {
- //car1.BeginInvoke(new Action(() => { car1.Location = new Point(309, a); }));
- //for (Pociag.wartosc = 0; Pociag.wartosc < 764; Pociag.wartosc++)
- for (Pociag.wartosc = 867; Pociag.wartosc > -120; Pociag.wartosc--)
- {
- Thread.Sleep(10);
- //pictureBoxPociag.BeginInvoke(new Action(() => { pictureBoxPociag.Left = Pociag.it; }));
- pictureBoxPociag.BeginInvoke(new Action(() => { pictureBoxPociag.Location = new Point(Pociag.wartosc,304); }));
- //867; 304
- if (Pociag.wartosc == 690)
- {
- pictureBoxRogatkaZamknieta1.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta1.Visible = true; }));
- pictureBoxRogatkaZamknieta2.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta2.Visible = true; }));
- pictureBoxRogatkaOtwarta1.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta1.Visible = false; }));
- pictureBoxRogatkaOtwarta2.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta2.Visible = false; }));
- Pociag.Rogatka = true;
- }
- if (Pociag.wartosc == 233)
- {
- pictureBoxRogatkaZamknieta1.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta1.Visible = false; }));
- pictureBoxRogatkaZamknieta2.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta2.Visible = false; }));
- pictureBoxRogatkaOtwarta1.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta1.Visible = true; }));
- pictureBoxRogatkaOtwarta2.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta2.Visible = true; }));
- Pociag.Rogatka = false;
- }
- if (Pociag.wartosc < -110)
- {
- Pociag.wartosc = 867;
- }
- }
- }
- }
- private void buttonStart_Click(object sender, EventArgs e)
- {
- Pociag.autaGora.Clear();
- Pociag.autaDol.Clear();
- train = new Thread(new ThreadStart(Poruszaj));
- train.Priority = ThreadPriority.AboveNormal;
- train.Start();
- czyStart = true;
- buttonStart.Enabled = false;
- }
- private void buttonQuit_Click(object sender, EventArgs e)
- {
- if (czyStart == true)
- {
- train.Abort();
- foreach (Samochod a in Pociag.autaDol)
- a.watek.Abort();
- Pociag.autaDol.Clear();
- foreach (Samochod a in Pociag.autaGora)
- a.watek.Abort();
- Pociag.autaGora.Clear();
- foreach (Ludziki a in Pociag.ludki)
- a.watek.Abort();
- Pociag.ludki.Clear();
- train.Join();
- }
- Application.Exit();
- }
- private void buttonGora_Click(object sender, EventArgs e)
- {
- if (czyStart)
- {
- Pociag.autaGora.Add(new Samochod(false, 10));
- //new Random().Next(10, 15)
- }
- }
- private void buttonDol_Click(object sender, EventArgs e)
- {
- if (czyStart)
- {
- Pociag.autaDol.Add(new Samochod(true, 10));
- //new Random().Next(10, 15)
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- buttonQuit.PerformClick();
- }
- private void buttonLudziki_Click(object sender, EventArgs e)
- {
- if (czyStart)
- {
- int a = new Random().Next(1, 3);
- // MessageBox.Show("sdasda " + a);
- if (a == 1)
- Pociag.ludki.Add(new Ludziki(true, 10));
- else
- Pociag.ludki.Add(new Ludziki(false, 10));
- //new Random().Next(10, 15)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment