private static ThisDay.Direction GetNewDirection(ThisDay.Direction currentlyFacing, ThisDay.Direction directionToTurn) { var result = (int)currentlyFacing; switch (directionToTurn) { case ThisDay.Direction.Left: result--; break; case ThisDay.Direction.Right: result++; break; default: break; } if (result < 1) { result = 4; } if (result > 4) { result = 1; } return((ThisDay.Direction)result); }
private static (int NewRowIndex, int NewtColumnIndex) MoveForward(int currentRowIndex, int currentColumnIndex, ThisDay.Direction currentlyFacing, List <List <Coordinate> > map) { switch (currentlyFacing) { case ThisDay.Direction.Up: if (currentRowIndex == 0) { //insert new row var newRow = new List <Coordinate>(); for (int i = 0; i < map[currentRowIndex].Count; i++) { newRow.Add(new Coordinate { CurrentState = State.NotInfected }); } map.Insert(0, newRow); currentRowIndex++; } currentRowIndex--; break; case ThisDay.Direction.Right: if (currentColumnIndex == map[currentRowIndex].Count - 1) { //add new item to every row foreach (var item in map) { item.Add(new Coordinate { CurrentState = State.NotInfected }); } } currentColumnIndex++; break; case ThisDay.Direction.Down: if (currentRowIndex == map.Count - 1) { //insert new row var newRow = new List <Coordinate>(); for (int i = 0; i < map[currentRowIndex].Count; i++) { newRow.Add(new Coordinate { CurrentState = State.NotInfected }); } map.Add(newRow); } currentRowIndex++; break; case ThisDay.Direction.Left: if (currentColumnIndex == 0) { //insert new item in each row foreach (var item in map) { item.Insert(0, new Coordinate { CurrentState = State.NotInfected }); } currentColumnIndex = 1; } currentColumnIndex--; break; default: break; } return(currentRowIndex, currentColumnIndex); }