public For(int start, int end, Func<int, Instruction> getBody) { this.start = start; //0 this.end = end; //10 this.getBody = getBody; //a delegate instance points towards a method this.i = start; //0 this.body = getBody(i); //getBody(0); }
public override InstructionResult Execute(float deltaTime) { switch (body.Execute(deltaTime)) { case InstructionResult.Done: body = body.Reset(); return InstructionResult.Running; case InstructionResult.DoneAndCreateEnemyObject: body = body.Reset(); return InstructionResult.RunningAndCreateEnemyObject; case InstructionResult.Running: return InstructionResult.Running; case InstructionResult.RunningAndCreateEnemyObject: return InstructionResult.RunningAndCreateEnemyObject; } return InstructionResult.Running; }
public override InstructionResult Execute(float deltaTime) { if (i >= end) { return InstructionResult.Done; } else { switch (body.Execute(deltaTime)) { //0 case InstructionResult.Done: i++; body = getBody(i); //returning back for the switch case return InstructionResult.Running; //1 case InstructionResult.DoneAndCreateEnemyObject: i++; body = getBody(i); //returning back for the switch case return InstructionResult.RunningAndCreateEnemyObject; case InstructionResult.Running: //returning back for the switch case return InstructionResult.Running; case InstructionResult.RunningAndCreateEnemyObject: //returning back for the switch case return InstructionResult.RunningAndCreateEnemyObject; } return InstructionResult.Done; } }
public Semicolon(Instruction A, Instruction B) { this.A = A; this.B = B; }
public Repeat(Instruction body) { this.body = body; }