namespace ConsoleApplication1
{
public static class MazeGenerator_Bar
{ // 通路・壁情報 const int Path = 0;
const int Wall = 1;
// 棒倒し法による迷路生成 public static int[,] GenerateMaze(int width, int height)
{ // 5未満のサイズでは生成できない if (height < 5 || width < 5) throw new ArgumentOutOfRangeException();
if (width % 2 == 0) width++;
if (height % 2 == 0) height++;
// 指定サイズで生成し外周を壁にする var maze = new int[width, height];
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
if (x == 0 || y == 0 || x == width - 1 || y == height - 1)
maze[x, y] = Wall; // 外周はすべて壁 else
maze[x, y] = Path; // 外周以外は通路
// 棒を立て、倒す var rnd = new Random();
for (int x = 2; x < width - 1; x += 2)
{
for (int y = 2; y < height - 1; y += 2)
{
maze[x, y] = Wall; // 棒を立てる
// 倒せるまで繰り返す while (true)
{ // 1行目のみ上に倒せる int direction;
if (y == 2)
direction = rnd.Next(4);
else
direction = rnd.Next(3);
// 棒を倒す方向を決める int wallX = x;
int wallY = y;
switch (direction)
{
case 0: // 右 wallX++;
break;
case 1: // 下 wallY++;
break;
case 2: // 左 wallX--;
break;
case 3: // 上 wallY--;
break;
} // 壁じゃない場合のみ倒して終了 if (maze[wallX, wallY] != Wall)
{
maze[wallX, wallY] = Wall;
break;
}
}
}
}
return maze;
}
// デバッグ用メソッド public static void DebugPrint(int[,] maze)
{ Console.WriteLine($"Width: {maze.GetLength(0)}");
Console.WriteLine($"Height: {maze.GetLength(1)}"); for (int y = 0; y < maze.GetLength(1); y++)
{
for (int x = 0; x < maze.GetLength(0); x++)
{
Console.Write(maze[x, y] == Wall ? "■" : " ");
}
Console.WriteLine();
}
}
}
}
***** コンパイル開始 *****
Microsoft (R) Visual C# Compiler version 4.8.9032.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
定年退職後、再度プログラミングを学習し、BCCForm and BCCSkeltonを(Unicode版のECCSkelton含む)更新、そのアプリケーションとして際にロハでついてくるC#、VB用のコンパイラーを利用するためのMSCompAssを作った際についでにC#を学習して、そのアプリを追加し、自分で常用する実用ソフト(注)も初めて作りました。
//////////////////////////////
// 日付入力ダイアログサンプル
// SampleMCDll.cs
//////////////////////////////
using System;
using System.Drawing;
using System.Windows.Forms;
namespace SampleMCDll
{
public class AppForm : Form
{
private TextBox textBox;
private Button ShowBtn, CloseBtn;
[STAThread]
static void Main()
{
Application.Run(new AppForm());
}
public AppForm()
{
//ウィンドウサイズ、文字列の設定
this.Size = new Size(320, 120);
this.Text = "MonthCalendarを使った日付入力ダイアログサンプル";
textBox = new TextBox();
textBox.BorderStyle = BorderStyle.FixedSingle;
textBox.Location = new Point(10, 10);
textBox.Multiline = false;
textBox.Size = new Size(this.ClientSize.Width - 20, 20);
this.Controls.Add(textBox);
//Showボタン
ShowBtn = new Button();
ShowBtn.Location = new Point(ClientSize.Width - ShowBtn.Width - 10, ClientSize.Height - ShowBtn.Height - 10);
ShowBtn.Text = "Show";
ShowBtn.AutoSize = true;
ShowBtn.Click += ShowButton_Click; //クリック時ハンドラーを設定する
this.Controls.Add(ShowBtn);
//Closeボタン
CloseBtn = new Button();
CloseBtn.Location = new Point(10, ClientSize.Height - CloseBtn.Height - 10);
CloseBtn.Text = "Close";
CloseBtn.AutoSize = true;
CloseBtn.Click += CloseButton_Click; //クリック時ハンドラーを設定する
this.Controls.Add(CloseBtn);
}
//引数無しで呼ぶと当日の年を表示します。
/////////////////////
public class SelectDate : Form
{
//日付出力用DateTimeクラスDateプロパティ
private DateTime _date;
public DateTime Date
{
get
{
return _date;
}
}
//ダイアログコントロール
Button OkBtn, CancelBtn;
MonthCalendar monthCalendar;