前回までの状況はこちら。
 
最新ソースはこちら。
https://github.com/takishita2nd/Picross 
今回は、前回のソースコードを元に、クラス構成を変えて作り直していきます。
まずはリソースを管理するクラス。
class Resource
{
    private static asd.Texture2D _picrossTexture = null;
    public static asd.Texture2D GetPicrossTexture()
    {
        if (_picrossTexture == null)
        {
            _picrossTexture = asd.Engine.Graphics.CreateTexture2D("square.png");
        }
        return _picrossTexture;
    }
} 
数独の時と同じです。
画像などの外部リソースは、読み込んだ一個のオブジェクトをみんなで使い回すような仕組みにしています。
こうすることで、外部リソース読み込み速度が向上し、使用メモリも少なくなります。
シングルトンに近いイメージですね。
絵を構成するオブジェクトのベース部分を作成します。
class ObjectBase
{
    protected int _x;
    protected int _y;
    protected asd.TextureObject2D _backTexture;
    protected asd.TextObject2D _valueText;
    protected int width;
    protected int height;
    public asd.TextureObject2D getBackTexture()
    {
        return _backTexture;
    }
    public asd.TextObject2D getTextObject()
    {
        return _valueText;
    }
    public bool isClick(asd.Vector2DF pos)
    {
        if (pos.X > _x && pos.X < _x + width
            && pos.Y > _y && pos.Y < _y + height)
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
これは、数独のObjectBaseクラスと全く同じです。
これをベースにして、絵を書く部分と、数字を入力する部分とで、クラスを派生させて行きます。
絵を書く部分は以下の様に派生させました。
class DrawSquare : ObjectBase
{
    protected int _row;
    protected int _col;
    protected const int setPositionX = 200;
    protected const int setPositionY = 200;
    public DrawSquare(int row, int col)
    {
        width = 32;
        height = 32;
        _row = row;
        _col = col;
        _x = col * width + setPositionX;
        _y = row * height + setPositionY;
        _backTexture = new asd.TextureObject2D();
        _backTexture.Texture = Resource.GetPicrossTexture();
        _backTexture.Position = new asd.Vector2DF(_x, _y);
    }
} 
これを使用して実装します。
class PicrossUI
{
    private List<List<DrawSquare>> drawSquares = new List<List<DrawSquare>>();
    public PicrossUI()
    {
    }
    public void Run()
    {
        asd.Engine.Initialize("ピクロス解析ツール", 1000, 800, new asd.EngineOption());
        // 下地
        var background = new asd.GeometryObject2D();
        asd.Engine.AddObject2D(background);
        var bgRect = new asd.RectangleShape();
        bgRect.DrawingArea = new asd.RectF(0, 0, 1000, 800);
        background.Shape = bgRect;
        for(int row = 0; row <10; row++)
        {
            List<DrawSquare> rowList = new List<DrawSquare>();
            for(int col = 0; col <10; col++)
            {
                var square = new DrawSquare(row, col);
                asd.Engine.AddObject2D(square.getBackTexture());
                rowList.Add(square);
            }
            drawSquares.Add(rowList);
        }
        while (asd.Engine.DoEvents())
        {
            asd.Engine.Update();
        }
        asd.Engine.Terminate();
    }
} 
今回色を書く部分のマスの数は可変になるので、二次元配列ではなく、Listを使います。
実行結果はこんな感じになりました。
 
当然、見た目は何も弄っていないので、前回と同じですね。
次回はサイズを変更するダイアログを作成していきます。