// 在当前世界OuterCoord坐标所代表的位置创建一个棋盘 public GameObject CreateChessboard(Vector2Int OuterCoord) { // 使用棋盘预制体创建棋盘父物体 GameObject CurrentChessBoard = GameObject.Instantiate(ChessBoardPrefab, new Vector3(OuterCoord.x, 0.0f, OuterCoord.y), Quaternion.identity); //GameObject ChessBoard = new GameObject(); CurrentChessBoard.name = "ChessBoard(" + OuterCoord.x + ", " + OuterCoord.y + ")"; //CurrentChessBoard.transform.position = new Vector3(OuterCoord.x, 0.0f, OuterCoord.y); // 初始化棋盘信息控制器中的常量 ChessBoardController CurrentChessBoardController = CurrentChessBoard.GetComponent <ChessBoardController>(); CurrentChessBoardController.Initialize(this, OuterCoord); //CurrentChessBoardInfoController.MaxPiecePerChecker = MaxPiecePerChecker; //CurrentChessBoardInfoController.CheckerBoardSize = CheckerBoardSize; //CurrentChessBoardInfoController.ChessBoardSize = ChessBoardSize; //CurrentChessBoardInfoController.ChessBoardOuterCoordinate = OuterCoord; //CurrentChessBoardInfoController.MainWorldManager = this; // 向世界状态控制器注册创建的新棋盘 ChessBoardInit(CurrentChessBoard); // 初始化创建棋盘的信息控制器 //CurrentChessBoardInfoController.Initialize(); // 调用创建棋盘的操作控制器生成棋盘的棋盘格 CurrentChessBoardController.CreateCheckerBoard(); return(CurrentChessBoard); }
// 在棋盘状态更新完毕后用于更新棋盘格上显示的棋子(对于玩家PlayID) public void RefreshPieceOnCheckerBoard(Vector2Int InterCoord, Vector2Int OuterCoord, int PlayerID) { // 在坐标为OuterCoord的棋盘上坐标为InterCoord的棋盘格上 // 将0层的棋子设为显示,其余层的棋子设为不显示 GameObject LocateChessBoard = this.GetComponent <ChessBoardController>().MainWorldManager.GetChessBoard(OuterCoord); ChessBoardController LocateChessBoardController = LocateChessBoard.GetComponent <ChessBoardController>(); for (int i = 0; i < LocateChessBoardController.GetCheckerBoardPlayerAlivePieceNum(InterCoord, PlayerID); i++) { //Debug.Log("((((" + LocateChessBoardStateController.GetCheckerPiece(InterCoord, i).name + "))))"); if (i == 0) { if (LocateChessBoardController.GetCheckerBoardPlayerAlivePiece(InterCoord, PlayerID, i) == null) { Debug.Log("get piece is null"); Debug.Log(LocateChessBoardController.GetCheckerBoardPlayerAlivePieceNum(InterCoord, PlayerID)); } //LocateChessBoardStateController.GetCheckerPiece(InterCoord, i).SetActive(true); LocateChessBoardController.GetCheckerBoardPlayerAlivePiece(InterCoord, PlayerID, i).GetComponentInChildren <PieceOperationController>().DisplayPiece(); } else { //LocateChessBoardStateController.GetCheckerPiece(InterCoord, i).SetActive(false); LocateChessBoardController.GetCheckerBoardPlayerAlivePiece(InterCoord, PlayerID, i).GetComponentInChildren <PieceOperationController>().HidePiece(); } } }
public void ToState(GameFlowState _state) { GameObject[] grounds = GameObject.FindGameObjectsWithTag("Ground"); state = _state; Debug.Log("GameFlow ToState" + _state); switch (state) { case GameFlowState.MANAGE: dataController.PutMoneyToPlayers(); break; case GameFlowState.READY: dataController.ArangeEnemyForBoards(); break; case GameFlowState.BATTLE: unfinishGroundCount = grounds.Length; break; } foreach (GameObject ground in grounds) { ChessBoardController board = ground.GetComponent <ChessBoardController> (); if (state == GameFlowState.BATTLE) { board.OnBattleOver += BattleOverHandler; } board.SetState(state); } PlayerController player = GameObject.Find("Player").GetComponent <PlayerController> (); player.SetState(state); }
public void BoardReady(ChessBoardController _board) { Init(_board); Vector3 pos = _board.GetChessPosition(x, y); transform.SetPositionAndRotation(pos, transform.rotation); GetComponent <MeshRenderer> ().material.color = chessColor; }
public void Init(ChessBoardController _board) { board = _board; GameObject HpBar = Resources.Load("Prefabs/HpBar") as GameObject; attr = new BattleUnitAttr(); getAttrs(); hp = maxHp; hpBar = GameObject.Instantiate(HpBar); hpBar.transform.parent = GameObject.Find("HpCanvas").transform; Update2DObj(); SetState(state); }
void GenerateChessBoards(List <PlayerInfo> players) { boards = new List <ChessBoardController> (); GameObject GroundPrefab = Resources.Load("Prefabs/Ground") as GameObject; Vector3 groundSize = GroundPrefab.GetComponent <Renderer> ().bounds.size; Vector3 pos = Vector3.zero; Vector3 posAdd = new Vector3(groundSize.x * 1.6f, -10, 15); for (int i = 0; i < players.Count; i++) { PlayerInfo player = players[i]; GameObject ground = GameObject.Instantiate(GroundPrefab); ground.transform.parent = GameObject.Find("Grounds").transform; ground.transform.position = pos; pos += posAdd; ChessBoardController board = ground.GetComponent <ChessBoardController> (); board.ownerTeam = i; boards.Add(board); } }
private void BattleOverHandler(ChessBoardController board, int hpChange) { Debug.Log("Battle Over Handler:" + unfinishGroundCount + "," + board.ownerTeam); if (hpChange != 0) { int owner = board.ownerTeam; int enemy = board.enemyTeam; dataController.PlayerHpChange(owner, hpChange); // dataController.PlayerHpChange(enemy, -hpChange); //吸血模式 } if (unfinishGroundCount > 0) { unfinishGroundCount--; if (unfinishGroundCount <= 0) { ToNextState(); } } }