コード例 #1
0
ファイル: MatchPieceType.cs プロジェクト: tacman/UnityMatch3
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            MatchPieceType otherPiece = obj as MatchPieceType;

            if (otherPiece != null)
            {
                return(string.Compare(this.name, otherPiece.name, StringComparison.CurrentCulture));
            }
            else
            {
                throw new ArgumentException("Object is not a MatcPieceType");
            }
        }
コード例 #2
0
        public void SetupPiece(int row, int column, MatchPieceType type, float time)
        {
            this.row    = row;
            this.column = column;
            this.type   = type;

            inUse = true;

            horizontalMatch    = false;
            verticalMatch      = false;
            diagonalMatchRight = false;
            diagonalMatchLeft  = false;

            mBallColorRender.sprite = type.sprite;

            DOTween.Sequence()
            .Append(transform.DOScale(1f, time))
            .Join(mBallColorRender.DOFade(1f, time));
        }
コード例 #3
0
        private void CreateBoard(float xOffset, float yOffset)
        {
            float startX = transform.position.x;
            float startY = transform.position.y;

            MatchPieceType[] previousLeft  = new MatchPieceType[columns];
            MatchPieceType   previousBelow = null;

            board = new MatchPiece[rows][];
            for (int x = 0; x < rows; x++)
            {
                board[x] = new MatchPiece[columns];
                for (int y = 0; y < columns; y++)
                {
                    var tile = Instantiate(
                        matchPieceObject,
                        new Vector3(startX + (xOffset * x),
                                    startY + (yOffset * y),
                                    2),
                        matchPieceObject.transform.rotation).AddComponent <MatchPiece>();

                    List <MatchPieceType> possibletypes = new List <MatchPieceType>();
                    possibletypes.AddRange(pieceTypes);

                    possibletypes.Remove(previousLeft[y]);
                    possibletypes.Remove(previousBelow);

                    MatchPieceType type = possibletypes[Random.Range(0, possibletypes.Count)];

                    tile.SetupPiece(y, x, type, TIME_TO_EXPLODE);

                    previousLeft[y] = type;
                    previousBelow   = type;

                    board[x][y] = tile;
                }
            }
        }