void InitLevel() { level = new List <List <DominoBlock> >(); for (int rowIdx = 0; rowIdx < rows; rowIdx++) { List <DominoBlock> levelLane = new List <DominoBlock>(); for (int laneIdx = 0; laneIdx < lanes; laneIdx++) { GameObject blockGO = Instantiate(dominoPrefab) as GameObject; DominoBlock block = blockGO.GetComponent <DominoBlock>(); block.laneIdx = laneIdx; blockGO.transform.parent = transform; levelLane.Add(block); block.gameObject.transform.localPosition = new Vector3((laneIdx - lanes / 2) * laneDistance, 0, rowIdx * rowsDistance); } level.Add(levelLane); } for (int rowIdx = 0; rowIdx < rows; rowIdx++) { for (int laneIdx = 0; laneIdx < lanes; laneIdx++) { DominoBlock block = level[rowIdx][laneIdx]; if (rowIdx < rows - 1) { DominoBlock forward = level[rowIdx + 1][laneIdx]; DominoBlock forwardLeft = null; DominoBlock forwardRight = null; if (laneIdx > 0) { forwardLeft = level[rowIdx + 1][laneIdx - 1]; } if (laneIdx < lanes - 1) { forwardRight = level[rowIdx + 1][laneIdx + 1]; } block.forward = forward; block.forwardLeft = forwardLeft; block.forwardRight = forwardRight; block.willKnock1 = forward; } } } }
void Start() { currentTumbeling = new List <DominoBlock>(); InitLevel(); for (int laneIdx = 0; laneIdx < lanes; laneIdx++) { currentTumbeling.Add(null); DominoBlock block = level[0][laneIdx]; block.Tumble(); } StartCoroutine(Game()); }
public void DisplayDominoBlocks(Transform holder, List <DominoBlockData> originList) { int currentHand = originList.Count; for (int i = currentHand; i < holder.childCount; i++) { holder.GetChild(i).gameObject.SetActive(false); } if (currentHand > 0) { for (int i = 0; i < currentHand; i++) { DominoBlock block = holder.GetChild(i).gameObject.GetComponent <DominoBlock>(); block.blockName = originList[i].name; block.upValue = originList[i].upValue; block.downValue = originList[i].downValue; block.totalValue = originList[i].totalValue; block.sprite = originList[i].sprite; block.indexPosition = i; Image image = block.gameObject.GetComponent <Image>(); image.sprite = block.sprite; block.gameObject.SetActive(true); } } else if (currentPlayerHand == 0) { for (int i = 0; i < 7; i++) { Transform currentBlockToUpdate = playerHolder.transform.GetChild(i); currentBlockToUpdate.gameObject.SetActive(false); } } }
IEnumerator Game() { yield return(new WaitForSeconds(3)); while (true) { int rand = Random.Range(-3, lanes + 3); if (rand < 0 || rand >= lanes) { rand = -1; } float lastRowZ = level[rows - 1][0].transform.localPosition.z; List <DominoBlock> levelLane = new List <DominoBlock>(); for (int laneIdx = 0; laneIdx < lanes; laneIdx++) { GameObject blockGO = Instantiate(dominoPrefab) as GameObject; DominoBlock block = blockGO.GetComponent <DominoBlock>(); block.laneIdx = laneIdx; blockGO.transform.parent = transform; level[rows - 1][laneIdx].willKnock1 = block; level[rows - 1][laneIdx].forward = block; if (laneIdx > 0) { level[rows - 1][laneIdx - 1].forwardRight = block; } if (laneIdx < lanes - 1) { level[rows - 1][laneIdx + 1].forwardLeft = block; } if (rand != -1) { if (laneIdx == rand) { block.canTumble = false; block.child.GetComponent <Renderer>().material.SetColor("_Color", Color.black); } } levelLane.Add(block); block.gameObject.transform.localPosition = new Vector3((laneIdx - lanes / 2) * laneDistance, 0, lastRowZ + 4); } level.Add(levelLane); yield return(new WaitForSeconds(1f)); for (int laneIdx = 0; laneIdx < lanes; laneIdx++) { DominoBlock block = level[0][laneIdx]; Destroy(block.gameObject); } level.RemoveAt(0); } }