public void Init(int x, int y, PieceColor color, bool isCrackPiece, BoardInstance board) { IsPieceUp = false; this.x = x; this.y = y; this.color = color; this.board = board; //TODO: Set Crack Piece Material if (GameManager.Instance.gamePlayMode.doUseCrack) { if (isCrackPiece) { GetComponent <Renderer>().material = crackMaterial; Debug.Log("isCrackPiece!!!! x: " + x + " y: " + y); } else { Debug.Log("NotCrackPiece!!!!"); } } material = GetComponent <Renderer>().material; material.SetFloat("_Rate", 1f); //var sprite = GetComponent<SpriteRenderer>(); //if (sprite != null) //{ // Debug.Log("normalSprite x: " + x + " y: " + y); // sprite.sprite = normalSprite; //} }
private IEnumerator InitCoroutine() { int timesToYield = 10000; int cnt = 0; while (true) { if (cnt-- <= 0) { cnt = timesToYield; yield return(0); } InitColorPool(boardLength); pieces = new Piece[boardLength, boardLength]; for (int i = 0; i < boardLength; i++) { for (int j = 0; j < boardLength; j++) { bool up = !(i == 0); bool down = !(i == boardLength - 1); bool left = !(j == 0); bool right = !(j == boardLength - 1); int randomIdx = Random.Range(0, colorPool.Count - 1); pieces[i, j] = new Piece(colorPool[randomIdx], left, right, up, down, i, j); colorPool.RemoveAt(randomIdx); } } if (IsValidBoard()) { break; } } nextPieces.Add(pieces[0, 0]); nextPieces.Add(pieces[0, boardLength - 1]); nextPieces.Add(pieces[boardLength - 1, 0]); nextPieces.Add(pieces[boardLength - 1, boardLength - 1]); if (gpm.doUseCrack) { InitCrackPieces(); } boardInstance = GameManager.Instance.boardInstance; isReady = true; }
private void InitNewbie() { InitNewbieColorPool(); pieces = new Piece[boardLength, boardLength]; for (int i = 0; i < boardLength; i++) { for (int j = 0; j < boardLength; j++) { bool up = !(i == 0); bool down = !(i == boardLength - 1); bool left = !(j == 0); bool right = !(j == boardLength - 1); pieces[i, j] = new Piece(colorPool[i * boardLength + j], left, right, up, down, i, j); } } nextPieces.Add(pieces[0, 0]); nextPieces.Add(pieces[0, boardLength - 1]); nextPieces.Add(pieces[boardLength - 1, 0]); nextPieces.Add(pieces[boardLength - 1, boardLength - 1]); boardInstance = GameManager.Instance.boardInstance; isReady = true; }
IEnumerator InitCoroutine() { InitPlayMode(); //gamePlayMode.gameMode = GameMode.VSAI; UIInstance = Instantiate(uiPrefab); UIInstance.Init(gamePlayMode.boardSideLength, prefabConfig); boardInstance = Instantiate(boardInstancePrefab); boardManager = GetComponent <BoardManager>(); boardManager.Init(gamePlayMode); while (!boardManager.IsReady()) { yield return(0); } switch (gamePlayMode.gameMode) { case GameMode.OneClientTwoPlayers: controller = Instantiate(controllerPrefab); controller.name = "Player 1"; controller2 = Instantiate(controllerPrefab); controller2.name = "Player 2"; controller.Init(gamePlayMode.boardSideLength, UIInstance.panels); controller2.Init(gamePlayMode.boardSideLength, UIInstance.panels); break; case GameMode.VSAI: controller = Instantiate(controllerPrefab); controller.name = "Player 1"; controller2 = Instantiate(controllerPrefab); controller2.name = "AI"; controller.Init(gamePlayMode.boardSideLength, UIInstance.panels); controller2.Init(gamePlayMode.boardSideLength, UIInstance.panels); break; case GameMode.Teaching: controller = Instantiate(controllerPrefab); controller.name = "Player 1"; controller2 = Instantiate(controllerPrefab); controller2.name = "AI"; controller.Init(gamePlayMode.boardSideLength, UIInstance.panels); controller2.Init(gamePlayMode.boardSideLength, UIInstance.panels); break; default: break; } boardInstance.Init(prefabConfig); GameStart(); if (gamePlayMode.gameMode == GameMode.OneClientTwoPlayers) { currentController = controller; controller.gameObject.SetActive(true); controller2.gameObject.SetActive(false); } else if (gamePlayMode.gameMode == GameMode.VSAI) { currentController = controller; controller.gameObject.SetActive(true); controller2.gameObject.SetActive(false); aiController = gameObject.AddComponent <AIController>(); } UnityAction BoardDisappear = new UnityAction(boardInstance.BoardDisappear); UnityAction UIDisappear = new UnityAction(UIInstance.ActionsOnGameEnd); UIAndBoardLogic_WhenGameEnd.AddListener(BoardDisappear); UIAndBoardLogic_WhenGameEnd.AddListener(UIDisappear); }