private void addtoPath(direction dir, int id) { pathDirection pd = new pathDirection(dir, id); if (!inbounds(pd.id)) { boundsError = true; } else { path.Add(pd); pathSize++; p[pd.id].selected = true; } }
private void check(pathDirection pd) { if (pd.id < 0) { System.Console.WriteLine(pd.id + "\n"); } switch (pd.dir) //0 none, 1 up, 2 down, 3 left, 4 right { case direction.up: { if (pd.id - width > 0) { if (!p[pd.id - width].selected && !p[pd.id - width].found) { addtoPath(direction.up, pd.id - width); //up } } if (pd.id % width != 0) { if (!p[pd.id - 1].selected && !p[pd.id - 1].found) { addtoPath(direction.left, pd.id - 1); //left } } if ((pd.id + 1) % width != 0) { if (!p[pd.id + 1].selected && !p[pd.id + 1].found) { addtoPath(direction.right, pd.id + 1); //right } } break; } case direction.down: { if (pd.id + width < total) { if (!p[pd.id + width].selected && !p[pd.id + width].found) { addtoPath(direction.down, pd.id + width); //down } } if (pd.id % width != 0) { if (!p[pd.id - 1].selected && !p[pd.id - 1].found) { addtoPath(direction.left, pd.id - 1); //left } } if ((pd.id + 1) % width != 0) { if (!p[pd.id + 1].selected && !p[pd.id + 1].found) { addtoPath(direction.right, pd.id + 1); //right } } break; } case direction.left: { if (pd.id - width > 0) { if (!p[pd.id - width].selected && !p[pd.id - width].found) { addtoPath(direction.up, pd.id - width); //up } } if (pd.id + width < total) { if (!p[pd.id + width].selected && !p[pd.id + width].found) { addtoPath(direction.down, pd.id + width); //down } } if (pd.id % width != 0) { if (!p[pd.id - 1].selected && !p[pd.id - 1].found) { addtoPath(direction.left, pd.id - 1); //left } } break; } case direction.right: { if (pd.id - width > 0) { if (!p[pd.id - width].selected && !p[pd.id - width].found) { addtoPath(direction.up, pd.id - width); //up } } if (pd.id + width < total) { if (!p[pd.id + width].selected && !p[pd.id + width].found) { addtoPath(direction.down, pd.id + width); //down } } if ((pd.id + 1) % width != 0) { if (!p[pd.id + 1].selected && !p[pd.id + 1].found) { addtoPath(direction.right, pd.id + 1); //right } } break; } case direction.none: { if (pd.id - width > 0) { if (!p[pd.id - width].selected && !p[pd.id - width].found) { addtoPath(direction.up, pd.id - width); //up } } if (pd.id + width < total) { if (!p[pd.id + width].selected && !p[pd.id + width].found) { addtoPath(direction.down, pd.id + width); //down } } if (pd.id % width != 0) { if (!p[pd.id - 1].selected && !p[pd.id - 1].found) { addtoPath(direction.left, pd.id - 1); //left } } if ((pd.id + 1) % width != 0) { if (!p[pd.id + 1].selected && !p[pd.id + 1].found) { addtoPath(direction.right, pd.id + 1); //right } } break; } } }