Untitled
unknown
csharp
a year ago
1.7 kB
4
Indexable
Never
using System; class Program { static void Main(string[] args) { Random r = new Random(); int size = r.Next(1, 5); int r_size = (4 * size) + 1; int mid = (r_size - 1)/2; int x, y; string[,] array = new string[r_size, r_size]; for ( y = 0; y < r_size; y++) { for ( x = 0; x < r_size; x++) { array[y, x] = "*"; } } int point_x = mid + 1; int point_y = mid - 1; int walk = 2; x = mid + 1; y = mid - 1; while (x <= array.GetUpperBound(1) && y <= array.GetUpperBound(0)) { for (x = point_x; x > point_x - walk; x--) { array[y, x] = " "; } point_x = x; for (y = point_y; y < point_y + walk ; y++) { array[y, x] = " "; } point_y = y; walk = walk + 2; for (x = point_x; x < point_x + walk; x++) { array[y, x] = " "; if (x >= array.GetUpperBound(1)) break; } if (x >=array.GetUpperBound(1)) { if (y >= array.GetUpperBound(0) - 1) break; } point_x = x; for (y = point_y; y > point_y - walk; y--) { array[y, x] = " "; } point_y = y; walk = walk + 2; } for ( y = 0; y < r_size; y++) { for ( x = 0; x < r_size; x++) { Console.Write(array[y, x] + " "); } Console.WriteLine(); }