2using static System.Console;
9 public abstract class Car {
12 /// A random number generator.
14 protected static Random rand = new Random();
17 /// The field storing x.
22 /// The x position of the car. Must be >= 1.
29 throw new Exception("X must be larger than 1");
36 /// The name of the car.
38 /// <value>The name.</value>
39 public string Name { get; set; }
42 /// The symbol represnting the car on screen.
44 /// <value>The symbol.</value>
45 public abstract Char Symbol { get; }
48 /// Moves the car a set random number of units.
50 public abstract void Step();
53 /// Prints the car to the console.
55 /// <param name="width">The width of the road.</param>
56 public void PrintOnMap(int width) {
58 throw new Exception("Width can not be negative");
60 var map = $"{Name}:\t [";
61 for (var i = 0; i < width; i++) {
76 public class SpeedCar: Car {
78 /// The symbol represnting the car on screen.
80 /// <value>The symbol.</value>
81 public override char Symbol => '>';
84 /// Moves the car form 3 to 5 units in the positive x direction.
86 public override void Step() {
91 /// Initializes a new instance of the <see cref="T:Cars.SpeedCar"/> class.
93 /// <param name="name">Name.</param>
94 public SpeedCar(string name) {
102 public class SlowCar: Car {
104 /// The symbol represnting the car on screen.
106 /// <value>The symbol.</value>
107 public override char Symbol => 'o';
110 /// Moves the car form 0 to 2 units in the positive x direction.
112 public override void Step() {
113 X += rand.Next(0, 3);
117 /// Initializes a new instance of the <see cref="T:Cars.SlowCar"/> class.
119 /// <param name="name">Name.</param>
120 public SlowCar(string name) {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list