/**打乱*/ public void Upset() { //获取星星颜色,位置id,准备打乱 List <int> cors = new List <int>(); List <int> posIds = new List <int>(); Star star; int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < _stars[i].Count; j++) { star = _stars[i][j].GetComponent <Star>(); cors.Add(star.color); posIds.Add(star.posId); star.Dispose(); } _stars[i].Clear(); for (j = 0; j < 10; j++) { _stars[i].Add(null); } } int[] corArr = cors.ToArray(); int[] posIdArr = posIds.ToArray(); RandomArr.Randomize(corArr, corArr.Length); //重建 StarsBoard[] starsBoards = new StarsBoard[] { new StarsBoard(), new StarsBoard(), new StarsBoard(), new StarsBoard(), new StarsBoard() }; for (i = 0; i < 5; i++) { starsBoards[i].SetAll(false); } int cor; int posId; for (i = 0; i < corArr.Length; i++) { cor = corArr[i]; posId = posIdArr[i]; starsBoards[cor].SetTrue(posId); PushStar(cor, posId); } _starsPosition = new StarsPosition(starsBoards); //移除空的元素 i = _stars.Length; while (--i >= 0) { j = _stars[i].Count; while (--j >= 0) { if (!_stars[i][j]) { _stars[i].RemoveAt(j); } } } }
/**播放完文字动画后执行*/ public void NewLevelB() { _starsShow = new StarsShow(); _starsShow.Init(this, new Vector2(-2.4f, -3.6f)); RandomArr.Instance(); int[] cnts = RandomArr.RandElement(100, 5, 12, 28);//得到长度为5的数组,各个元素的和为100,元素最小12最大28如:[16, 14, 26, 24, 20 ] /* for(int i=0; i<5; i++){ * Debug.Log(cnts[i]); * }*/ _starsShow.NewStarsPosition(cnts); // SoundMan.instance.PlayOneShot("星星出现动画"); }
public void NewStarsPosition(int[] cnts) { //清理 _selectTotal = 0; int i; int j; for (i = 0; i < 10; i++) { for (j = 0; j < _stars[i].Count; j++) { _stars[i][j].GetComponent <Star>().Dispose(); } _stars[i].Clear(); for (j = 0; j < 10; j++) { _stars[i].Add(null); } } //新建 int id; StarsBoard[] starsBoards = new StarsBoard[] { new StarsBoard(), new StarsBoard(), new StarsBoard(), new StarsBoard(), new StarsBoard() }; for (i = 0; i < 5; i++) { starsBoards[i].SetAll(false); for (j = 0; j < cnts[i]; j++) { id = RandomArr.GetNextRandomElement(); starsBoards[i].SetTrue(id); PushStar(i, id, true); } //Debug.Log( starsBoards[i].toString()); } _starsPosition = new StarsPosition(starsBoards); }