static void Main(string[] args) { PaintingRobot[] robots = new PaintingRobot[5]; robots[0] = new PaintingRobot(); robots[1] = new RobotNTimes(robots[0]); robots[2] = new RobotLog(robots[1]); robots[3] = new RobotplusN(robots[2]); robots[4] = new Compaund(robots[1], robots[2], robots[3]); foreach (var robot in robots) { Console.WriteLine($"Current robot: {robot}"); Console.WriteLine($"Painted length in 2 time units: {robot.GetPaintedLength(2)}."); Console.WriteLine($"Painted length in 3 time units: {robot.GetPaintedLength(3)}."); Console.WriteLine(""); } PaintingRobot robot2 = new PaintingRobot(); robot2 = new RobotNTimes(robot2); robot2 = new RobotplusN(robot2, 10); robot2 = new RobotNTimes(robot2, 3); Console.WriteLine($"Current robot: {robot2}"); Console.WriteLine($"Painted length in 2 time units: {robot2.GetPaintedLength(2)}."); Console.WriteLine($"Painted length in 3 time units: {robot2.GetPaintedLength(3)}."); Console.WriteLine(""); }
public string DescriptionTemplate(string name, PaintingRobot r2) { string result = r2.ToString(); result = result.Replace("\n", "\n\t"); return($"{name} {this.GetPaintedLength(1)}\n(\n\t{result}\n)"); }
public override double GetPaintedLength(double time) { double max = 0; foreach (var r in robots) { if (r.GetPaintedLength(time) > max) { max = r.GetPaintedLength(time); curr = r; } } return(max); }
public RobotDecoratorNlogN(PaintingRobot robot) { this.robot = robot; }
public RobotDecoratorMultiply(PaintingRobot robot, double n) { this.robot = robot; this.n = n; }
public RobotDecoratorAdd(PaintingRobot robot, double n) { this.robot = robot; this.n = n; }
public RobotLog(PaintingRobot r) : base(r) { }
public RobotplusN(PaintingRobot r, int n1 = 1) : base(r) { this.n = n1; }
public RobotNTimes(PaintingRobot r, int _n = 2) : base(r) { n = _n; }
public RobotDecorator(PaintingRobot _robot) { robot = _robot; }