Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- public abstract class Car
- {
- string name;
- int x = 1;
- public int X
- {
- get { return x; }
- set { x = Step; }
- }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public abstract char Symbol
- {
- get;
- }
- public abstract int Step
- {
- get;
- }
- public void PrintOnMap(int width)
- {
- Console.WriteLine("Name = {0}; Symbol = '{1}'; X = {2}; width = {3}", name, Symbol, X, width);
- Console.Write("[");
- for (int i = 1; i <= width; i++)
- {
- if (i == X)
- Console.Write("1");
- else Console.Write("-");
- }
- Console.Write("]");
- }
- }
- public class SpeedCar : Car
- {
- char ch;
- Random rand = new Random();
- public override char Symbol
- {
- get { return '>'; }
- }
- public override int Step
- {
- get { return X + rand.Next(3, 6); }
- }
- public SpeedCar(string name)
- {
- Name = name;
- }
- }
- public class SlowCar : Car
- {
- Random rand = new Random();
- public override char Symbol
- {
- get { return 'o'; }
- }
- public override int Step
- {
- get { return X + rand.Next(0, 3); }
- }
- public SlowCar(string name)
- {
- Name = name;
- }
- }
- class Program
- {
- static void Main()
- {
- string lower = "qwertyuiopasdfghjklzxcvbnm";
- string upper = "QWERTYUIOPASDFGHJKLZXCVBNM";
- Random rand = new Random();
- int width = rand.Next(10, 31);
- Car[] car = new Car[5];
- for (int i = 0; i < 5; i++)
- {
- string line = "";
- line += upper[rand.Next(26)];
- for (int y = 0; y < 6; y++)
- {
- line += lower[rand.Next(26)];
- }
- if (rand.Next(0,2) == 0)
- {
- car[i] = new SpeedCar(line);
- car[i].PrintOnMap(width);
- }
- else
- {
- car[i] = new SlowCar(line);
- car[i].PrintOnMap(width);
- }
- Console.WriteLine();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement