public void updateMahjong(Mahjong from, int toValue) { ResetStatus(); int fromValue = from.GetMahjongValue(); Debug.Log("[updateMahjong] " + fromValue + " > " + toValue); valueList.Remove(fromValue); valueList.Add(toValue); string before = ""; valueList.ForEach((v) => { before += v + ","; }); Debug.Log("BeforeSort " + before); valueList.Sort(); string after = ""; valueList.ForEach((v) => { after += v + ","; }); Debug.Log("AfterSort " + after); from.SetStatus(Mahjong.Status.Holding); from.SetMahjongValue(toValue); from.transform.SetSiblingIndex(valueList.IndexOf(toValue)); if (checkGang() == true) { return; } else if (checkHupai()) { handleHupai(); } }
public void AddMahjong(Mahjong mjToAdd) { ResetStatus(); valueList.Add(mjToAdd.GetMahjongValue()); mjToAdd.SetStatus(Mahjong.Status.Holding); mjToAdd.name = mjToAdd.GetMahjongValue().ToString(); mjToAdd.isMine = true; mjToAdd.transform.SetParent(this.gameObject.transform, false); valueList.Sort(); mjToAdd.transform.SetSiblingIndex(valueList.IndexOf(mjToAdd.GetMahjongValue())); }
private void AddCurrentMahjongToMine() { if (!mahjongCurrent) { mahjongCurrent = GameObject.Find("CurrentMahjong"); } Mahjong currentMahjong = mahjongCurrent.GetComponent <Mahjong>(); CreateMahjongByValue((currentMahjong.GetMahjongValue())); currentMahjong.SetStatus(Mahjong.Status.Gone); }
/* * 当用户按下杠时执行动作,由GangScript使用SendMessage("OnGangClicked")调用 */ public void OnGangClicked() { Debug.Log("[OnGangClicked]"); List <int> startIndex = new List <int>(); int i = 0; while (i < valueList.Count) { int currentValue = valueList[i]; int currentCount = 0; Debug.Log("Now checking at " + i + " Value=" + currentValue); for (int j = i; j < valueList.Count; j++) { if (currentValue == valueList[j]) { currentCount++; } else { break; } } if (currentCount >= 4) { startIndex.Add(i); Debug.Log("Has found gang at " + i); } i += currentCount; } if (startIndex.Count == 0) { Debug.LogWarning("Wrong Message! Nothing to Gang!"); } else if (startIndex.Count == 1) { handleGang(startIndex[0]); } else if (startIndex.Count > 1) { Debug.Log("Pending to choose which to Gang. count=" + startIndex.Count); Mahjong mj = null; startIndex.ForEach((start) => { Debug.Log("Pending to choose which to Gang." + start); for (int k = start; k < start + 4; k++) { mj = transform.GetChild(k).gameObject.GetComponent <Mahjong>(); mj.SetStatus(Mahjong.Status.HoldingToGang); } }); } }
public void ResetStatus() { Debug.Log("[ResetStatus]"); Mahjong mj = null; for (int i = 0; i < transform.childCount; i++) { mj = transform.GetChild(i).gameObject.GetComponent <Mahjong>(); if (mj.GetStatus() == Mahjong.Status.HoldingToThrow || mj.GetStatus() == Mahjong.Status.HoldingToGang) { mj.SetStatus(Mahjong.Status.Holding); } } }
internal bool ReceiveMahjong(int value) { Debug.Log("[ReceiveMahjong]"); if (!currentMahjong) { currentMahjong = GameObject.Find("CurrentMahjong"); } if (currentMahjong != null) { Mahjong new_mahjong = currentMahjong.GetComponent <Mahjong>(); new_mahjong.SetMahjongValue(value); new_mahjong.SetStatus(Mahjong.Status.Holding); } return(true); }
// Update is called once per frame public bool CreateMahjongByValue(int value) { if (transform.childCount >= MaxCount) { Debug.LogWarning("[AddMahjong] Can not add any more Mahjong. We already have " + transform.childCount); return(false); } GameObject newCell = Instantiate <GameObject>(mahjongPrefab) as GameObject; Mahjong mjToAdd = newCell.GetComponent <Mahjong>() as Mahjong; mjToAdd.SetMahjongValue(value); AddMahjong(mjToAdd); if (checkGang() == true) { return(true); } return(true); }
public void handleGang(int startIndex) { Debug.Log("[handleGang] startIndex:" + startIndex); Mahjong[] mj = new Mahjong[4]; for (int i = 0; i < 4; i++) { gangList.Add(valueList[startIndex + i]); mj[i] = transform.GetChild(i + startIndex).gameObject.GetComponent <Mahjong>(); } Array.ForEach(mj, (m) => { m.SetStatus(Mahjong.Status.IsForGang); m.transform.localScale = new Vector3(0.75f, 0.75f, 1f); m.transform.SetParent(gangArea); }); MaxCount -= 3; valueList.RemoveRange(startIndex, 4); AddCurrentMahjongToMine(); ResetStatus(); }
private void InitAllTiles(int row, int col) { Debug.Log("[InitAllTiles] row:" + row + " col:" + col); List <Transform> allTiles = new List <Transform>(); List <int> indexList = MJHelper.GenerateForFirstChoose(row * col); GridLayoutGroup gridLayoutGroup = GetComponent <GridLayoutGroup>(); gridLayoutGroup.constraint = GridLayoutGroup.Constraint.Flexible; // gridLayoutGroup.constraintCount = row; for (int i = 0; i < indexList.Count; i++) { GameObject newCell = Instantiate <GameObject>(mahjongPrefab) as GameObject; Mahjong mahjong = newCell.GetComponent <Mahjong>() as Mahjong; mahjong.SetMahjongValue(indexList[i]); mahjong.SetStatus(Mahjong.Status.Selecting); // mahjong.SetStatus(Mahjong.Status.Closed); newCell.transform.SetParent(this.gameObject.transform, false); } }
public void OnPointUp() { MyTilesScript myMahjongs = GameObject.Find("MyTiles").GetComponent <MyTilesScript>() as MyTilesScript; switch (currentStatus) { case Status.Selecting: case Status.Closed: myMahjongs.ResetStatus(); if (myMahjongs.CreateMahjongByValue(mahjongValue)) { SetStatus(Status.Gone); return; //如果被手里的牌接收了,则处理结束 } NewFetchScript currentMahjong = GameObject.Find("NewFetched").GetComponent <NewFetchScript>() as NewFetchScript; if (currentMahjong.ReceiveMahjong(this.GetMahjongValue())) { // GameObject.Destroy(this); // 已经被传给当前牌了,因为当前牌是复用,所以可以直接销毁被摸的牌 // transform.SetParent(null); SetStatus(Status.Gone); return; // 摸牌的情况 } break; case Status.Holding: SetStatus(Status.HoldingToThrow); break; case Status.HoldingToThrow: // 如果不是手里的牌,直接销毁 if (!this.isMine) { SetStatus(Status.Gone); } else { // 如果是手里的牌,则需要把新抓的牌替代进去 GameObject currentMahjong2 = GameObject.Find("CurrentMahjong"); if (currentMahjong2 != null) { Mahjong to = currentMahjong2.GetComponent <Mahjong>() as Mahjong; if (to.GetStatus() != Status.Gone) { myMahjongs.updateMahjong(this, to.GetMahjongValue()); to.SetStatus(Status.Gone); } } else { // (未知错误的时候,通常不会发生)如果是手里的牌,但又没有摸牌,则恢复。 SetStatus(Status.Holding); } } break; case Status.HoldingToGang: myMahjongs.OnMahjongSelectedToGang(mahjongValue); break; } }