///////////////////////////////
// Boids.cs
// Copyright (c) 2026 by ysama
///////////////////////////////
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection; //Assembly使用の為
using System.Resources; //リソース使用の為
using Boids_for_CS; //Boids_for_CS.dll使用の為(解説:これが主役です。)
namespace Boids_EXE
{ //名前空間共用静的クラス(解説:今回初めて名前空間で共有される文字列の為に作ってみました。)
static class Title
{
public const string Ver = "Boids for C# Ver 2.0"; //解説:器プログラム用の名称とVersion情報です。
}
//////////////////////
//Boids設定ダイアログ
////////////////////// class SetUpDlg : Form
{ //ダイアログのフィールド
public int NoOfBoids;
public bool Introvert;
public bool Sociopath; //ダイアログのコントロール
Button BtnOK;
ComboBox DDList; //DropDownStyleプロパティをDropDownList
CheckBox IvCheck; //Introvert付加指定
CheckBox SpCheck; //Sociopath付加指定
完全に(Cells for C#とかいいましたか?どっかでみたことがある)「のっぺらぼう」です。ツールバーボタンは左から、メニューの「Boidsの設定」、「Boidsの終了」、「ゲーム開始」、「ゲーム中止」、「飛行跡」、「バージョン」となっており、ステータスバーにはプログラム、バージョン名(注)と「Boidsの情報(設定後、開始すると開始時のPoidsの総数とその内訳が表示されます。)」が表示されます。
//グローバル定数 public enumBoidType //Boidの種を行動特性別に以下4種とする {
Flocker, //0 - "Birds of a feather flock together" Introvert, //1 - Harmless "Lone wolf" but tends to get away from a flock Sociopath, //2 - Dangerous, often times kills others Dead //3 - a dead body //https://gigazine.net/news/20240921-difference-between-psychopath-sociopath/ }
"Cells for C#"の時と同じように、"Boids.bat"を起動すれば自動的にコンパイルされ、Boids_for_CS.dllとBoids.exeが出来上がる仕組みになっています。(プログラムアイコンやリソースファイルも入っているので、Windows 11であればこれだけで大丈夫です。)因みに↑はこのバッチファイルでのコンパイルテストの生成ファイルで撮っています。
//////////////////////////////////////////////////
// Boids algorithm demonstration (in JavaScript)
// Original program Copyright by Ben Eater
// 日本語コメント文責:Y-sama
// https://eater.net/boids
//////////////////////////////////////////////////
//描画領域の幅、高さ(ブラウザーの大きさに合わせて更新される)
let width = 150; //HTMLファイルの描画領域canvas定義の初期値
let height = 150; //HTMLファイルの描画領域canvas定義の初期値
"There are lots of features you could try adding to the code yourself: - Add a predator(捕食者の追加) that the boids try to avoid that scatters the flock if it gets too close. - Add a strong wind(強風など外部環境の追加)or current to see what effect it has on the flock. - Add "perching" behavior(地上行動の追加). If a boid gets close to the bottom of the screen, have it land and hang out on the ground for a bit before taking off again and rejoining the flock. - Make it 3D! (三次元映像化)The boids' velocity is currently represented as a 2D vector. You could change them to 3D vectors and update the vector math to work. To draw in 3D, you could just change the size of the boids to represent how far away they are."