public void OnMouseUp() { manager.ReleaseModel(); if (manager.isSkill == false && canSkill) { if (Time.time - firstClickTime <= 0.5f) { //skill1 if (Type == GameManager.ModelType.CrossClear) { //Debug.Log("skill1"); manager.ClearCross(x, y); Instantiate(effect_Row, manager.CalGridPos(x, y), Quaternion.Euler(new Vector3(0, 0, 90))); Instantiate(effect_Col, manager.CalGridPos(x, y), Quaternion.identity); } //skill2 else { ModelColor.ColorType clearType = (ModelColor.ColorType)Random.Range(0, 5); manager.ClearByType(clearType); rainbowSpawn.transform.GetChild((int)clearType).gameObject.SetActive(true); this.modelClearComponent.Clear(); if (manager.models[x, y] != null && manager.models[x, y].CanClear()) { manager.models[x, y].ModelClearComponent.Clear(); manager.models[x, y] = manager.CreatNewModel(x, y, GameManager.ModelType.Empty); } } } canSkill = false; } }
//同类型消除 public void ClearByType(ModelColor.ColorType color) { if (gameBegin) { PlayerPrefs.SetInt("RainbowNums", PlayerPrefs.GetInt("RainbowNums", 0) + 1);//记录彩虹个数 awardNums++; PlayerPrefs.SetInt("LuckDog", awardNums); int count = 0; for (int x = 0; x < xCol; x++) { for (int y = 0; y < yRow; y++) { if (models[x, y].CanColor() && models[x, y].ModelColorComponent.Color == color) { count++; ClearModel(x, y); } } } score += 5 * count; score += 20; StartCoroutine(FillAll(fillTime)); } }
//匹配model public List <ModelBase> MatchModels(ModelBase model, int newX, int newY) { if (model.CanColor()) { ModelColor.ColorType color = model.ModelColorComponent.Color; List <ModelBase> matchRow = new List <ModelBase>(); //存取行 List <ModelBase> matchCol = new List <ModelBase>(); //存取列 List <ModelBase> match = new List <ModelBase>(); //存取全部可消除的列表 //行匹配 matchRow.Add(model); //i=0代表往左,i=1代表往右 for (int i = 0; i <= 1; i++) { for (int xDistance = 1; xDistance < xCol; xDistance++) { int x; if (i == 0) { x = newX - xDistance; } else { x = newX + xDistance; } if (x < 0 || x >= xCol) { break; } if (models[x, newY].CanColor() && models[x, newY].ModelColorComponent.Color == color) { matchRow.Add(models[x, newY]); } else { break; } } } if (matchRow.Count >= 3) { foreach (var r in matchRow) { match.Add(r); } } //L T型匹配 //检查一下当前行遍历列表中的元素数量是否大于3 if (matchRow.Count >= 3) { for (int i = 0; i < matchRow.Count; i++) { //行匹配列表中满足匹配条件的每个元素上下依次进行列遍历 // 0代表上方 1代表下方 for (int j = 0; j <= 1; j++) { for (int yDistance = 1; yDistance < yRow; yDistance++) { int y; if (j == 0) { y = newY - yDistance; } else { y = newY + yDistance; } if (y < 0 || y >= yRow) { break; } if (models[matchRow[i].X, y].CanColor() && models[matchRow[i].X, y].ModelColorComponent.Color == color) { matchCol.Add(models[matchRow[i].X, y]); } else { break; } } } if (matchCol.Count < 2) { matchCol.Clear(); } else { for (int j = 0; j < matchCol.Count; j++) { match.Add(matchCol[j]); } break; } } } if (match.Count >= 3) { return(match); } matchRow.Clear(); matchCol.Clear(); matchCol.Add(model); //列匹配 //i=0代表往左,i=1代表往右 for (int i = 0; i <= 1; i++) { for (int yDistance = 1; yDistance < yRow; yDistance++) { int y; if (i == 0) { y = newY - yDistance; } else { y = newY + yDistance; } if (y < 0 || y >= yRow) { break; } if (models[newX, y].CanColor() && models[newX, y].ModelColorComponent.Color == color) { matchCol.Add(models[newX, y]); } else { break; } } } if (matchCol.Count >= 3) { for (int i = 0; i < matchCol.Count; i++) { match.Add(matchCol[i]); match.Add(matchCol[i]); } } //L T型匹配 //检查一下当前行遍历列表中的元素数量是否大于3 if (matchCol.Count >= 3) { for (int i = 0; i < matchCol.Count; i++) { //行匹配列表中满足匹配条件的每个元素上下依次进行列遍历 // 0代表上方 1代表下方 for (int j = 0; j <= 1; j++) { for (int xDistance = 1; xDistance < xCol; xDistance++) { int x; if (j == 0) { x = newX - xDistance; } else { x = newX + xDistance; } if (x < 0 || x >= xCol) { break; } if (models[x, matchCol[i].Y].CanColor() && models[x, matchCol[i].Y].ModelColorComponent.Color == color) { matchRow.Add(models[x, matchCol[i].Y]); } else { break; } } } if (matchRow.Count < 2) { matchRow.Clear(); } else { for (int j = 0; j < matchRow.Count; j++) { match.Add(matchRow[j]); } break; } } } if (match.Count >= 3) { return(match); } } return(null); }