本文整理汇总了C#中Square.SelectOpenSide方法的典型用法代码示例。如果您正苦于以下问题:C# Square.SelectOpenSide方法的具体用法?C# Square.SelectOpenSide怎么用?C# Square.SelectOpenSide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Square
的用法示例。
在下文中一共展示了Square.SelectOpenSide方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildMaze
//.........这里部分代码省略.........
currentSquare.RemoveSide(Square.Direction.LEFT);
// set last side to left
lastSide = Square.Direction.LEFT;
// while there remains any blocked square in the grid
while (maze.IsAnyBlocked()) {
// set bool addingSquare to false
addingSquareFlag = false;
// create a random sequence of the 0, 1, 2, or 3 remaining walls for currentSquare
// exclude sides that lead to unblocked squares (squares that are already in the maze)
directions.Clear();
if (currentSquare.HasSide(Square.Direction.LEFT)) {
if (currentSquare.AdjacentSquare(Square.Direction.LEFT) != null &&
currentSquare.AdjacentSquare(Square.Direction.LEFT).IsBlocked()) {
directions.Add(Square.Direction.LEFT);
}
}
if (currentSquare.HasSide(Square.Direction.RIGHT)) {
if (currentSquare.AdjacentSquare(Square.Direction.RIGHT) != null &&
currentSquare.AdjacentSquare(Square.Direction.RIGHT).IsBlocked()) {
directions.Add(Square.Direction.RIGHT);
}
}
if (currentSquare.HasSide(Square.Direction.TOP)) {
if (currentSquare.AdjacentSquare(Square.Direction.TOP) != null &&
currentSquare.AdjacentSquare(Square.Direction.TOP).IsBlocked()) {
directions.Add(Square.Direction.TOP);
}
}
if (currentSquare.HasSide(Square.Direction.BOTTOM)) {
if (currentSquare.AdjacentSquare(Square.Direction.BOTTOM) != null &&
currentSquare.AdjacentSquare(Square.Direction.BOTTOM).IsBlocked()) {
directions.Add(Square.Direction.BOTTOM);
}
}
// exclude lastSide
directions.Remove(lastSide);
// shuffle them
Shuffle(directions);
foreach (Square.Direction dir in directions) {
// let nextSide be the current element in this sequence
Square.Direction nextSide = dir;
// if square adjacent to the current square on side nextSide exists and is blocked
if (currentSquare.AdjacentSquare(nextSide) != null && currentSquare.AdjacentSquare(nextSide).IsBlocked()) {
// remove walls that separate currentSquare and adjacentSquare
Square adjacent = currentSquare.AdjacentSquare(nextSide);
currentSquare.RemoveSide(nextSide);
adjacent.RemoveSide(Square.OppositeSide(nextSide));
// add path to adjacency matrix
int u = ConvertToNode(currentSquare.Row, currentSquare.Column);
int v = ConvertToNode(adjacent.Row, adjacent.Column);
adjacentMatrix[u, v] = true;
adjacentMatrix[v, u] = true;
// adjacentSquare becomes currentSquare
currentSquare = adjacent;
// set boolean addingSquareFlag to true
addingSquareFlag = true;
// set lastSide to the opposite of nextSide
lastSide = Square.OppositeSide(nextSide);
break;
}
}
// this means we couldn't find any adjacent square to move to in the for loop above
// we now have to backtrack by picking a random unblocked square elsewhere in the maze
// and try to build a path from that point
if (!addingSquareFlag) {
// pick an unblocked square (already in the maze) from the grid at
// random, optionally ensuring that it is adjacent to at least one
// blocked square (not already in the maze)
// this becomes the current square
currentSquare = maze.SelectRandomUnblockedSquare();
if (currentSquare == null)
break;
// randomly pick an open side (one with wall already removed) of the
// current square, this becomes lastSide
lastSide = currentSquare.SelectOpenSide();
}
// redraw
UpdateDrawing();
}
// update state
mazeState = MazeState.BUILT;
}