Exemplo n.º 1
0
        public void CheckTrack(Bolide Bolide)
        {
            X = -100;
            Y = Bolide.Y;
            int speed = RaceConfig.rnd.Next(10);

            while (!TrackChecked)
            {
                X += speed;
                Thread.Sleep(5);
                if (Math.Abs(X - Bolide.X) < 105)
                {
                    int time = RaceConfig.rnd.Next(100, 300);
                    Thread.Sleep(time);
                    TrackChecked = true;
                }
            }
            while (Y < TrackHeight + 50)
            {
                Y += speed;
                Thread.Sleep(5);
            }
            X            = -100;
            Y            = -100;
            Busy         = false;
            TrackChecked = false;
        }
Exemplo n.º 2
0
        private void BolideBroken(Bolide b)
        {
            ILoader reparer = null;
            bool    found   = false;

            while (!found)
            {
                lock (Loaders)
                {
                    foreach (ILoader l in Loaders)
                    {
                        if (!l.Busy && (l is ReparingLoader))
                        {
                            l.Busy  = true;
                            reparer = l;
                            break;
                        }
                    }
                }
                if (reparer != null)
                {
                    found = true;
                    reparer.InteractingWithBolide(b);
                }
            }
        }
Exemplo n.º 3
0
        private void Cleaning(Bolide b)
        {
            ILoader cleaner = null;
            bool    found   = false;

            while (!found)
            {
                lock (Loaders)
                {
                    foreach (ILoader l in Loaders)
                    {
                        if (!l.Busy && (l is CleaningLoader))
                        {
                            l.Busy  = true;
                            cleaner = l;
                            break;
                        }
                    }
                }
                if (cleaner != null)
                {
                    found = true;
                    cleaner.InteractingWithBolide(b);
                }
            }
        }
Exemplo n.º 4
0
        private void FixBolide(Bolide Bolide)
        {
            //Console.WriteLine(Name + ';' + Busy + ';' + Bolide.Name);

            if (!OnWayToHome)
            {
                X = Bolide.X;
            }

            while (Y > Bolide.Y && Bolide.Crashed && !OnWayToHome)
            {
                int speed = RaceConfig.rnd.Next(5);
                Y -= speed;
                Thread.Sleep(5);
                if (Math.Abs(Y - Bolide.Y) < 40)
                {
                    int time = RaceConfig.rnd.Next(7000, 12000);
                    Bolide.WaitingTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    Thread.Sleep(time);
                    Bolide.Crashed = false;
                    Bolide.Arguing = false;
                }
            }

            while (Y < TrackHeight + 110)
            {
                int speed = 5;
                Y += speed;
                Thread.Sleep(5);
            }
            Y    = TrackHeight + 110;
            Busy = false;
        }
Exemplo n.º 5
0
        public void AddRacer(string Name)
        {
            if (!RaceIsOn)
            {
                Bolide newbolide = new Bolide(Name);
                Bolides.Add(newbolide);

                Mechanic newmechanic = new Mechanic(Name, newbolide);
                newmechanic.SetPosition(TrackWidth, TrackHeight);
                Mechanics.Add(newmechanic);

                SetStartGrid();
            }
            else
            {
                throw new Exception("Гонка уже началась! Сначала остановите гонку");
            }
        }
Exemplo n.º 6
0
 public void FixBolide(Bolide Bolide)
 {
     X = Bolide.X;
     while (Y < Bolide.Y && Bolide.TiresWornOut)
     {
         int speed = 5;
         Y += speed;
         Thread.Sleep(5);
         if (Math.Abs(Y - Bolide.Y) < 10)
         {
             int time = RaceConfig.rnd.Next(1000, 5000);
             Thread.Sleep(time);
             Bolide.TiresCondition = RaceConfig.DefaultTiresCondition;
             Bolide.TiresWornOut   = false;
         }
     }
     while (Y > -110)
     {
         int speed = 5;
         Y -= speed;
         Thread.Sleep(5);
     }
 }
Exemplo n.º 7
0
 public void InteractingWithBolide(Bolide bolide)
 {
     Task.Run(() => CheckTrack(bolide));
     Busy = false;
 }
Exemplo n.º 8
0
 private async void BolideBrokenAsync(Bolide b)
 {
     await Task.Run(() => BolideBroken(b));
 }
Exemplo n.º 9
0
 public void InteractingWithBolide(Bolide bolide)
 {
     Task.Run(() => FixBolide(bolide));
 }
Exemplo n.º 10
0
 private void Fix(Bolide b)
 {
     Task.Run(() => FixBolide(b));
 }
Exemplo n.º 11
0
 public Mechanic(string Name, Bolide Bolide)
 {
     this.Name     = Name;
     this.Bolide   = Bolide;
     Bolide.Tires += Fix;
 }