// PE911 Зырянов Павел // д/з урок 9 "Автомобильные гонки" // от 13.11.2020 static void Main(string[] args) { PlayGame play = new PlayGame(); char q = PrintGame.Greeting(); if (q == '1') { play.InitDefaultDriverNames(); } else if (q == '2') { InputDriverNamesTypeCar(play); } try { if (q != '0') { play.Play(0); } } catch (Exception ex) { if (ex.Message != "exit") { PrintGame.PrintExceptionInfo(ex.Message); } } Clear(); PrintGame.Bye(); ReadKey(); }
public void BeforeStart() { SetWindowSize(150, 40); foreach (var item in cars) { item.MaxSpeed = Car._random.Next (MinForRandomCarSpeed, MaxForRandomCarSpeed); prepareCarEvent += new Action(item.Prepare); driveCarEvent += new Action(item.Drive); } finishEvent += GameOver; PrintGame.PrintBoard(cars); }
void PlayAgain() { if (Again()) { foreach (var item in cars) { item.Position = 1200; item.MaxSpeed = Car._random.Next (MinForRandomCarSpeed, MaxForRandomCarSpeed); } PrintGame.PrintBoard(cars); Play(1); } else { throw new Exception("exit"); } }
public void Play(int n) { try { if (n == 0) { BeforeStart(); } OnPrepareCarEvent(); PrintGame.CountDown(); while (true) { OnDriveCarEvent(); PrintGame.PrintGameInfo(cars); if (CheckFinish()) { OnFinishEvent(); } System.Threading.Thread.Sleep(40); } } catch (Exception ex) { if (ex.Message != "exit") { PrintGame.PrintExceptionInfo(ex.Message); } else { throw new Exception("exit"); } } }