/// <summary> /// x,yの位置にある肉球から繋がれている肉球の数を調べ上げる /// </summary> private void LookUpPawConnectable(int x, int y, ref int count) { // 連結数をカウントアップ count++; // 繋がりをみる肉球をいれておく変数 Paw curr = this.paws[IndexBy(x, y)]; Paw next; // 評価中の肉球は評価済にしておく curr.IsEvaluated = true; // 上方向の繋がりをみる if (y < Define.Versus.PAW_ROW - 1) { next = this.paws[IndexBy(x, y + 1)]; if (!next.IsEvaluated && curr.CanConnect(next)) { LookUpPawConnectable(x, y + 1, ref count); } } // 下方向のつながりを見る if (0 < y) { next = this.paws[IndexBy(x, y - 1)]; if (!next.IsEvaluated && curr.CanConnect(next)) { LookUpPawConnectable(x, y - 1, ref count); } } // 左方向のつながりを見る if (0 < x) { next = this.paws[IndexBy(x - 1, y)]; if (!next.IsEvaluated && curr.CanConnect(next)) { LookUpPawConnectable(x - 1, y, ref count); } } // 右方向のつながりを見る if (x < Define.Versus.PAW_COL - 1) { next = this.paws[IndexBy(x + 1, y)]; if (!next.IsEvaluated && curr.CanConnect(next)) { LookUpPawConnectable(x + 1, y, ref count); } } }
/// <summary> /// 指定した肉球、及びその肉球に繋がっている肉球を消滅させる /// このメソッドはLookUpPadConnectionによって肉球のつながりを調べた後に使用すること /// </summary> private void Vanish(int x, int y) { // 肉球 Paw curr = this.paws[IndexBy(x, y)]; Paw next; // 評価フラグを落とし、消滅状態へ設定する curr.IsEvaluated = false; curr.ToVanish(); // 上方向を消していく if (y < Define.Versus.PAW_ROW - 1) { next = this.paws[IndexBy(x, y + 1)]; if (next.IsEvaluated && curr.CanConnect(next)) { Vanish(x, y + 1); } } // 下方向を消していく if (0 < y) { next = this.paws[IndexBy(x, y - 1)]; if (next.IsEvaluated && curr.CanConnect(next)) { Vanish(x, y - 1); } } // 左方向を消していく if (0 < x) { next = this.paws[IndexBy(x - 1, y)]; if (next.IsEvaluated && curr.CanConnect(next)) { Vanish(x - 1, y); } } // 右方向を消していく if (x < Define.Versus.PAW_COL - 1) { next = this.paws[IndexBy(x + 1, y)]; if (next.IsEvaluated && curr.CanConnect(next)) { Vanish(x + 1, y); } } }