Ejemplo n.º 1
0
 public void StartGame()
 {
     currentPlayerIndex = UnityEngine.Random.Range(0, players.Count);
     currentTurnPlayer  = players[currentPlayerIndex];
     currentTurnPlayer.Activate(true);
     Destroy(startButton.gameObject);
 }
Ejemplo n.º 2
0
    public void NextPlayer()
    {
        if (players.Count < 2)
        {
            Debug.Log("Game Over");
        }

        if (currentTurnPlayer != null)
        {
            currentTurnPlayer.Activate(false);
        }
        else
        {
            currentPlayerIndex--;
        }

        currentTurnPlayer = null;

        while (currentTurnPlayer == null)
        {
            currentPlayerIndex++;

            if (currentPlayerIndex >= players.Count)
            {
                currentPlayerIndex = 0;
            }

            currentTurnPlayer = players[currentPlayerIndex];
        }

        currentTurnPlayer.Activate(true);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the game loop. This loop returns once the game finishes.
        /// </summary>
        /// <param name="playerFirst">Whether the player should have the first turn. Else the enemy begins.</param>
        /// <returns></returns>
        public async Task RunAsync(bool playerFirst = false)
        {
            TurnPlayer = playerFirst ? Player : Enemy;
            TriggerEvent("first-turn", new EventArgs());

            int guard = 0;

            while (Player.LifePoints > 0 && Enemy.LifePoints > 0)
            {
                TurnPlayer            = TurnPlayer.Equals(Player) ? Enemy : Player;
                context["TurnPlayer"] = TurnPlayer;

                TriggerEvent("turn", new EventArgs());

                if (guard++ > 3)
                {
                    return;
                }
            }
        }
Ejemplo n.º 4
0
 private void OnPlayerDestroyed(TurnPlayer player)
 {
     players.Remove(player);
 }
Ejemplo n.º 5
0
    void TaoBai()
    {
        foreach (var item in p1.card)
        {
            Destroy(item);
        }
        p1.p.dataCard.Clear();
        foreach (var item in p2.card)
        {
            Destroy(item);
        }
        p2.p.dataCard.Clear();
        foreach (var item in p3.card)
        {
            Destroy(item);
        }
        p3.p.dataCard.Clear();
        foreach (var item in p4.card)
        {
            Destroy(item);
        }
        p4.p.dataCard.Clear();

        List <DataCard> datas = new List <DataCard>();

        for (int a = 0; a < 4; a++)
        {
            for (int b = 0; b < 13; b++)
            {
                datas.Add(new DataCard((DataCard.Chat)a, (DataCard.Nut)b));
            }
        }

        int r = Random.Range(0, datas.Count);

        for (int i = 0; i < 13; i++)
        {
            datas[r].player = p1.p;
            p1.p.dataCard.Add(datas[r]);
            datas.RemoveAt(r);
            r = Random.Range(0, datas.Count);
        }

        for (int i = 0; i < 13; i++)
        {
            datas[r].player = p2.p;
            p2.p.dataCard.Add(datas[r]);
            datas.RemoveAt(r);
            r = Random.Range(0, datas.Count);
        }

        for (int i = 0; i < 13; i++)
        {
            datas[r].player = p3.p;
            p3.p.dataCard.Add(datas[r]);
            datas.RemoveAt(r);
            r = Random.Range(0, datas.Count);
        }

        for (int i = 0; i < 13; i++)
        {
            datas[0].player = p4.p;
            p4.p.dataCard.Add(datas[0]);
            datas.RemoveAt(0);
        }

        p1.XoeBai();
        p2.XoeBai();
        p3.XoeBai();
        p4.XoeBai();

        if (firstRound)
        {
            //nguoi choi cam la 3 bich duoc di truoc
            foreach (var item in FindObjectsOfType <Card>())
            {
                if (item.data.nut == DataCard.Nut._3 && item.data.chat == DataCard.Chat._Bich)
                {
                    if (item.data.player == p1.p)
                    {
                        turnPlayer = TurnPlayer.P1;
                    }
                    else if (item.data.player == p2.p)
                    {
                        turnPlayer = TurnPlayer.P2;
                        p2.ToiLuotDanh();
                    }
                    else if (item.data.player == p3.p)
                    {
                        turnPlayer = TurnPlayer.P3;
                        p3.ToiLuotDanh();
                    }
                    else if (item.data.player == p4.p)
                    {
                        turnPlayer = TurnPlayer.P4;
                        p4.ToiLuotDanh();
                    }
                    break;
                }
            }
        }
        else
        {
            switch (turnPlayer)
            {
            case TurnPlayer.P1:
                break;

            case TurnPlayer.P2:
                p2.ToiLuotDanh();
                break;

            case TurnPlayer.P3:
                p3.ToiLuotDanh();
                break;

            case TurnPlayer.P4:
                p4.ToiLuotDanh();
                break;
            }
        }
    }
Ejemplo n.º 6
0
    void ShowKetQua()
    {
        foreach (Transform item in GameObject.Find("Group Card").transform)
        {
            Destroy(item.gameObject);
        }

        sortI = 1;

        p1.p.coLuot = true;
        p1.p.hetBai = false;

        p2.p.coLuot = true;
        p2.p.hetBai = false;

        p3.p.coLuot = true;
        p3.p.hetBai = false;

        p4.p.coLuot = true;
        p4.p.hetBai = false;

        groupCard.p = null;

        foreach (var item in p1.card)
        {
            Destroy(item);
        }

        foreach (var item in p2.card)
        {
            Destroy(item);
        }

        foreach (var item in p3.card)
        {
            Destroy(item);
        }

        foreach (var item in p4.card)
        {
            Destroy(item);
        }

        stateGame = StateGame.KetQua;

        panelKetQua.SetActive(true);
        nameP1.text = "Player " + indexP1;
        nameP2.text = "Player " + indexP2;
        nameP3.text = "Player " + indexP3;
        nameP4.text = "Player " + indexP4;

        if (indexP1 == 1)
        {
            turnPlayer = TurnPlayer.P1;
        }
        if (indexP1 == 2)
        {
            turnPlayer = TurnPlayer.P2;
        }
        if (indexP1 == 3)
        {
            turnPlayer = TurnPlayer.P3;
        }
        if (indexP1 == 4)
        {
            turnPlayer = TurnPlayer.P4;
        }
    }
Ejemplo n.º 7
0
    public void NextPlayer()
    {
        int pHetBai = 0;

        if (p1.p.hetBai)
        {
            pHetBai++;
        }
        if (p2.p.hetBai)
        {
            pHetBai++;
        }
        if (p3.p.hetBai)
        {
            pHetBai++;
        }
        if (p4.p.hetBai)
        {
            pHetBai++;
        }

        if (pHetBai == 3)
        {
            ShowKetQua();
            return;
        }

        int pBoLuot = 0;

        if (!p1.p.coLuot || p1.p.hetBai)
        {
            pBoLuot++;
        }
        if (!p2.p.coLuot || p2.p.hetBai)
        {
            pBoLuot++;
        }
        if (!p3.p.coLuot || p3.p.hetBai)
        {
            pBoLuot++;
        }
        if (!p4.p.coLuot || p4.p.hetBai)
        {
            pBoLuot++;
        }

        if (pBoLuot == 3)
        {
            ResetLuot();
            if (groupCard.p.gameObject.name == "Player 1")
            {
                if (p1.p.hetBai)
                {
                    if (p2.p.hetBai)
                    {
                        if (p3.p.hetBai)
                        {
                            turnPlayer = TurnPlayer.P4;
                            p4.ToiLuotDanh();
                        }
                        else
                        {
                            turnPlayer = TurnPlayer.P3;
                            p3.ToiLuotDanh();
                        }
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P2;
                        p2.ToiLuotDanh();
                    }
                }
                else
                {
                    turnPlayer = TurnPlayer.P1;
                }
            }
            else if (groupCard.p.gameObject.name == "Player 2")    //LA BAI CUOI DC DANH RA BOI NGUOI CHOI DA HET BAI MA KHONG CO NGUOI AN SE LOI
            {
                if (p2.p.hetBai)
                {
                    if (p3.p.hetBai)
                    {
                        if (p4.p.hetBai)
                        {
                            turnPlayer = TurnPlayer.P1;
                        }
                        else
                        {
                            turnPlayer = TurnPlayer.P4;
                            p4.ToiLuotDanh();
                        }
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P3;
                        p3.ToiLuotDanh();
                    }
                }
                else
                {
                    turnPlayer = TurnPlayer.P2;
                    p2.ToiLuotDanh();
                }
            }
            else if (groupCard.p.gameObject.name == "Player 3")
            {
                if (p3.p.hetBai)
                {
                    if (p4.p.hetBai)
                    {
                        if (p1.p.hetBai)
                        {
                            turnPlayer = TurnPlayer.P2;
                            p2.ToiLuotDanh();
                        }
                        else
                        {
                            turnPlayer = TurnPlayer.P1;
                        }
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P4;
                        p4.ToiLuotDanh();
                    }
                }
                else
                {
                    turnPlayer = TurnPlayer.P3;
                    p3.ToiLuotDanh();
                }
            }
            else if (groupCard.p.gameObject.name == "Player 4")
            {
                if (p4.p.hetBai)
                {
                    if (p1.p.hetBai)
                    {
                        if (p2.p.hetBai)
                        {
                            turnPlayer = TurnPlayer.P3;
                            p3.ToiLuotDanh();
                        }
                        else
                        {
                            turnPlayer = TurnPlayer.P2;
                            p2.ToiLuotDanh();
                        }
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P1;
                    }
                }
                else
                {
                    turnPlayer = TurnPlayer.P4;
                    p4.ToiLuotDanh();
                }
            }

            groupCard.p = null;
        }
        else
        {
            switch (turnPlayer)
            {
            case TurnPlayer.P1:
                if (!p2.p.hetBai && p2.p.coLuot)
                {
                    turnPlayer = TurnPlayer.P2;
                    p2.ToiLuotDanh();
                }
                else
                {
                    if (!p3.p.hetBai && p3.p.coLuot)
                    {
                        turnPlayer = TurnPlayer.P3;
                        p3.ToiLuotDanh();
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P4;
                        p4.ToiLuotDanh();
                    }
                }
                break;

            case TurnPlayer.P2:
                if (!p3.p.hetBai && p3.p.coLuot)
                {
                    turnPlayer = TurnPlayer.P3;
                    p3.ToiLuotDanh();
                }
                else
                {
                    if (!p4.p.hetBai && p4.p.coLuot)
                    {
                        turnPlayer = TurnPlayer.P4;
                        p4.ToiLuotDanh();
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P1;
                    }
                }
                break;

            case TurnPlayer.P3:
                if (!p3.p.hetBai && p4.p.coLuot)
                {
                    turnPlayer = TurnPlayer.P4;
                    p4.ToiLuotDanh();
                }
                else
                {
                    if (!p1.p.hetBai && p1.p.coLuot)
                    {
                        turnPlayer = TurnPlayer.P1;
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P2;
                        p2.ToiLuotDanh();
                    }
                }
                break;

            case TurnPlayer.P4:
                if (!p1.p.hetBai && p1.p.coLuot)
                {
                    turnPlayer = TurnPlayer.P1;
                }
                else
                {
                    if (!p2.p.hetBai && p2.p.coLuot)
                    {
                        turnPlayer = TurnPlayer.P2;
                        p2.ToiLuotDanh();
                    }
                    else
                    {
                        turnPlayer = TurnPlayer.P3;
                        p3.ToiLuotDanh();
                    }
                }
                break;
            }
        }
    }
Ejemplo n.º 8
0
 private void Awake()
 {
     Instance         = this;
     overridesOnTiles = new Override[Grid.Size, Grid.Size];
     overrideManager  = FindObjectOfType <OverridesManager>();
 }