Пример #1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     SinhXe++;
     if (SinhXe == ((xecuatui.H / tocdo) * 2))
     {
         xemoi   = new Xe(2);
         xemoi.g = g2;
         xemoi.VeXe(true);
         xemoi.TocDo = tocdo;
         doixe.Add(xemoi);
         SinhXe = 0;
     }
     if (doixe.Count > 0)
     {
         for (int i = 0; i < doixe.Count; i++)
         {
             doixe[i].ChuyenDong();
             if (doixe[i].ViTri.Y > this.panel1.Height)
             {
                 doixe[i].VeXe(false);
                 doixe.RemoveAt(i);
                 diemso++;
                 TinhDiem();
             }
             KiemTraVaCham(doixe[i]);
         }
     }
 }
Пример #2
0
 private void KiemTraVaCham(Xe xe)
 {
     if (xe.ViTri.X > (xecuatui.ViTri.X - xecuatui.W) && xe.ViTri.X < (xecuatui.ViTri.X + xecuatui.W) && xe.ViTri.Y > (xecuatui.ViTri.Y - xecuatui.H) && xe.ViTri.Y < (xecuatui.ViTri.Y + xecuatui.H))
     {
         timer.Stop();
         MessageBox.Show("Tai nạn rồi!");
     }
 }
Пример #3
0
 private void btnMotXe_Click(object sender, EventArgs e)
 {
     tocdo           = 1;
     timer2.Interval = 30;
     xemoi1          = new Xe(2);
     xemoi1.g        = g2;
     xemoi1.VeXe(true);
     xemoi1.TocDo = tocdo;
     timer2.Start();
 }
Пример #4
0
        private void btnKhoiTao_Click(object sender, EventArgs e)
        {
            g = this.panel1.CreateGraphics();

            #region "VeXeCuaTui"
            xecuatui        = new Xe();
            xecuatui.LoaiXe = 1;
            xecuatui.W      = 60;
            xecuatui.H      = 120;
            Point vitrixecuatui = new Point(this.panel1.Width - xecuatui.W, this.panel1.Height - xecuatui.H);
            xecuatui.ViTri = vitrixecuatui;
            xecuatui.g     = g;
            xecuatui.VeXe(true);
            #endregion
        }
Пример #5
0
 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     SinhXe++;
     if (SinhXe == ((xecuatui.H / tocdo) * 2))
     {
         xemoi   = new Xe(2);
         xemoi.g = g2;
         xemoi.VeXe(true);
         doixe.Add(xemoi);
         SinhXe = 0;
     }
     for (int i = 0; i < doixe.Count; i++)
     {
         doixe[i].ChuyenDong();
         if (doixe[i].ViTri.Y > this.panel1.Height)
         {
             doixe[i].VeXe(false);
             doixe.RemoveAt(i);
             diemso++;
             //TinhDiem();
         }
         KiemTraVaCham(doixe[i]);
     }
 }