コード例 #1
0
ファイル: AIController.cs プロジェクト: nasa03/GwentCard
        public bool AITurn()
        {
            if (EnemyController.GetInstance().grids[1].childCount == 0)
            {
                return(true);
            }

            if (TurnController.GetInstance().turnIndex == 0)
            {
                if (TurnController.GetInstance().isTurned[0] &&
                    (PlayerController.GetInstance().grids[1].childCount >= EnemyController.GetInstance().grids[1].childCount ||
                     PowerController.GetInstance().enemy_total > PowerController.GetInstance().player_total ||
                     PowerController.GetInstance().player_total - PowerController.GetInstance().enemy_total >= 25))
                {
                    return(true);
                }
                else if (PowerController.GetInstance().enemy_total - PowerController.GetInstance().player_total >= 15 ||
                         PowerController.GetInstance().player_total - PowerController.GetInstance().enemy_total >= 25)
                {
                    return(true);
                }
            }
            if (TurnController.GetInstance().turnIndex == 1)
            {
                if (TurnController.GetInstance().isTurned[0])
                {
                    if ((int)GameOver.GetInstance().playerPowerList[0] >= (int)GameOver.GetInstance().enemyPowerList[0] &&
                        PowerController.GetInstance().enemy_total > PowerController.GetInstance().player_total)
                    {
                        return(true);
                    }
                    else if ((int)GameOver.GetInstance().enemyPowerList[0] > (int)GameOver.GetInstance().playerPowerList[0] &&
                             (PlayerController.GetInstance().grids[1].childCount >= EnemyController.GetInstance().grids[1].childCount ||
                              PowerController.GetInstance().enemy_total > PowerController.GetInstance().player_total))
                    {
                        return(true);
                    }
                }
                else if ((int)GameOver.GetInstance().playerPowerList[0] > (int)GameOver.GetInstance().enemyPowerList[0] &&
                         PowerController.GetInstance().enemy_total - PowerController.GetInstance().player_total >= 15)
                {
                    return(true);
                }
                else if ((int)GameOver.GetInstance().enemyPowerList[0] >= (int)GameOver.GetInstance().playerPowerList[0] &&
                         PowerController.GetInstance().player_total - PowerController.GetInstance().enemy_total >= 25)
                {
                    return(true);
                }
                else if (PowerController.GetInstance().enemy_total - PowerController.GetInstance().player_total >= 25)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        public void PlayOver(Transform card)
        {
            CoroutineManager.GetInstance().AddTask(TweenCard.GetInstance().Play(card));
            Number();
            PowerController.GetInstance().Number();

            if (!TurnController.GetInstance().isTurned[1])
            {
                CoroutineManager.GetInstance().AddTask(EnemyController.GetInstance().Play(EnemyController.GetInstance().grids[1]));
            }
        }
コード例 #3
0
ファイル: EnemyController.cs プロジェクト: nasa03/GwentCard
        IEnumerator PlayOver(Transform card)
        {
            StartCoroutine(LeaderController.GetInstance().EnemyTurnIndicator());
            yield return(TweenCard.GetInstance().Play(card));

            Number();
            PowerController.GetInstance().Number();
            if (TurnController.GetInstance().isTurned[0])
            {
                yield return(Play(grids[1]));
            }
        }
コード例 #4
0
ファイル: EnemyController.cs プロジェクト: nasa03/GwentCard
        public IEnumerator Play(Transform grid)
        {
            bool isTurn = AIController.GetInstance().AITurn();
            int  index  = AIController.GetInstance().AICard(grid);

            if (LeaderController.GetInstance().obj[1].GetComponent <EnemyLeaderBehavior>().IsEnabled)
            {
                LeaderController.GetInstance().obj[1].GetComponent <EnemyLeaderBehavior>().Play();
                yield return(PlayOver(LeaderController.GetInstance().obj[1].transform));

                CoroutineManager.GetInstance().Finish();
                yield break;
            }

            if (isTurn || index == -1)
            {
                yield return(TurnController.GetInstance().EnemyTurn());

                CoroutineManager.GetInstance().Finish();
                yield break;
            }

            Transform card;

            try
            {
                card = grid.GetChild(index);
            }
            catch
            {
                card = grid.GetChild(Random.Range(0, grid.childCount));
            }
            CardProperty cardProperty = card.GetComponent <CardProperty>();

            switch (cardProperty.effect)
            {
            case Global.Effect.spy:
                card.SetTarget(PlayerController.GetInstance().grids[(int)cardProperty.line + 2]);
                DrawCards(2);
                break;

            case Global.Effect.clear_sky:
                WeatherController.GetInstance().ClearSky();
                card.SetTarget(grids[5]);
                break;

            case Global.Effect.frost:
                if (!WeatherController.GetInstance().weather[0])
                {
                    WeatherController.GetInstance().Frost();
                    card.SetTarget(WeatherController.GetInstance().grid);
                    break;
                }
                else
                {
                    goto default;
                }

            case Global.Effect.fog:
                if (!WeatherController.GetInstance().weather[1])
                {
                    WeatherController.GetInstance().Fog();
                    card.SetTarget(WeatherController.GetInstance().grid);
                    break;
                }
                else
                {
                    goto default;
                }

            case Global.Effect.rain:
                if (!WeatherController.GetInstance().weather[2])
                {
                    WeatherController.GetInstance().Rain();
                    card.SetTarget(WeatherController.GetInstance().grid);
                    break;
                }
                else
                {
                    goto default;
                }

            case Global.Effect.nurse:
                if (grids[5].childCount != 0)
                {
                    card.SetTarget(grids[(int)cardProperty.line + 2]);
                    yield return(TweenCard.GetInstance().Play(card));

                    yield return(Play(grids[5]));

                    PlayerController.GetInstance().obj.SetActive(false);
                    obj.SetActive(false);
                    PlayerController.GetInstance().obj.SetActive(true);
                    obj.SetActive(true);
                    yield break;
                }
                else
                {
                    goto default;
                }

            case Global.Effect.scorch:
                int maxPower = 0;
                for (int i = 2; i < 5; i++)
                {
                    for (int ii = 0; ii < PlayerController.GetInstance().grids[i].childCount; ii++)
                    {
                        int power = PlayerController.GetInstance().grids[i].GetChild(ii).GetComponent <CardBehavior>().totalPower;
                        if (power > maxPower)
                        {
                            maxPower = power;
                        }
                    }
                }
                for (int i = 2; i < 5; i++)
                {
                    for (int ii = 0; ii < grids[i].childCount; ii++)
                    {
                        int power = grids[i].GetChild(ii).GetComponent <CardBehavior>().totalPower;
                        if (power > maxPower)
                        {
                            maxPower = power;
                        }
                    }
                }

                for (int i = 2; i < 5; i++)
                {
                    for (int ii = PlayerController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--)
                    {
                        Transform scorchCard = PlayerController.GetInstance().grids[i].GetChild(ii);
                        if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold)
                        {
                            scorchCard.SetTarget(PlayerController.GetInstance().grids[5]);
                        }
                    }
                }
                for (int i = 2; i < 5; i++)
                {
                    for (int ii = grids[i].childCount - 1; ii >= 0; ii--)
                    {
                        Transform scorchCard = grids[i].GetChild(ii);
                        if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold)
                        {
                            scorchCard.SetTarget(grids[5]);
                        }
                    }
                }
                goto default;

            case Global.Effect.dummy:
                if (grids[2].childCount == 0 &&
                    grids[3].childCount == 0 &&
                    grids[4].childCount == 0)
                {
                    card.SetTarget(grids[5]);
                    break;
                }

                int dummyGrid  = 0;
                int dummyIndex = 0;
                for (int i = 2; i < 5; i++)
                {
                    for (int ii = 0; ii < grids[i].childCount; ii++)
                    {
                        if (grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.spy ||
                            grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.nurse ||
                            grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.scorch ||
                            grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.warhorn)
                        {
                            dummyGrid  = i;
                            dummyIndex = ii;
                        }
                    }
                }
                card.SetTarget(grids[dummyGrid]);
                grids[dummyGrid].GetChild(dummyIndex).SetTarget(grid);
                break;

            case Global.Effect.warhorn:
                if (cardProperty.line == Global.Line.empty)
                {
                    if (grids[2].childCount == 0 &&
                        grids[3].childCount == 0 &&
                        grids[4].childCount == 0)
                    {
                        card.SetTarget(grids[5]);
                        break;
                    }

                    int line     = 0;
                    int maxCount = 0;
                    for (int i = 2; i < 5; i++)
                    {
                        if (grids[i].childCount >= maxCount &&
                            !WarhornController.GetInstance().enemyWarhorn[i - 2])
                        {
                            line     = i - 2;
                            maxCount = grids[i].childCount;
                        }
                    }

                    WarhornController.GetInstance().enemyWarhorn[line] = true;
                    card.SetTarget(WarhornController.GetInstance().enemyGrids[line]);
                    break;
                }
                else
                {
                    WarhornController.GetInstance().enemyWarhorn[(int)cardProperty.line] = true;
                    goto default;
                }

            case Global.Effect.muster:
                int musterIndex = 0;
                for (int i = 0; i < MusterController.GetInstance().musterCards.Length; i++)
                {
                    for (int ii = 0; ii < MusterController.GetInstance().musterCards[i].Length; ii++)
                    {
                        if (grid.GetChild(index).GetComponent <UISprite>().spriteName == MusterController.GetInstance().musterCards[i][ii])
                        {
                            musterIndex = i;
                        }
                    }
                }

                for (int i = 0; i < MusterController.GetInstance().musterCards[musterIndex].Length; i++)
                {
                    for (int ii = grids[0].childCount - 1; ii >= 0; ii--)
                    {
                        Transform musterCard = grids[0].GetChild(ii);
                        if (musterCard.GetComponent <UISprite>().spriteName == MusterController.GetInstance().musterCards[musterIndex][i])
                        {
                            musterCard.SetTarget(grids[(int)musterCard.GetComponent <CardProperty>().line + 2]);
                        }
                    }
                }

                goto default;

            case Global.Effect.agile:
                int agileIndex = 0;
                for (int i = 0; i < 2; i++)
                {
                    if (!WeatherController.GetInstance().weather[i])
                    {
                        agileIndex = i;
                    }
                }
                card.SetTarget(grids[agileIndex + 2]);
                break;

            default:
                card.SetTarget(grids[(int)cardProperty.line + 2]);
                break;
            }

            yield return(PlayOver(card));

            CoroutineManager.GetInstance().Finish();
        }
コード例 #5
0
ファイル: GameController.cs プロジェクト: nasa03/GwentCard
        public IEnumerator Turn()
        {
            TurnController.GetInstance().Clear();
            GameOver.GetInstance().AddPower(PowerController.GetInstance().player_total, PowerController.GetInstance().enemy_total);
            int          power        = PowerController.GetInstance().player_total - PowerController.GetInstance().enemy_total;
            GameBehavior gameBehavior = new GameBehavior();

            if (power > 0)
            {
                enemy_life_gem[enemy_fail].PlayForward();
                enemy_fail++;
                gameBehavior = GameBehavior.win;
            }
            else if (power < 0)
            {
                player_life_gem[player_fail].PlayForward();
                player_fail++;
                gameBehavior = GameBehavior.lose;
            }
            else if (power == 0)
            {
                if (PlayerController.GetInstance().group == Global.Group.nilfgaardian && EnemyController.GetInstance().group == Global.Group.nilfgaardian)
                {
                    player_life_gem[player_fail].PlayForward();
                    enemy_life_gem[enemy_fail].PlayForward();
                    player_fail++;
                    enemy_fail++;
                    gameBehavior = GameBehavior.dogfall;
                }
                else if (PlayerController.GetInstance().group == Global.Group.nilfgaardian)
                {
                    enemy_life_gem[enemy_fail].PlayForward();
                    enemy_fail++;
                    gameBehavior = GameBehavior.win;
                    yield return(TweenMessage.GetInstance().Play("领导牌技能发动\r\n平手时获胜"));
                }
                else if (EnemyController.GetInstance().group == Global.Group.nilfgaardian)
                {
                    player_life_gem[player_fail].PlayForward();
                    player_fail++;
                    gameBehavior = GameBehavior.lose;
                }
                else
                {
                    player_life_gem[player_fail].PlayForward();
                    enemy_life_gem[enemy_fail].PlayForward();
                    player_fail++;
                    enemy_fail++;
                    gameBehavior = GameBehavior.dogfall;
                }
            }

            if (player_fail == 2)
            {
                yield return(GameOver.GetInstance().Show(false));

                CoroutineManager.GetInstance().Finish();
                yield break;
            }
            else if (enemy_fail == 2)
            {
                yield return(GameOver.GetInstance().Show(true));

                CoroutineManager.GetInstance().Finish();
                yield break;
            }

            WeatherController.GetInstance().ClearSky();

            Transform playerMonsterCard = null;

            if (PlayerController.GetInstance().group == Global.Group.monster)
            {
                ArrayList line = new ArrayList();
                for (int i = 0; i < 3; i++)
                {
                    if (PlayerController.GetInstance().grids[i + 2].childCount != 0)
                    {
                        line.Add(i);
                    }
                }
                if (line.Count != 0)
                {
                    int randomLine  = (int)line[Random.Range(0, line.Count)];
                    int randomIndex = Random.Range(0, PlayerController.GetInstance().grids[randomLine + 2].childCount);
                    playerMonsterCard = PlayerController.GetInstance().grids[randomLine + 2].GetChild(randomIndex);
                }
            }
            Transform enemyMonsterCard = null;

            if (EnemyController.GetInstance().group == Global.Group.monster)
            {
                ArrayList line = new ArrayList();
                for (int i = 0; i < 3; i++)
                {
                    if (EnemyController.GetInstance().grids[i + 2].childCount != 0)
                    {
                        line.Add(i);
                    }
                }
                if (line.Count != 0)
                {
                    int randomLine  = (int)line[Random.Range(0, line.Count)];
                    int randomIndex = Random.Range(0, EnemyController.GetInstance().grids[randomLine + 2].childCount);
                    enemyMonsterCard = EnemyController.GetInstance().grids[randomLine + 2].GetChild(randomIndex);
                }
            }

            for (int i = 2; i < 5; i++)
            {
                for (int ii = PlayerController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--)
                {
                    PlayerController.GetInstance().grids[i].GetChild(ii).SetTarget(PlayerController.GetInstance().grids[5]);
                }
            }
            for (int i = 2; i < 5; i++)
            {
                for (int ii = EnemyController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--)
                {
                    EnemyController.GetInstance().grids[i].GetChild(ii).SetTarget(EnemyController.GetInstance().grids[5]);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (WarhornController.GetInstance().playerWarhorn[i])
                {
                    if (WarhornController.GetInstance().playerGrids[i].childCount == 1)
                    {
                        WarhornController.GetInstance().playerGrids[i].GetChild(0).SetTarget(PlayerController.GetInstance().grids[5]);
                    }
                    WarhornController.GetInstance().playerWarhorn[i] = false;
                }
                if (WarhornController.GetInstance().enemyWarhorn[i])
                {
                    if (WarhornController.GetInstance().enemyGrids[i].childCount == 1)
                    {
                        WarhornController.GetInstance().enemyGrids[i].GetChild(0).SetTarget(EnemyController.GetInstance().grids[5]);
                    }
                    WarhornController.GetInstance().enemyWarhorn[i] = false;
                }
            }

            switch (gameBehavior)
            {
            case GameBehavior.win:
                yield return(TweenMessage.GetInstance().Play("此局获胜"));

                break;

            case GameBehavior.lose:
                yield return(TweenMessage.GetInstance().Play("此局失败"));

                break;

            case GameBehavior.dogfall:
                yield return(TweenMessage.GetInstance().Play("此局平手"));

                break;
            }

            if (PlayerController.GetInstance().group == Global.Group.northern && gameBehavior == GameBehavior.win)
            {
                PlayerController.GetInstance().DrawCards(1);
                yield return(TweenMessage.GetInstance().Play("领导牌技能发动\r\n摸一张牌"));
            }
            if (EnemyController.GetInstance().group == Global.Group.northern && gameBehavior == GameBehavior.lose)
            {
                EnemyController.GetInstance().DrawCards(1);
            }
            if (PlayerController.GetInstance().group == Global.Group.monster && playerMonsterCard != null)
            {
                playerMonsterCard.SetTarget(PlayerController.GetInstance().grids[(int)playerMonsterCard.GetComponent <CardProperty>().line + 2]);
                if (playerMonsterCard.GetComponent <CardProperty>().effect == Global.Effect.warhorn)
                {
                    WarhornController.GetInstance().playerWarhorn[0] = true;
                }
                yield return(TweenMessage.GetInstance().Play("领导牌技能发动\r\n保留一张牌再战场上"));
            }
            if (EnemyController.GetInstance().group == Global.Group.monster && enemyMonsterCard != null)
            {
                enemyMonsterCard.SetTarget(EnemyController.GetInstance().grids[(int)enemyMonsterCard.GetComponent <CardProperty>().line + 2]);
                if (enemyMonsterCard.GetComponent <CardProperty>().effect == Global.Effect.warhorn)
                {
                    WarhornController.GetInstance().enemyWarhorn[0] = true;
                }
            }

            PlayerController.GetInstance().grids[5].gameObject.SetActive(false);
            PlayerController.GetInstance().grids[5].gameObject.SetActive(true);
            EnemyController.GetInstance().grids[5].gameObject.SetActive(false);
            EnemyController.GetInstance().grids[5].gameObject.SetActive(true);

            PowerController.GetInstance().Number();

            offensive = !offensive;
            if (offensive)
            {
                yield return(TweenMessage.GetInstance().Play("你先手"));

                LeaderController.GetInstance().PlayerTurnIndicator();
            }
            else
            {
                yield return(TweenMessage.GetInstance().Play("对方先手"));

                yield return(EnemyController.GetInstance().Play(EnemyController.GetInstance().grids[1]));
            }

            CoroutineManager.GetInstance().Finish();
        }