public static BoardElement CreateNewElement(BoardElement previousElement, BoardElement.BoardElementTypes type) { int randomNum = random.Next(0, ConstantValues.GetAvailableColors().Length); Vector4 newColor = ConstantValues.GetAvailableColors() [randomNum]; switch (type) { case BoardElement.BoardElementTypes.Cross: previousElement = new CrossBoardElement(previousElement.GetTransformIndex(), previousElement.GetElementValue()); break; case BoardElement.BoardElementTypes.Bomb: previousElement = new BombBoardElement(previousElement.GetTransformIndex()); break; case BoardElement.BoardElementTypes.Bell: previousElement = new BellBoardElement(previousElement.GetTransformIndex()); break; case BoardElement.BoardElementTypes.Default: if (previousElement.GetElementClassType() != typeof(BoardElement)) { previousElement = new BoardElement(previousElement.GetTransformIndex(), newColor); } else { previousElement.OnElementAppearance(newColor); } break; } return(previousElement); }
void Awake() { inst = this; elementsPositions = new BoardElement[ConstantValues.totalCollums, ConstantValues.totalRows]; matchedElemPositions = new bool[ConstantValues.totalCollums, ConstantValues.totalRows]; possibleInput = new bool[ConstantValues.totalCollums, ConstantValues.totalRows]; changedPotitions = new bool[ConstantValues.totalCollums, ConstantValues.totalRows]; // Debug //DebugCheckPanels(); int row = 0; int collum = 0; // Assign elements to the board // foreach gameobject child of gameobject "GamePanel" for (int i = 0; i < ConstantValues.totalCollums * ConstantValues.totalRows; i++) { // if in set bounds if (collum < ConstantValues.totalCollums && row < ConstantValues.totalRows) { // Get a random color int randomNum = random.Next(0, ConstantValues.GetAvailableColors().Length); Vector4 newColor = ConstantValues.GetAvailableColors() [randomNum]; // Create a new BoardElement instance an assign it to positions board elementsPositions[collum, row] = new BoardElement(new int[] { 0, 1, i }, newColor); // new animation to show the default sprite on gameobject currentMessageID += 1; messagesToClient.Add(new Messages.AnimationMessage(currentMessageID, -1, Messages.AnimationMessage.AnimationMessageTypes.ChangeSprite, elementsPositions[collum, row].GetImageTransformIndex(), (int)ConstantValues.AvailableSprites.defaultElement, newColor)); changedPotitions[collum, row] = true; collum++; // fix collum index if (collum == ConstantValues.totalCollums) { row++; collum = 0; } } else { UnityEngine.Debug.LogError("There are more transforms on the board than collums * rows"); } } AddWaitMessage(); SendMessagesToClient(); }