Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get automatic characters
- var automaticcharacters = new List<CharacterPositioner>();
- foreach (var character in row.Value)
- {
- if (character.IsPositionedAutomatically())
- {
- automaticcharacters.Add(character);
- }
- }
- automaticcharacters.Sort();
- switch (automaticcharacters.Count)
- {
- case 0:
- break;
- case 1:
- automaticcharacters[0].MoveCharacter(null, 0, null);
- break;
- default:
- //Determine max
- var max = 1;
- switch (automaticcharacters.Count)
- {
- default:
- max = 1;
- break;
- }
- //Determine step
- int numberofsteps = automaticcharacters.Count;
- if (numberofsteps % 2 == 1)
- {
- numberofsteps--;
- }
- numberofsteps /= 2;
- var step = max / numberofsteps;
- if (automaticcharacters.Count % 2 == 1)
- {
- //Operate on the middle
- var middleindex = automaticcharacters.Count / 2;
- automaticcharacters[middleindex].MoveCharacter(null, 0, null);
- //Operate on the left
- for (int i = middleindex-1; i > -1; i--)
- {
- var stepnumber = middleindex - i;
- automaticcharacters[i].MoveCharacter(null, -step * stepnumber, null);
- }
- //Operate on the right
- for (int i = middleindex + 1; i < automaticcharacters.Count; i++)
- {
- var stepnumber = i - middleindex;
- automaticcharacters[i].MoveCharacter(null, step * stepnumber, null);
- }
- }
- else
- {
- var leftindex = (automaticcharacters.Count / 2) - 1;
- var rightindex = leftindex + 1;
- //Operate on the left
- for (int i = leftindex; i > -1; i--)
- {
- var stepnumber = (leftindex + 1) - i;
- automaticcharacters[i].MoveCharacter(null, -step * stepnumber, null);
- }
- //Operate on the right
- for (int i = rightindex; i < automaticcharacters.Count; i++)
- {
- var stepnumber = i - (rightindex - 1);
- automaticcharacters[i].MoveCharacter(null, step * stepnumber, null);
- }
- }
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement