Exemple #1
0
    private bool CheckAllHorseofPlayer(int playerNumber, int diceNumber)
    {
        int cnt             = 0;
        int squareMaxPlayer = (playerNumber - 1) * 12 + 48;       // o toi da co the den cua playerNumber


        for (int i = 1; i <= 4; i++)
        {
            Horse horse = player[playerNumber].getHorse(i);
            if (horse.Check_trong_chuong())
            {
                continue;
            }
            if (horse.GetChuongUnder() != 0)
            {
                continue;
            }
            horse.SetCanRun(2);
            int squareUnder = horse.GetSquareUnder();
            if (playerNumber == 2 && 1 <= squareUnder && squareUnder <= 12)
            {
                squareUnder += 48;
            }
            if (playerNumber == 3 && 1 <= squareUnder && squareUnder <= 24)
            {
                squareUnder += 48;
            }
            if (playerNumber == 4 && 1 <= squareUnder && squareUnder <= 36)
            {
                squareUnder += 48;
            }

            Debug.Log(squareUnder.ToString());
            if (squareUnder + diceNumber > squareMaxPlayer && squareUnder < squareMaxPlayer)
            {
                horse.SetCanRun(0);
            }
            else
            {
                for (int j = squareUnder + 1; j <= diceNumber + squareUnder - 1; j++)
                {
                    //int k = (j - 1) % 48 + 1;// fix vuot qua gioi han 48 o
                    if (square[(j - 1) % 48 + 1].GetPlayerOnThisSquare() != 0) // neu tren o nay co con ngua dang dung
                    {
                        Debug.Log(i.ToString() + "bi chan");
                        horse.SetCanRun(0);
                        break;
                    }
                }
            }

            if (square[(squareUnder + diceNumber - 1) % 48 + 1].GetPlayerOnThisSquare() == playerNumber)
            {
                horse.SetCanRun(0);
            }

            if (squareUnder == squareMaxPlayer)     // kiem tra di chuyen o o toi da cua player
            {
                horse.SetCanRun(3);
                for (int j = 1; j <= diceNumber; j++)
                {
                    if (chuongDich[playerNumber, j].HasHorse())
                    {
                        horse.SetCanRun(0);
                    }
                }
            }
        }

        Debug.Log(cnt);
        for (int i = 1; i <= 4; i++)
        {
            if (player[playerNumber].getHorse(i).GetCanRun() > 0)
            {
                return(true);
            }
        }
        return(false);
    }
Exemple #2
0
    private void Run_horse(int playerNumber)
    {
        int currentsquare = horsePicking.GetSquareUnder();                                  //o hien tai dang dung
        int tmp           = (currentsquare + DiceNumberTextScript.diceNumber - 1) % 48 + 1; // o tiep theo se di den

        Debug.Log("currentsquare " + currentsquare);
        Debug.Log("tmp " + tmp);
        if (horsePicking.GetCanRun() == 1)
        {
            //xuat chuong
            if (playerNumber == 1)
            {
                tmp = 1;
                horsePicking.MoveTo(square[1].getPosition());
                square[1].SetHasHorse();
            }
            if (playerNumber == 2)
            {
                tmp = 13;
                horsePicking.MoveTo(square[13].getPosition());
                square[13].SetHasHorse();
            }
            if (playerNumber == 3)
            {
                tmp = 25;
                square[25].SetHasHorse();
                horsePicking.MoveTo(square[25].getPosition());
            }
            if (playerNumber == 4)
            {
                tmp = 37;
                square[37].SetHasHorse();
                horsePicking.MoveTo(square[37].getPosition());
            }
            horsePicking.Xuat_chuong();
        }
        if (horsePicking.GetCanRun() == 2)
        {
            // di binh thuong
            Debug.Log("di binh thuong");
            if (square[tmp].HasHorse())
            { // neu co quan cua thang khac thi da
                Debug.Log("da chet cmm di");
                Horse   dieHorse = HorseOfSquare(tmp);
                Vector3 tmpVec   = Chuong[(dieHorse.getplayerNumber() - 1) * 4 + dieHorse.gethorseNumber()];
                dieHorse.MoveTo(new Vector3(tmpVec.x, tmpVec.y - 3.5f, tmpVec.z));
                dieHorse.Nhap_chuong();
            }// da

            square[tmp].SetHasHorse();
            horsePicking.MoveTo(square[tmp].getPosition()); // mac dinh la di binh thuong


            square[currentsquare].resetAll();
        }

        if (horsePicking.GetCanRun() == 3)
        {
            //di trong chuong dich
            Chuong chuong = null;
            if (horsePicking.GetSquareUnder() > 0)
            {
                chuong = chuongDich[playerNumber, DiceNumberTextScript.diceNumber];
                horsePicking.SetChuongUnder(DiceNumberTextScript.diceNumber);
                chuongDich[currentPlayer, DiceNumberTextScript.diceNumber].SetHasHorse();
            }
            if (horsePicking.GetSquareUnder() == 0)
            {
                chuong = chuongDich[playerNumber, horsePicking.GetChuongUnder() + 1];
                horsePicking.SetChuongUnder(horsePicking.GetChuongUnder() + 1);
                chuongDich[currentPlayer, horsePicking.GetChuongUnder() + 1].SetHasHorse();
            }

            if (chuong != null)
            {
                horsePicking.MoveTo(new Vector3(chuong.getPosition().x, chuong.getPosition().y - 1.8f, chuong.getPosition().z));
            }
        }

        if (horsePicking.GetCanRun() != 3)
        {
            UpdateSquareOfHorse(playerNumber, horsePicking.gethorseNumber(), tmp);
        }
        return;
    }