private void executeCommand(Day12Command command) { string instruction = command.instruction; if (instruction == "F") { switch (this.direction) { case 0: instruction = "E"; break; case 1: instruction = "S"; break; case 2: instruction = "W"; break; case 3: instruction = "N"; break; } } switch (instruction) { case "N": this.coordinates[1] += command.units; break; case "S": this.coordinates[1] -= command.units; break; case "E": this.coordinates[0] += command.units; break; case "W": this.coordinates[0] -= command.units; break; case "L": this.direction = (this.direction - (uint)(command.units / 90)) % 4; break; case "R": this.direction = (this.direction + (uint)(command.units / 90)) % 4; break; } }
private void executeCommand(Day12Command command) { switch (command.instruction) { case "N": this.waypointCoordinates[1] += command.units; break; case "S": this.waypointCoordinates[1] -= command.units; break; case "E": this.waypointCoordinates[0] += command.units; break; case "W": this.waypointCoordinates[0] -= command.units; break; case "L": for (int i = 0; i < command.units / 90; i++) { int tempY = this.waypointCoordinates[1]; this.waypointCoordinates[1] = this.waypointCoordinates[0]; this.waypointCoordinates[0] = -tempY; } break; case "R": for (int i = 0; i < command.units / 90; i++) { int tempX = this.waypointCoordinates[0]; this.waypointCoordinates[0] = this.waypointCoordinates[1]; this.waypointCoordinates[1] = -tempX; } break; case "F": this.shipCoordinates[0] += (command.units * this.waypointCoordinates[0]); this.shipCoordinates[1] += (command.units * this.waypointCoordinates[1]); break; } }