Guest User

sfsdfdfdsfs

a guest
Jan 25th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.54 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////
  2. /////////////////////////////////////////////////////////////////////
  3. /////////////////////////////////////////////////////////////////////
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.Drawing;
  12.  
  13. namespace Pociagi
  14. {
  15.     class Ludziki
  16.     {
  17.  
  18.  
  19.  
  20.         public bool czyPrawo;
  21.         public int sleep;
  22.  
  23.         public Thread watek;
  24.         private PictureBox pb;
  25.  
  26.         public Ludziki(bool czyPrawo, int sleep)
  27.         {
  28.             this.czyPrawo = czyPrawo;
  29.             this.sleep = sleep;
  30.  
  31.             this.pb = new PictureBox();
  32.  
  33.             if (czyPrawo)
  34.                 this.pb.Location = new Point(867, 262);
  35.             else
  36.                 this.pb.Location = new Point(-20, 262);
  37.  
  38.  
  39.             this.pb.Width = 28;//32; 61
  40.             this.pb.Height = 29;
  41.             this.pb.Image = global::Pociagi.Properties.Resources.Ludzik;
  42.             this.pb.Visible = true;
  43.             Pociag.form.Controls.Add(this.pb);
  44.  
  45.  
  46.  
  47.             this.watek = new Thread(new ThreadStart(this.NaPiechote));
  48.           //  this.watek = new Thread(new ParameterizedThreadStart(Poruszaj_Samochod));
  49.             this.watek.Start();
  50.  
  51.         }
  52.  
  53.         public void NaPiechote()
  54.         {
  55.            
  56.             if (Thread.CurrentThread == this.watek)
  57.             {
  58.  
  59.                 if (this.czyPrawo)
  60.                 {
  61.                     for (int i = 867; i > -30; i--)
  62.                     {
  63.  
  64.                         if (Pociag.Rogatka==false)//dol
  65.                         {
  66.                             if (i == 483)//420
  67.                             {
  68.                                 i++;
  69.  
  70.  
  71.                             }
  72.  
  73.  
  74.                            // else if (i < 420 && i > 205)
  75.                              //   i -= 3;
  76.  
  77.                         }
  78.  
  79.  
  80.  
  81.                         Thread.Sleep(this.sleep);
  82.                         if (this.pb != null && i < 866)
  83.                         {
  84.                             this.pb.BeginInvoke(new Action(() => { this.pb.Location = new Point(i,262); }));
  85.                             //this.pb.BeginInvoke(new Action(() => { this.pb.Top = i; }));
  86.                            // this.pb.BeginInvoke(new Action(() => this.pb.BringToFront()));
  87.  
  88.                         }
  89.                     }
  90.  
  91.  
  92.                 }
  93.                 else//gora
  94.                 {
  95.                     for (int i = -88; i < Pociag.form.ClientSize.Height; i++)
  96.                     {
  97.                         if (Pociag.Rogatka)
  98.                         {
  99.                             if (i == 205)
  100.                                 i--;
  101.                             else
  102.                                 if (i < 420 && i > 205)
  103.                                     i += 3;
  104.                         }
  105.  
  106.                         Thread.Sleep(this.sleep);
  107.                         if (this.pb != null)
  108.                         {
  109.                             this.pb.BeginInvoke(new Action(() => { this.pb.Top = i; }));
  110.                             this.pb.BeginInvoke(new Action(() => this.pb.BringToFront()));
  111.                         }
  112.                     }
  113.  
  114.                 }
  115.                 Pociag.ludki.Remove(this);
  116.             }
  117.         }
  118.  
  119.        
  120.     }
  121. }
  122.  
  123.  
  124. /////////////////////////////////////////////////////////////////////
  125. /////////////////////////////////////////////////////////////////////
  126. /////////////////////////////////////////////////////////////////////
  127.  
  128.  
  129.  
  130. using System;
  131. using System.Collections.Generic;
  132. using System.ComponentModel;
  133. using System.Data;
  134. using System.Drawing;
  135. using System.Linq;
  136. using System.Text;
  137. using System.Windows.Forms;
  138. using System.Threading;
  139.  
  140.  
  141. namespace Pociagi
  142. {
  143.     public partial class Form1 : Form
  144.     {
  145.         public Thread train;
  146.         bool czyStart;
  147.  
  148.        
  149.  
  150.         public Form1()
  151.         {
  152.             InitializeComponent();
  153.             Pociag.form = this;
  154.         }
  155.  
  156.  
  157.         void Poruszaj()
  158.         {
  159.            
  160.  
  161.             if (Thread.CurrentThread == train)
  162.             {
  163.                 //car1.BeginInvoke(new Action(() => { car1.Location = new Point(309, a); }));
  164.                 //for (Pociag.wartosc = 0; Pociag.wartosc < 764; Pociag.wartosc++)
  165.                 for (Pociag.wartosc = 867; Pociag.wartosc > -120; Pociag.wartosc--)
  166.                 {
  167.                     Thread.Sleep(10);
  168.                     //pictureBoxPociag.BeginInvoke(new Action(() => { pictureBoxPociag.Left = Pociag.it; }));
  169.                     pictureBoxPociag.BeginInvoke(new Action(() => { pictureBoxPociag.Location = new Point(Pociag.wartosc,304); }));
  170.                     //867; 304
  171.                     if (Pociag.wartosc == 690)
  172.                     {
  173.                         pictureBoxRogatkaZamknieta1.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta1.Visible = true; }));
  174.                         pictureBoxRogatkaZamknieta2.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta2.Visible = true; }));
  175.                         pictureBoxRogatkaOtwarta1.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta1.Visible = false; }));
  176.                         pictureBoxRogatkaOtwarta2.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta2.Visible = false; }));
  177.                         Pociag.Rogatka = true;
  178.                     }
  179.                     if (Pociag.wartosc == 233)
  180.                     {
  181.                         pictureBoxRogatkaZamknieta1.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta1.Visible = false; }));
  182.                         pictureBoxRogatkaZamknieta2.BeginInvoke(new Action(() => { pictureBoxRogatkaZamknieta2.Visible = false; }));
  183.                         pictureBoxRogatkaOtwarta1.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta1.Visible = true; }));
  184.                         pictureBoxRogatkaOtwarta2.BeginInvoke(new Action(() => { pictureBoxRogatkaOtwarta2.Visible = true; }));
  185.                         Pociag.Rogatka = false;
  186.                     }
  187.                      if (Pociag.wartosc < -110)
  188.                      {
  189.                          Pociag.wartosc = 867;
  190.                      }
  191.                      
  192.                 }
  193.             }
  194.         }
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.         private void buttonStart_Click(object sender, EventArgs e)
  203.         {
  204.             Pociag.autaGora.Clear();
  205.             Pociag.autaDol.Clear();
  206.             train = new Thread(new ThreadStart(Poruszaj));
  207.             train.Priority = ThreadPriority.AboveNormal;
  208.             train.Start();
  209.             czyStart = true;
  210.  
  211.             buttonStart.Enabled = false;
  212.  
  213.  
  214.         }
  215.  
  216.         private void buttonQuit_Click(object sender, EventArgs e)
  217.         {
  218.             if (czyStart == true)
  219.             {
  220.                 train.Abort();
  221.                 foreach (Samochod a in Pociag.autaDol)
  222.                     a.watek.Abort();
  223.                 Pociag.autaDol.Clear();
  224.  
  225.                 foreach (Samochod a in Pociag.autaGora)
  226.                     a.watek.Abort();
  227.                 Pociag.autaGora.Clear();
  228.  
  229.                 foreach (Ludziki a in Pociag.ludki)
  230.                     a.watek.Abort();
  231.                 Pociag.ludki.Clear();
  232.  
  233.  
  234.                 train.Join();
  235.             }
  236.             Application.Exit();
  237.         }
  238.  
  239.         private void buttonGora_Click(object sender, EventArgs e)
  240.         {
  241.             if (czyStart)
  242.             {
  243.                
  244.                     Pociag.autaGora.Add(new Samochod(false, 10));
  245.                     //new Random().Next(10, 15)
  246.                
  247.             }
  248.         }
  249.  
  250.         private void buttonDol_Click(object sender, EventArgs e)
  251.         {
  252.             if (czyStart)
  253.             {
  254.                
  255.              
  256.                     Pociag.autaDol.Add(new Samochod(true, 10));
  257.                     //new Random().Next(10, 15)
  258.                
  259.             }
  260.         }
  261.  
  262.        
  263.        
  264.  
  265.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  266.         {
  267.             buttonQuit.PerformClick();
  268.         }
  269.  
  270.         private void buttonLudziki_Click(object sender, EventArgs e)
  271.         {
  272.             if (czyStart)
  273.             {
  274.                 int a = new Random().Next(1, 3);
  275.                // MessageBox.Show("sdasda   " + a);
  276.                 if (a == 1)
  277.                 Pociag.ludki.Add(new Ludziki(true, 10));
  278.                 else
  279.                 Pociag.ludki.Add(new Ludziki(false, 10));
  280.  
  281.                
  282.                 //new Random().Next(10, 15)
  283.  
  284.             }
  285.         }
  286.        
  287.     }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment