public Puyo Generate(PuyoFieldStatus puyoType, Vector2Int position) { var obj = Instantiate(puyoPrefab); var puyo = obj.GetComponent <Puyo>(); puyo.puyoType = puyoType; puyo.MoveTo(position); return(puyo); }
/// <summary> /// ある位置のぷよの連結しているぷよの数を数える /// </summary> /// <param name="x">初めのぷよのx座標</param> /// <param name="y">初めのぷよのy座標</param> /// <param name="status">連結もとのぷよの状態</param> /// <param name="searched">探索済みかどうかの2次元配列</param> /// <param name="positionList">連結しているぷよの座標を格納するリスト</param> /// <returns></returns> int CountNumConnectedPuyo(int x, int y, PuyoFieldStatus status, bool[,] searched, List <Vector2Int> positionList) { if (searched[y, x]) { return(0); } var stat = this.fieldStatus[y, x]; if (stat == PuyoFieldStatus.None || stat == PuyoFieldStatus.OutOfField) { searched[y, x] = true; return(0); } if (stat == PuyoFieldStatus.RedPuyo || stat == PuyoFieldStatus.BluePuyo || stat == PuyoFieldStatus.GreenPuyo || stat == PuyoFieldStatus.YellowPuyo) { if (stat != status) { return(0); } searched[y, x] = true; positionList.Add(new Vector2Int(x, y)); //上下左右のマスで再帰 var right = CountNumConnectedPuyo(x + 1, y, status, searched, positionList); var up = CountNumConnectedPuyo(x, y + 1, status, searched, positionList); var left = CountNumConnectedPuyo(x - 1, y, status, searched, positionList); var down = CountNumConnectedPuyo(x, y - 1, status, searched, positionList); return(right + up + left + 1); } throw new Exception(""); }