public Program() { wndWidth = 50; wndHeight = 40; score = 0; deltaSpeed = 12; Console.SetWindowSize(wndWidth, wndHeight); Console.SetBufferSize(wndWidth, wndHeight); Console.OutputEncoding = Encoding.UTF8; Console.CursorVisible = false; road = new Road(); road.leftSide = 2; controledCar = new ControlledCar(); oncomingCar = new OncomingCar(); controledCar.setLeft(road.rightSide - controledCar.getWidth()); controledCar.setTop(Console.WindowHeight - controledCar.getLength() - 1); }
private void controlledCarRoutine() { ConsoleKeyInfo key = new ConsoleKeyInfo(); int carLeft, carTop, bottomLimit, leftLimit, rightLimit; while (!Console.KeyAvailable && key.Key != ConsoleKey.Escape) { key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.UpArrow: //Console.WriteLine("UpArrow was pressed"); carTop = controledCar.getTop(); if (--carTop <= 0) { carTop = 0; } controledCar.setTop(carTop); controledCar.wipeBehind(); break; case ConsoleKey.DownArrow: //Console.WriteLine("DownArrow was pressed"); bottomLimit = wndHeight - controledCar.getLength() - 1; carTop = controledCar.getTop(); if (++carTop >= bottomLimit) { carTop = bottomLimit; } controledCar.setTop(carTop); controledCar.wipeBefore(); break; case ConsoleKey.LeftArrow: //Console.WriteLine("LeftArrow was pressed"); leftLimit = road.leftSide + 1; carLeft = controledCar.getLeft(); if (--carLeft <= leftLimit) { carLeft = leftLimit; } controledCar.setLeft(carLeft); controledCar.wipeRight(); break; case ConsoleKey.RightArrow: //Console.WriteLine("RightArrow was pressed"); rightLimit = road.rightSide - controledCar.getWidth(); carLeft = controledCar.getLeft(); if (++carLeft >= rightLimit) { carLeft = rightLimit; } controledCar.setLeft(carLeft); controledCar.wipeLeft(); break; case ConsoleKey.Escape: break; } controledCar.draw(); } }