Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. public abstract class Car
  6. {
  7. string name;
  8. int x = 1;
  9. public int X
  10. {
  11. get { return x; }
  12. set { x = Step; }
  13. }
  14. public string Name
  15. {
  16. get { return name; }
  17. set { name = value; }
  18. }
  19. public abstract char Symbol
  20. {
  21. get;
  22. }
  23. public abstract int Step
  24. {
  25. get;
  26. }
  27. public void PrintOnMap(int width)
  28. {
  29. Console.WriteLine("Name = {0}; Symbol = '{1}'; X = {2}; width = {3}", name, Symbol, X, width);
  30. Console.Write("[");
  31. for (int i = 1; i <= width; i++)
  32. {
  33. if (i == X)
  34. Console.Write("1");
  35. else Console.Write("-");
  36. }
  37. Console.Write("]");
  38. }
  39. }
  40. public class SpeedCar : Car
  41. {
  42. char ch;
  43. Random rand = new Random();
  44. public override char Symbol
  45. {
  46. get { return '>'; }
  47. }
  48. public override int Step
  49. {
  50. get { return X + rand.Next(3, 6); }
  51. }
  52. public SpeedCar(string name)
  53. {
  54. Name = name;
  55. }
  56. }
  57. public class SlowCar : Car
  58. {
  59. Random rand = new Random();
  60. public override char Symbol
  61. {
  62. get { return 'o'; }
  63. }
  64. public override int Step
  65. {
  66. get { return X + rand.Next(0, 3); }
  67. }
  68. public SlowCar(string name)
  69. {
  70. Name = name;
  71. }
  72. }
  73. class Program
  74. {
  75. static void Main()
  76. {
  77. string lower = "qwertyuiopasdfghjklzxcvbnm";
  78. string upper = "QWERTYUIOPASDFGHJKLZXCVBNM";
  79. Random rand = new Random();
  80. int width = rand.Next(10, 31);
  81. Car[] car = new Car[5];
  82. for (int i = 0; i < 5; i++)
  83. {
  84. string line = "";
  85. line += upper[rand.Next(26)];
  86. for (int y = 0; y < 6; y++)
  87. {
  88. line += lower[rand.Next(26)];
  89. }
  90.  
  91. if (rand.Next(0,2) == 0)
  92. {
  93. car[i] = new SpeedCar(line);
  94. car[i].PrintOnMap(width);
  95. }
  96. else
  97. {
  98. car[i] = new SlowCar(line);
  99. car[i].PrintOnMap(width);
  100. }
  101. Console.WriteLine();
  102. }
  103.  
  104. Console.ReadKey();
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement