Esempio n. 1
0
        public AIBattle(BattleViewer battleViewer, AIType aiType)
            : base(battleViewer)
        {
            int[] aiTeamIDs;

            var kernelPlayer1 = new Player(0);
            var kernelPlayer2 = new Player(1);

            HumanPlayer = new LocalPlayer(battleViewer, kernelPlayer1, this, GameManager.Instance.UserName);
            AiPlayer    = CreateAI(aiType, battleViewer, kernelPlayer2, this, out aiTeamIDs);

            IEnumerable <GameObject> humanTeam;
            IEnumerable <Position>   coords;
            IEnumerable <Position>   flippedCoords;
            IEnumerable <GameObject> aiTeam = ClientFruitonFactory.CreateClientFruitonTeam(aiTeamIDs, battleViewer.Board);

            if (aiType == AIType.Tutorial)
            {
                int[] humanTeamIDs = { 2, 5, 15, 14, 12, 17, 21, 21, 30, 25 };
                humanTeam = ClientFruitonFactory.CreateClientFruitonTeam(humanTeamIDs, battleViewer.Board);
                coords    = Tutorial.CreatePositionsForArtificialTeam(humanTeam.Select(gameObject =>
                                                                                       gameObject.GetComponent <ClientFruiton>().KernelFruiton));
            }
            else
            {
                humanTeam = ClientFruitonFactory.CreateClientFruitonTeam(gameManager.CurrentFruitonTeam.FruitonIDs, battleViewer.Board);
                coords    = gameManager.CurrentFruitonTeam.Positions;
            }
            battleViewer.InitializeTeam(humanTeam, kernelPlayer1, kernelPlayer1.id == 0, coords.ToArray());
            flippedCoords = BattleHelper.FlipCoordinates(coords, GameState.WIDTH, GameState.HEIGHT);
            battleViewer.InitializeTeam(aiTeam, kernelPlayer2, kernelPlayer2.id == 0, flippedCoords.ToArray());

            var fruitons = new Array <object>();

            foreach (var fruiton in humanTeam)
            {
                fruitons.push(fruiton.GetComponent <ClientFruiton>().KernelFruiton);
            }
            foreach (var fruiton in aiTeam)
            {
                fruitons.push(fruiton.GetComponent <ClientFruiton>().KernelFruiton);
            }

            Array <int>  maps           = GameManager.Instance.FruitonDatabase.getMapsIds();
            int          rndMapId       = maps[Random.Range(0, maps.length)];
            GameSettings kernelSettings = GameSettingsFactory.CreateGameSettings(rndMapId, battleViewer.GameMode);

            bool infiniteTurnTime = battleViewer.battleType == BattleType.TutorialBattle;

            Kernel = new Kernel(kernelPlayer1, kernelPlayer2, fruitons, kernelSettings, false, infiniteTurnTime);
            BattleReady();
        }
Esempio n. 2
0
        public OfflineBattle(BattleViewer battleViewer) : base(battleViewer)
        {
            var    kernelPlayer1 = new Player(0);
            var    kernelPlayer2 = new Player(1);
            string login         = GameManager.Instance.UserName;

            Player1 = new LocalPlayer(battleViewer, kernelPlayer1, this, "Player 1");
            Player2 = new LocalPlayer(battleViewer, kernelPlayer2, this, "Player 2");

            IEnumerable <GameObject> currentTeam  = ClientFruitonFactory.CreateClientFruitonTeam(gameManager.CurrentFruitonTeam.FruitonIDs, battleViewer.Board);
            IEnumerable <GameObject> opponentTeam = ClientFruitonFactory.CreateClientFruitonTeam(gameManager.OfflineOpponentTeam.FruitonIDs, battleViewer.Board);

            RepeatedField <Position> coords = gameManager.CurrentFruitonTeam.Positions;

            battleViewer.InitializeTeam(currentTeam, kernelPlayer1, kernelPlayer1.id == 0, coords.ToArray());
            RepeatedField <Position> flippedCoords = BattleHelper.FlipCoordinates(coords, GameState.WIDTH, GameState.HEIGHT);

            battleViewer.InitializeTeam(opponentTeam, kernelPlayer2, kernelPlayer2.id == 0, flippedCoords.ToArray());

            var fruitons = new Array <object>();

            foreach (var fruiton in currentTeam)
            {
                fruitons.push(fruiton.GetComponent <ClientFruiton>().KernelFruiton);
            }
            foreach (var fruiton in opponentTeam)
            {
                fruitons.push(fruiton.GetComponent <ClientFruiton>().KernelFruiton);
            }

            Array <int>  maps           = GameManager.Instance.FruitonDatabase.getMapsIds();
            int          rndMapId       = maps[Random.Range(0, maps.length)];
            GameSettings kernelSettings = GameSettingsFactory.CreateGameSettings(rndMapId, battleViewer.GameMode);

            Kernel = new Kernel(kernelPlayer1, kernelPlayer2, fruitons, kernelSettings, false, false);
            BattleReady();
        }