注:当時、著者の小野さんは東大のUNIXマシーンでSmall-Cを使っていたようです。私は出たての8bitパソコン、Sharp MZ-2500でCP/M(Control Program for Microcomputers)を走らせ、整数しか使えないBDS-Cを使っていました。(MZ-2500には浮動小数点演算を行えるFNCコールがあったので痛痒を感じませんでしたが。)
//////////////////////
// EightPuzzle.cs
// Copyright (c) 2025
// By Y-Sama
//////////////////////
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging; //PixelFormatを使う為
using System.Reflection; //Assemblyを使う為
namespace EightPuzzle
{
public partial class EtPuzzle : Form
{ //メンバーグラフィックス
Bitmap BaseImg; //ピクチャーボックスサイズ化した基本画像
Bitmap Canvas; //Bitmapインスタンスによる仮想画面
Graphics cvsHandle; //Canvasのグラフィックハンドル
Image[] PieceImg = new Image[8]; //分割画像([0]-[7]) //メンバーコントロール
PictureBox picBox;
Button btnFile, btnStart, btnUp, btnDown, btnLeft, btnRight, btnExit; //メンバーフィールド
int picOrgWidth; //ピクチャーボックス幅の初期値
int picOrgHeight; //ピクチャーボックス高さの初期値
Single PieceW; //分割画像幅
Single PieceH; //分割画像高さ
int[] Pieces = new int[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; //8パズルのピース配列(8はブランク) const string Filter = "イメージファイル|*.bmp;*.jpeg;*.jpg;*.gif;*.tiff;*.png;*.wmf;*.emf;*.ico";
[STAThread]
public static void Main()
{
Application.Run(new EtPuzzle());
}
//分割画像サイズ設定
PieceW = (Single)picBox.Width / 3;
PieceH = (Single)picBox.Height / 3; //BasdeImgで分割画像を作成
RectangleF Rect;
Rect = new RectangleF(0, 0, PieceW, PieceH);
PixelFormat Format = BaseImg.PixelFormat;
for(int i = 0; i < 8; i++)
{
Single x = PieceW * (i % 3);
Single y = PieceH * (i / 3);
Rect = new RectangleF(x, y, PieceW, PieceH);
PieceImg[i] = BaseImg.Clone(Rect, Format);
}
return true;
}