Пример #1
0
        /// <summary>
        /// After pseudo has been given
        /// </summary>
        /// <param name="pseudo">pseudo given by the player</param>
        private void AfterPseudoGiven(string pseudo)
        {
            PlayerPseudo = pseudo;

            //HUD
            Instantiate(hudPrefab);

            //grid
            _grid = Instantiate(gridPrefab).GetComponent <TicTacToeGrid>();

            //listen slot clicks
            _grid.Slots.ForEach(slot => slot.PlaceSymbol.Subscribe(_ => PlaceSymbolOnSlot(slot)));

            //Listen current player change to play turns
            CurrentPlayer.SkipLatestValueOnSubscribe().Subscribe(PlayTurn);

            //new game
            if (BetweenSceneData.Mode == BetweenSceneData.GameMode.NewGame)
            {
                StartGame();
            }
            //continue game
            else
            {
                ContinuePreviousGame();
            }
        }
Пример #2
0
        /// <summary>
        /// Play the CPU turn
        /// </summary>
        /// <param name="grid">the grid to play on</param>
        public static void PlayTurn(TicTacToeGrid grid)
        {
            var smartness = PlayerPrefs.GetInt("CPU Smartness", 50);
            var random    = new Random(DateTime.Now.Millisecond).Next(101);

            IPlayTurnStrategy strategy;

            if (smartness == 0)
            {
                strategy = new RandomSlotPlayTurnStrategy();
            }
            else if (random <= smartness)
            {
                strategy = new SmartPlayTurnStrategy();
            }
            else
            {
                strategy = new RandomSlotPlayTurnStrategy();
            }

            //Simulate 1s thinking
            Observable.Timer(TimeSpan.FromSeconds(1f)).Subscribe(time =>
            {
                strategy.ChooseSlot(grid).PlaceSymbol.Execute();
            });
        }