private void Set(int Index, int XDim, int YDim, GridElement.GridElementState GriElementType, bool SetBack = false) { int MyPosY = (int)Mathf.Floor(Index / 6); int MyPosX = Index - (MyPosY * 6); if (SetBack) { for (int CntX = 0; CntX < XDim; CntX++) { for (int CntY = 0; CntY < YDim; CntY++) { int NewIndex = IndexFromDims(Index, CntX, CntY); if (NewIndex != -1) { transform.GetChild(NewIndex).GetComponent <GridElement>().SetBack(); } } } } else { for (int CntX = 0; CntX < XDim; CntX++) { for (int CntY = 0; CntY < YDim; CntY++) { int NewIndex = IndexFromDims(Index, CntX, CntY); if (NewIndex != -1) { transform.GetChild(NewIndex).GetComponent <GridElement>().SetState(GriElementType); } } } } }
public void SetState(PlaceShipsStates NewState) { if (MyGlobalController == null) { Start(); } CurrState = NewState; switch (CurrState) { case PlaceShipsStates.Place2x1: MyGlobalController.MyShipsMessage.text = "Place your 2x1 ship."; MyGlobalController.MyGridControllerScript.ClearMyShip(); break; case PlaceShipsStates.Place1X3: MyGlobalController.MyShipsMessage.text = "Place your 1x3 ship."; break; case PlaceShipsStates.Place4X1: MyGlobalController.MyShipsMessage.text = "Place your 4x1 ship."; break; case PlaceShipsStates.Place1X5: MyGlobalController.MyShipsMessage.text = "Place your 1x5 ship."; break; case PlaceShipsStates.SendData: GridElement.GridElementState[] MyShips = new GridElement.GridElementState[48]; for (int CntX = 0; CntX < 6; CntX++) { for (int CntY = 0; CntY < 8; CntY++) { if (MyGlobalController.MyGridControllerScript.gameObject.transform.GetChild(CntY * 6 + CntX).GetComponent <GridElement>().MyCurrState != GridElement.GridElementState.Empty) { MyShips[CntY * 6 + CntX] = GridElement.GridElementState.Occupied; } else { MyShips[CntY * 6 + CntX] = GridElement.GridElementState.Empty; } } } if (isClient) { CmdSendShips(MyShips, MyGlobalController.WelcomeInputName.text); } break; default: MyGlobalController.MyShipsMessage.text = "This is your sea."; break; } }