Skip to content

Instantly share code, notes, and snippets.

@cacapon
Created July 14, 2021 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cacapon/82a0cadd53321ac47fcaf426420a61e9 to your computer and use it in GitHub Desktop.
Save cacapon/82a0cadd53321ac47fcaf426420a61e9 to your computer and use it in GitHub Desktop.
デリゲートのテスト
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Puzzle
{
//MEMO:ePieceColorについては別途定義しています。
public static int STAGESIZE = 7; //7x7の領域を想定しているので、一つしか用意してません。
public (Guid,ePieceColor)[,] HoldErea; // 持って動かす部分の領域
public (Guid,ePieceColor)[,] StageErea; // パズルのピースを置いていく領域
public Puzzle()
{
HoldErea = new (Guid, ePieceColor)[STAGESIZE, STAGESIZE];
StageErea = new (Guid, ePieceColor)[STAGESIZE, STAGESIZE];
InitErea(HoldErea);
InitErea(StageErea);
}
/// <summary>
/// 指定のエリアを(ID無し,色なし)で初期化します。
/// </summary>
/// <param name="erea"></param>
private void InitErea((Guid, ePieceColor)[,] erea)
{
Search(STAGESIZE,STAGESIZE,(height,width)=>{
erea[height, width] = (Guid.Empty, ePieceColor.NONE);
});
}
/// <summary>
/// 二次元配列の各要素について特定の処理を行います。
/// </summary>
/// <param name="height"></param>
/// <param name="width"></param>
/// <param name="action"></param>
private void Search(int height,int width, Action<int,int> action)
{
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
action(h,w);
}
}
}
/// <summary>
/// HoldEreaの(0,0)の地点からピースをセットします。
/// </summary>
/// <param name="piece"></param>
public void SetHoldErea((Guid,ePieceColor)[,] piece)
{
Search(piece.GetLength(0),piece.GetLength(1),(height,width)=>{
HoldErea[height, width] = piece[height,width];
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment