Esempio n. 1
0
 public void PressPiece(gamePiece piece)   //这是第一个选择的块
 {
     pressedPiece = piece;
     //判定亮起
     ChangeColor(piece, 180);
     SearchClearablePiece(piece);
     //显示UI
 }
Esempio n. 2
0
 //TODO:改变透明度,以后可能改变模型
 public void RestorePiece()
 {
     for (int x = 0; x < xdim; x++)
     {
         for (int y = 0; y < ydim; y++)
         {
             gamePiece piece = pieces[x, y];
             piece.GetComponentInChildren <SpriteRenderer>().material.color = new Color32(255, 255, 255, 255);
             piece.ClearType = (int)gamePiece.ClearTypeEnum.NONE;
             piece.transform.Find("magicRing").gameObject.SetActive(false);
         }
     }
 }
Esempio n. 3
0
    //单步填充计算
    public bool FillStep()
    {
        bool movedPiece = false;

        for (int x = 1; x < xdim; x++)
        {
            for (int y = 0; y < ydim; y++)
            {
                gamePiece piece = pieces[x, y];
                if (piece.isMovable())
                {
                    gamePiece pieceBelow = pieces[x - 1, y];
                    if (pieceBelow.getType() == pieceType.EMPTY)
                    {
                        Destroy(pieceBelow.gameObject);
                        piece.MovableComponent.Move(x - 1, y, filltime);
                        pieces[x - 1, y] = piece;
                        SpawnNewPiece(x, y, pieceType.EMPTY);
                        movedPiece = true;
                    }
                    ;
                }
            }
        }

        for (int y = 0; y < ydim; y++)
        {
            gamePiece pieceBelow = pieces[xdim - 1, y];

            if (pieceBelow.getType() == pieceType.EMPTY)
            {
                Destroy(pieceBelow.gameObject);
                GameObject newPiece = (GameObject)Instantiate(piecePrefabDict[pieceType.NORMAL], GetWorldPositon(xdim - 0.84f, y), Quaternion.identity);
                newPiece.transform.parent = transform;

                pieces[xdim - 1, y] = newPiece.GetComponent <gamePiece>();
                pieces[xdim - 1, y].Init(xdim - 1, y, this, pieceType.NORMAL);
                pieces[xdim - 1, y].MovableComponent.Move(xdim - 0.84f, y, filltime);
                pieces[xdim - 1, y].ColorPieceComponent.SetColor((ColorPiece.ColorType)Random.Range(0, pieces[xdim - 1, y].ColorPieceComponent.NumColors));
                movedPiece = true;
            }
        }
        return(movedPiece);
    }
Esempio n. 4
0
 public void ChangeColor(gamePiece piece, float newAlpha)
 {
     piece.transform.Find("magicRing").gameObject.SetActive(true);
     //piece.GetComponentInChildren<SpriteRenderer>().material.color = new Color(1, 1, 1, newAlpha/255);
 }
Esempio n. 5
0
    public void ReleasePiece()
    {
        // RealeasedPiece = piece;
        //以后这里都要改成按照状态判断
        gamePiece piece1 = enteredPiece;
        gamePiece piece2 = pressedPiece;

        switch (enteredPiece.ClearType)
        {
        case 1:
            ClearPiece(pressedPiece.X, pressedPiece.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.AttackSingleClear);
            Debug.Log("1消了进攻球");
            break;

        case 2:
            ClearPiece(pressedPiece.X, pressedPiece.Y);
            ClearPiece(enteredPiece.X, enteredPiece.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.AttackDoubleClear);
            Debug.Log("2消了进攻球");
            break;

        case 3:
            if (pressedPiece.X < enteredPiece.X)
            {
                piece1 = pieces[pressedPiece.X + 1, pressedPiece.Y];
                piece2 = pieces[enteredPiece.X - 1, enteredPiece.Y];
            }
            if (pressedPiece.X > enteredPiece.X)
            {
                piece1 = pieces[pressedPiece.X - 1, pressedPiece.Y];
                piece2 = pieces[enteredPiece.X + 1, enteredPiece.Y];
            }
            ClearPiece(pressedPiece.X, pressedPiece.Y);
            ClearPiece(enteredPiece.X, enteredPiece.Y);
            ClearPiece(piece1.X, piece1.Y);
            ClearPiece(piece2.X, piece2.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.AttackTripleClear);
            Debug.Log("4消了进攻球");
            break;

        case 4:
            ClearPiece(pressedPiece.X, pressedPiece.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.DefenseSingleClear);
            Debug.Log("1消了防御球");
            break;

        case 5:
            ClearPiece(pressedPiece.X, pressedPiece.Y);
            ClearPiece(enteredPiece.X, enteredPiece.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.DefenseDoubleClear);
            Debug.Log("2消了防御球");
            break;

        case 6:
            Debug.Log("4消了防御球");
            piece1 = enteredPiece;
            piece2 = pressedPiece;

            if (pressedPiece.X < enteredPiece.X)
            {
                piece1 = pieces[pressedPiece.X + 1, pressedPiece.Y];
                piece2 = pieces[enteredPiece.X - 1, enteredPiece.Y];
            }
            if (pressedPiece.X > enteredPiece.X)
            {
                piece1 = pieces[pressedPiece.X - 1, pressedPiece.Y];
                piece2 = pieces[enteredPiece.X + 1, enteredPiece.Y];
            }

            ClearPiece(pressedPiece.X, pressedPiece.Y);
            ClearPiece(enteredPiece.X, enteredPiece.Y);
            ClearPiece(piece1.X, piece1.Y);
            ClearPiece(piece2.X, piece2.Y);
            Levelsystem.GetComponent <LevelSystem>().Hero.GetComponent <CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.DefenseTripleClear);

            break;

        default:
            Debug.Log("没有判断出消球");
            break;
        }

        /*if (enteredPiece.ClearType == (int)gamePiece.ClearTypeEnum.AttackSingleClear) {
         *  ClearPiece(pressedPiece.X, pressedPiece.Y);
         *  Levelsystem.GetComponent<LevelSystem>().battleInitial.hero.GetComponent<CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.AttackSingleClear);
         *  Debug.Log("1消了进攻球");
         * }
         * else if (enteredPiece.ClearType == (int)gamePiece.ClearTypeEnum.AttackDoubleClear) {
         *  ClearPiece(pressedPiece.X, pressedPiece.Y);
         *  ClearPiece(enteredPiece.X, enteredPiece.Y);
         *  Levelsystem.GetComponent<LevelSystem>().battleInitial.hero.GetComponent<CharacterProperties>().StartSkill((int)gamePiece.ClearTypeEnum.AttackDoubleClear);
         * } else if (enteredPiece.ClearType == (int)gamePiece.ClearTypeEnum.AttackTripleClear) {
         *  gamePiece piece1 = enteredPiece;
         *  gamePiece piece2 = pressedPiece;
         *
         *  if (pressedPiece.X < enteredPiece.X) {
         *      piece1 = pieces[pressedPiece.X + 1, pressedPiece.Y];
         *      piece2 = pieces[enteredPiece.X - 1, enteredPiece.Y];
         *  }
         *  if (pressedPiece.X > enteredPiece.X) {
         *      piece1 = pieces[pressedPiece.X - 1, pressedPiece.Y];
         *      piece2 = pieces[enteredPiece.X + 1, enteredPiece.Y];
         *  }
         *
         *  ClearPiece(pressedPiece.X, pressedPiece.Y);
         *  ClearPiece(enteredPiece.X, enteredPiece.Y);
         *  ClearPiece(piece1.X, piece1.Y);
         *  ClearPiece(piece2.X, piece2.Y);
         * }*/
        RestorePiece();
    }
Esempio n. 6
0
 public void EnterPiece(gamePiece piece)   //这是最后一个选择的块
 {
     enteredPiece = piece;
     //判定是否构成连锁消除
     //TODO:根据种类显示UI
 }
Esempio n. 7
0
    public void SearchClearablePiece(gamePiece piece)
    {
        if (piece.ColorPieceComponent.Color == ColorPiece.ColorType.RED)
        {
            piece.ClearType = (int)gamePiece.ClearTypeEnum.AttackSingleClear;
        }
        else if (piece.ColorPieceComponent.Color == ColorPiece.ColorType.BLUE)
        {
            piece.ClearType = (int)gamePiece.ClearTypeEnum.DefenseSingleClear;
        }

        for (int x = 0; x < xdim - 1; x++)
        {
            for (int y = 0; y < ydim; y++)
            {
                gamePiece piecePotential = pieces[x, y];
                if (IsAdjacent(piece, piecePotential) && IsSameColor(piece, piecePotential))
                {
                    ChangeColor(piecePotential, 180);
                    if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.RED)
                    {
                        piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.AttackDoubleClear;
                    }
                    else if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.BLUE)
                    {
                        piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.DefenseDoubleClear;
                    }
                    //这几个是二消的
                    //Debug.Log(piecePotential.GetComponentInChildren<SpriteRenderer>());
                }
            }
        }
        for (int x = 0; x < xdim - 1; x++)
        {
            for (int y = 0; y < ydim; y++)
            {
                gamePiece piecePotential = pieces[x, y];
                if ((int)Mathf.Abs(piece.X - piecePotential.X) == 1 && (int)Mathf.Abs(piece.Y - piecePotential.Y) == 1 && IsSameColor(piece, piecePotential))
                {
                    //如果点选的x大于进入的x,不用考虑边界
                    if (piece.X < piecePotential.X)
                    {
                        gamePiece piece1 = pieces[piece.X + 1, piece.Y];
                        gamePiece piece2 = pieces[piecePotential.X - 1, piecePotential.Y];
                        if (IsSameColor(piece1, piece) && IsSameColor(piece2, piece))
                        {
                            if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.RED)
                            {
                                piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.AttackTripleClear;
                            }
                            else if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.BLUE)
                            {
                                piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.DefenseTripleClear;
                            }
                            ChangeColor(piecePotential, 100);
                        }
                    }

                    if (piece.X > piecePotential.X)
                    {
                        gamePiece piece1 = pieces[piece.X - 1, piece.Y];
                        gamePiece piece2 = pieces[piecePotential.X + 1, piecePotential.Y];
                        if (IsSameColor(piece1, piece) && IsSameColor(piece2, piece))
                        {
                            if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.RED)
                            {
                                piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.AttackTripleClear;
                            }
                            else if (piecePotential.ColorPieceComponent.Color == ColorPiece.ColorType.BLUE)
                            {
                                piecePotential.ClearType = (int)gamePiece.ClearTypeEnum.DefenseTripleClear;
                            }
                            ChangeColor(piecePotential, 100);
                        }
                    }
                }
            }
        }
    }
Esempio n. 8
0
 public bool IsSameColor(gamePiece piece1, gamePiece piece2)
 {
     return(piece1.ColorPieceComponent.Color == piece2.ColorPieceComponent.Color);
 }
Esempio n. 9
0
 public bool IsAdjacent(gamePiece piece1, gamePiece piece2)
 {
     return(piece1.X == piece2.X && (int)Mathf.Abs(piece1.Y - piece2.Y) == 1 ||
            piece1.Y == piece2.Y && (int)Mathf.Abs(piece1.X - piece2.X) == 1);
     //是否相邻
 }
Esempio n. 10
0
        private void gamePieceEvent_Click(object sender, EventArgs e)
        {
            if (sessionTimer.Enabled == false)
                sessionTimer.Start();
            int x, y;
            x = (((Button)sender).Location.X) / 50;
            y = (((Button)sender).Location.Y) / 50;

            gamePiece temp = new gamePiece();
            temp.pieceButton = new Button();
            Point tempPoint = new Point(0, 0);

            pieceArray[lastEvent.X/50,lastEvent.Y/50].pieceButton.BackColor = this.BackColor;
            if ((lastEvent.X == ((Button)sender).Location.X) && (lastEvent.Y == ((((Button)sender).Location.Y)+50)))
            {
                makeMove(x, y, x, y+1);

                if (!checkMove(pieceArray[x, y]) && !checkMove(pieceArray[x, y + 1]))
                    makeMove(x, y, x, y + 1);
                else
                    lastEvent = new Point(0, 0);
            }
            else if ((lastEvent.X == ((((Button)sender).Location.X)+50)) && (lastEvent.Y == ((Button)sender).Location.Y))
            {
                makeMove(x, y, x + 1, y);

                if (!checkMove(pieceArray[x, y]) && !checkMove(pieceArray[x + 1, y]))
                    makeMove(x, y, x + 1, y);
                else
                    lastEvent = new Point(0, 0);

            }
            else if ((lastEvent.X == ((Button)sender).Location.X) && (lastEvent.Y == ((((Button)sender).Location.Y) - 50)))
            {

                makeMove(x, y, x, y - 1);
                if (!checkMove(pieceArray[x, y]) && !checkMove(pieceArray[x, y - 1]))
                    makeMove(x, y, x, y - 1);
                else
                    lastEvent = new Point(0, 0);
            }
            else if ((lastEvent.X == ((((Button)sender).Location.X) - 50)) && (lastEvent.Y == ((Button)sender).Location.Y))
            {
                makeMove(x, y, x - 1, y);
                if (!checkMove(pieceArray[x, y]) && !checkMove(pieceArray[x - 1, y]))
                    makeMove(x, y, x - 1, y);
                else
                    lastEvent = new Point(0, 0);
            }
            else
            {
                lastEvent = ((Button)sender).Location;
                ((Button)sender).BackColor = Color.Yellow;
                return;
            }
            do
            {
                fillGaps();
            }
            while (checkBoardHorizontal() || checkBoardVertical());

        }
Esempio n. 11
0
        private void makeMove(int x, int y, int k, int j)
        {
            gamePiece temp = new gamePiece();
            temp.pieceButton = new Button();

            temp.pieceButton.BackgroundImage = pieceArray[x, y].pieceButton.BackgroundImage;
            pieceArray[x, y].pieceButton.BackgroundImage = pieceArray[k, j].pieceButton.BackgroundImage;
            pieceArray[k, j].pieceButton.BackgroundImage = temp.pieceButton.BackgroundImage;

            temp.jewelType = pieceArray[x, y].jewelType;
            pieceArray[x, y].jewelType = pieceArray[k, j].jewelType;
            pieceArray[k, j].jewelType = temp.jewelType;
        }
Esempio n. 12
0
 private void Awake()
 {
     piece = GetComponent <gamePiece>();
 }