public override string ToString() { char[,] map = BoardSetting.GetMap(); for (int i = 0; i < Pieces.Length; i++) { Point pos = Pieces[i].Position; foreach (Point offset in Pieces[i].Shape) { map[pos.X + offset.X, pos.Y + offset.Y] = GetMark(i); } } sb.Length = 0; for (int y = 0; y < BoardSetting.Height; y++) { for (int x = 0; x < BoardSetting.Width; x++) { sb.Append(map[x, y]); } sb.AppendLine(); } return(sb.ToString().Trim()); }
public Board[] Move(int num, Direction direction) { // 移動判定用 準備 char[,] map = BoardSetting.GetMap(); for (int i = 0; i < Pieces.Length; i++) { Point pos1 = Pieces[i].Position; if (i != num) { foreach (Point offset in Pieces[i].Shape) { map[pos1.X + offset.X, pos1.Y + offset.Y] = '*'; } } } // 方向 int xSign = 0, ySign = 0; if (direction == Direction.UP) { ySign = -1; } else if (direction == Direction.DOWN) { ySign = 1; } else if (direction == Direction.RIGHT) { xSign = 1; } else if (direction == Direction.LEFT) { xSign = -1; } // 移動判定 Board[] result = new Board[0]; int count = 1; while (true) { Point pos = Pieces[num].Position; pos = new Point(pos.X + xSign * count, pos.Y + ySign * count); foreach (Point offset in Pieces[num].Shape) { int x = pos.X + offset.X; int y = pos.Y + offset.Y; if (x < 0 || map.GetLength(0) <= x || y < 0 || map.GetLength(1) <= y || map[x, y] != ' ') { return(result); } } Board next = new Board(this); next.Pieces[num] = new Piece(next.Pieces[num].ShapeNo, pos); next.PreviousMove = new MoveData(num, direction, count); next.MoveCount++; Board[] tmp = new Board[result.Length + 1]; result.CopyTo(tmp, 0); result = tmp; result[result.Length - 1] = next; count++; } }