Public void Handlerev()
{ bool crash = false; for (int i = 0; i < al.Count; i++) { Avto a = (Avto)al[i];
if (a.life) for (int j = i; j < al.Count; j++) { Avto a1 = (Avto)al[j];
if ((a.num!= a1.num) && (Math.Abs(a1.x - a.x) < 10) && (Math.Abs(a1.y - a.y) < 10)) { Console.WriteLine("Автомобили " + a.num +" и "+ a1.num + " врезались"); crash = true; a.run = false; a1.run = false; Thread.Sleep(500); a.run = true; a1.run = true; run = true;
if (crash) { if ((a.x > a1.x)||(a.y > a1.y)) { a.x += 2; a1.x -= 1; a.y += 2; a1.y -= 1; crash = false; } else { a1.x += 2; a.x -= 1; a1.y += 2; a.y -= 1; crash = false; } Console.WriteLine("Автомобили " + a.num + " и " + a1.num + " разъехались");
}
} } }
}
… } }
static void Main() { Application.Run(new Avtos()); } } Результат:
Пример 5.3.5.2. Реализация пятого этапа разработки Avtos–приложения на языке C++/CLI. // kurs.cc.cpp: main project file.
#include "stdafx.h" #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Threading;
|