public static void SetPosition(this Rover rover, int x, int y, DirectionStatus direction) { if (rover.position == null) { rover.position = new Position(x, y); } else { rover.position.x = x; rover.position.y = y; } rover.directionStatus = direction; }
public Rover(Plateau plateu, Position position, DirectionStatus directionStatus) { this.plateu = plateu; this.position = position; this.directionStatus = directionStatus; }
private static void MoveVerticalLines(LadderLogicModule ladderLogicModule, List <VerticalLineViewModel> VLines, int cnt) { for (int j = 0; j < VLines.Count(); j++) { var tempVLine = VLines.ElementAt(j); if (tempVLine.X != cnt - 1) { IntPoint point = new IntPoint(); //大于cnt - 1则表示向前移,小于则向后移 if (tempVLine.X > cnt - 1) { //检查VLine周围元素的分布关系,判断是否在移动时需要添加或减少HLine DirectionStatus status = CheckVLine(ladderLogicModule, tempVLine); if (status == DirectionStatus.Down_Inc || status == DirectionStatus.Up_Inc) { if (status == DirectionStatus.Down_Inc) { point.Y = tempVLine.Y + 1; } else if (status == DirectionStatus.Up_Inc) { point.Y = tempVLine.Y; } for (int k = cnt; k <= tempVLine.X; k++) { point.X = k; if (!ladderLogicModule.LadderElements.Exists(x => { return(x.X == point.X && x.Y == point.Y); })) { HorizontalLineViewModel HLine = new HorizontalLineViewModel(); HLine.X = point.X; HLine.Y = point.Y; ladderLogicModule.ReplaceElement(HLine); } } } if (status == DirectionStatus.Down_Dec || status == DirectionStatus.Up_Dec) { if (status == DirectionStatus.Down_Dec) { point.Y = tempVLine.Y + 1; } else { point.Y = tempVLine.Y; } for (int k = cnt; k <= tempVLine.X; k++) { point.X = k; ladderLogicModule.RemoveElement(point.X, point.Y); } } } else { for (int k = tempVLine.X + 1; k <= cnt - 1; k++) { point.X = k; point.Y = tempVLine.Y + 1; if (!ladderLogicModule.LadderElements.Exists(x => { return(x.X == point.X && x.Y == point.Y); })) { HorizontalLineViewModel HLine = new HorizontalLineViewModel(); HLine.X = point.X; HLine.Y = point.Y; ladderLogicModule.ReplaceElement(HLine); } } } ladderLogicModule.RemoveVerticalLine(tempVLine.X, tempVLine.Y); tempVLine.X = cnt - 1; ladderLogicModule.ReplaceVerticalLine(tempVLine); } } }