Exemplo n.º 1
0
    public void AddWinnerCount(int winO, int winX)
    {
        WinnerData winnerData = new WinnerData {
            mWinO = winO, mWinX = winX
        };


        /*if(PlayerPrefs.HasKey("gameData"))
         * {
         *  WinnerData jsonCount = new WinnerData();
         *
         *  jsonCount = JsonUtility.FromJson<WinnerData>(PlayerPrefs.GetString("gameData"));
         *
         *  winnerData.mWinO += mPlayersArray[0].WinCount;
         *  winnerData.mWinX += mPlayersArray[0].WinCount;
         *
         *  //winnerData.mWinO += jsonCount.mWinO;
         *  //winnerData.mWinX += jsonCount.mWinX;
         * }*/


        string json = JsonUtility.ToJson(winnerData);

        PlayerPrefs.SetString("gameData", json);
        PlayerPrefs.Save();

        Debug.Log("Побед ноликов: " + winnerData.mWinO + " Побед крестиков: " + winnerData.mWinX);
    }
Exemplo n.º 2
0
    public void Fill(WinnerData content)
    {
        string lifeform = (content.playerList.AiPlayers.Count == 1
            ? content.playerList.AiPlayers.Count +  " lifeform"
            : content.playerList.AiPlayers.Count + " lifeforms");

        if (content.DidHumanPlayerSurvive()) {
            // domination
            // you defated
            // xx lifeforms
            Line1.text = "Domination";
            Line2.text = "You defeated";
            Line3.text = lifeform;
            Line4.text = "";
        }else{
            // extinction
            // you couldn't
            // compete with
            // xx lifeforms
            Line1.text = "Extinction";
            Line2.text = "You couldn't";
            Line3.text = "compete with";
            Line4.text = lifeform;
        }
    }
Exemplo n.º 3
0
    public WinnerData IsAWinnerCombination()
    {
        WinnerData rowData               = CheckRowCombination();
        WinnerData colData               = CheckColumnCombination();
        WinnerData mainDiagonalData      = CheckMainDiagonalCombination();
        WinnerData secondaryDiagonalData = CheckSecondaryDiagonalCombination();


        if (rowData.IsWinner)
        {
            return(rowData);
        }
        if (colData.IsWinner)
        {
            return(colData);
        }
        if (mainDiagonalData.IsWinner)
        {
            return(mainDiagonalData);
        }
        if (secondaryDiagonalData.IsWinner)
        {
            return(secondaryDiagonalData);
        }

        return(new WinnerData(CellOwner.None, false));// si no hay combinación ganadora devolvemos la que sea
    }
Exemplo n.º 4
0
    public void DeleteCount()
    {
        if (PlayerPrefs.HasKey("gameData"))
        {
            PlayerPrefs.DeleteKey("gameData");
            WinnerData winnerData = new WinnerData();
            string     json       = JsonUtility.ToJson(winnerData);
            winnerData.mWinO = 0;
            winnerData.mWinX = 0;

            PlayerPrefs.SetString("gameData", json);
            PlayerPrefs.Save();
        }
    }
Exemplo n.º 5
0
        public static async Task <WinnerData> CandidatureWinnerChart(string url)
        {
            WinnerData objData = new WinnerData();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    var result = await client.GetAsync(url);

                    var place = result.Content.ReadAsStringAsync().Result;
                    objData = JsonConvert.DeserializeObject <WinnerData>(await result.Content.ReadAsStringAsync());
                }
            }
            catch (Exception ex)
            {
            }
            return(objData);
        }
        /**
         * Retrieves the payout odds for the given type of bet.
         * return dictionary of the data
         */
        public static Dictionary <byte[], WinnerData> bestSpecialBet(List <Day> days, RetrieveHorses f)
        {
            int finalCount = 0;
            Dictionary <byte[], WinnerData> result = new Dictionary <byte[], WinnerData>(new ByteArrayComparer());

            foreach (Day day in days)
            {
                if (isValidDay(day))
                {
                    foreach (Race race in day.getRaces())
                    {
                        if (true)//race.getWeather() != "Clear")
                        {
                            RaceData rd = f(race);
                            if (rd.payoff > 0)
                            {
                                if (!result.ContainsKey(rd.winners))
                                {
                                    result.Add(rd.winners, new WinnerData()
                                    {
                                        count  = 0,
                                        payoff = rd.payoff
                                    });
                                }
                                else
                                {
                                    WinnerData old = result[rd.winners];
                                    old.count++;
                                    old.payoff        += rd.payoff;
                                    result[rd.winners] = old;
                                }
                                finalCount++;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("THIS IS THE NUMBER OF RACES: " + finalCount);
            return(result);
        }
        /**
         * Returns a dictionary containing the odds that each horse came in for the given Position over the given days.
         */
        public static Dictionary <byte, WinnerData> retrieveListForPosn(List <Day> days, RetrievePosn f)
        {
            int finalCount = 0;
            Dictionary <byte, WinnerData> result = new Dictionary <byte, WinnerData>();


            foreach (Day day in days)
            {
                if (isValidDay(day))
                {
                    foreach (Race race in day.getRaces())
                    {
                        if (race.getWinPayoff() > 0)
                        {
                            byte rank = f(race).getOddRank();
                            if (!result.ContainsKey(rank))
                            {
                                result.Add(rank, new WinnerData()
                                {
                                    count = 0, payoff = race.getWinPayoff()
                                });
                            }
                            else
                            {
                                WinnerData old = result[rank];
                                old.count++;
                                old.payoff  += race.getWinPayoff();
                                result[rank] = old;
                            }
                            finalCount++;
                        }
                    }
                }
            }
            Console.WriteLine("Total number of races: " + finalCount);
            return(result);
        }
Exemplo n.º 8
0
    protected override void AttackPhase()
    {
        float      highestDamage = -1000;
        WeaponType attackType    = WeaponType.Scissor;

        Dictionary <Player, List <CardData> > cards = new Dictionary <Player, List <CardData> >()
        {
            { pc.player, currRoundCards }
        };

        foreach (WeaponType type in Enum.GetValues(typeof(WeaponType)))
        {
            Dictionary <Player, WeaponType> pWeapon = new Dictionary <Player, WeaponType>();
            pWeapon[pc.player] = type;

            //Same weapon
            pWeapon[GameController.instance.GetOpponentPlayerType()] = type;
            WinnerData data1 = GameController.instance.SimulateRound(pWeapon, cards);
            if (data1.winner != pc.player)
            {
                data1.winnerAttDefDiff = 0;
            }

            //Opponent picks strong type
            pWeapon[GameController.instance.GetOpponentPlayerType()] = WeaponController.GetStrongType(type);
            WinnerData data2 = GameController.instance.SimulateRound(pWeapon, cards);

            //Average both scenarios
            if ((data1.winnerAttDefDiff + data2.winnerAttDefDiff) / 2 > highestDamage)
            {
                highestDamage = (data1.winnerAttDefDiff + data2.winnerAttDefDiff) / 2;
                attackType    = type;
            }
        }
        _EventBus.Publish <AttackWeaponPicked>(new AttackWeaponPicked(pc, attackType));
    }
Exemplo n.º 9
0
    public Player RegisterWinner(WinnerData winnerData)
    {
        float coins = CalculateCoins(winnerData.winnerAttDefDiff);

        if (winnerData.winner == Player.L)
        {
            GlobalVars.instance.currentStalemateStreak = 0;

            playerControllerL.score++;
            playerControllerL.coins += coins;
            _EventBus.Publish <PlayerWonRound>(new PlayerWonRound(Player.L, coins, winnerData.weaponUsed[Player.L], winnerData.weaponUsed[Player.R]));
            if (playerControllerL.score >= GlobalVars.SCORE_TO_WIN)
            {
                return(Player.L);
            }
        }
        else if (winnerData.winner == Player.R)
        {
            GlobalVars.instance.currentStalemateStreak = 0;

            playerControllerR.score++;
            playerControllerR.coins += coins;
            _EventBus.Publish <PlayerWonRound>(new PlayerWonRound(Player.R, coins, winnerData.weaponUsed[Player.L], winnerData.weaponUsed[Player.R]));
            if (playerControllerR.score >= GlobalVars.SCORE_TO_WIN)
            {
                return(Player.R);
            }
        }
        else
        {
            GlobalVars.instance.currentStalemateStreak++;

            _EventBus.Publish <PlayerWonRound>(new PlayerWonRound(Player.NaN, 0, 0, 0));
        }
        return(Player.NaN);
    }
Exemplo n.º 10
0
        private static void InitializeBoard(int size, Action callback)
        {
            SetSize(size);     // Sets Size of the console, etc.

            // Initializes the 2D Array
            var dat = new BDat[size, size];

            for (var i = 0; i < dat.GetLength(0); i++)
            {
                for (var j = 0; j < dat.GetLength(1); j++)
                {
                    var d = new BDat(j, i);

                    d.OnStateChanged += (s, g) =>
                    {
                        RenderBoard();
                    };

                    dat[i, j] = d;
                }
            }

            // Subscribe to selection changed event
            BoardData.Selection.OnVectorChange += (s, g) =>
            {
                RenderBoard();
            };

            // Set board data to dat (temp data)
            BoardData.Data = dat;

            BoardData.OnWinnerSelected += (s, g) =>
            {
                var win = new WinnerData
                {
                    Winner  = g,
                    WinTime = DateTime.Now
                };

                BoardData.Winner = win;

                //RenderBoard();
            };

            BoardData.OnPlaceChanged += (s, g) =>
            {
                // Check neighbors and check winner
                BoardData.Data.CheckNeighbors(g, 5, (i, state) =>
                {
                    var c = state.StateChar;
                    if (HighestScoreData.Data.ContainsKey(c) && HighestScoreData.Data[c] is HighestScoreData score)
                    {
                        if (score.Score > i)
                        {
                            return;
                        }

                        var tempD = new HighestScoreData
                        {
                            Score     = i,
                            Character = state
                        };
                        HighestScoreData.Data[c] = tempD;
                    }


                    if (i >= 5) // Check if any winner
                    {
                        BoardData.CallWinnerSelected(state);
                    }


                    TitleEditor.RefreshTitle();
                });


                if (!BoardData.Data.IsFilled())
                {
                    RenderBoard();
                }
            };

            // Invoke callback
            callback?.Invoke();
        }
Exemplo n.º 11
0
    public IEnumerator AnimateAttack()
    {
        print("Animating Attack");
        MenuController.instance.DoMenuStateChange("animateAttack");
        yield return(new WaitForSeconds(swapDuration / 2 + 0.1f));

        // === MOVE PHASE ===
        WeaponController weaponL = GameController.instance.playerControllerL.GetCurrentWeaponController();
        Transform        tL      = weaponL.weaponVisualObj.transform;

        LeanTween.move(tL.gameObject, new Vector3(-5, tL.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);

        WeaponController weaponR = GameController.instance.playerControllerR.GetCurrentWeaponController();
        Transform        tR      = weaponR.weaponVisualObj.transform;

        LeanTween.move(tR.gameObject, new Vector3(5, tR.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
        yield return(new WaitForSeconds(weaponFlyTime + 0.1f));

        // === APPLY CARDS PHASE ===
        CardIterator cardIt   = new CardIterator();
        BaseCard     nextCard = cardIt.GetNextCard();

        while (nextCard != null)
        {
            //DO CARDS
            nextCard.DoPreAttackAction();
            nextCard = cardIt.GetNextCard();
        }

        // === WIN PHASE ===
        WinnerData winnerData = GameController.instance.DetermineWinner();
        float      coins      = GameController.CalculateCoins(winnerData.winnerAttDefDiff);

        yield return(new WaitForSeconds(weaponPreAttack));

        Vector3 tlScale = tL.localScale;
        Vector3 tRScale = tR.localScale;

        if (winnerData.winner == Player.L)
        {
            LeanTween.move(tL.gameObject, new Vector3(0.2f, tL.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            LeanTween.move(tR.gameObject, new Vector3(0.1f, tR.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            yield return(new WaitForSeconds(weaponFlyTime - 0.3f));

            LeanTween.scale(tL.gameObject, tL.localScale * winnerScale, weaponSizeChangeTime);
            LeanTween.scale(tR.gameObject, tR.localScale * loserScale, weaponSizeChangeTime);
            LeanTween.move(tR.gameObject, new Vector3(4f, tR.position.y, 0), weaponFlyBounceBackTime).setEase(LeanTweenType.easeOutExpo);
            currMenuObj.GetComponent <AnimateAttackWindowController>().EnableWinnerText(Player.L, coins);
        }
        else if (winnerData.winner == Player.R)
        {
            LeanTween.move(tR.gameObject, new Vector3(-0.2f, tR.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            LeanTween.move(tL.gameObject, new Vector3(0.1f, tL.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            yield return(new WaitForSeconds(weaponFlyTime - 0.3f));

            LeanTween.scale(tR.gameObject, tR.localScale * winnerScale, weaponSizeChangeTime);
            LeanTween.scale(tL.gameObject, tL.localScale * loserScale, weaponSizeChangeTime);
            LeanTween.move(tL.gameObject, new Vector3(-4f, tL.position.y, 0), weaponFlyBounceBackTime).setEase(LeanTweenType.easeOutExpo);
            currMenuObj.GetComponent <AnimateAttackWindowController>().EnableWinnerText(Player.R, coins);
        }
        else
        {
            LeanTween.move(tR.gameObject, new Vector3(-0.5f, tR.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            LeanTween.move(tL.gameObject, new Vector3(0.5f, tL.position.y, 0), weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            currMenuObj.GetComponent <AnimateAttackWindowController>().EnableWinnerText(Player.NaN, coins);
        }

        Player isGameWinner = GameController.instance.RegisterWinner(winnerData);

        if (isGameWinner != Player.NaN)
        {
            // === ENG GAME PHASE ===
            winText.text    = GlobalVars.GAME_WIN_DISPLAY_TEXT[0] + isGameWinner.ToString() + GlobalVars.GAME_WIN_DISPLAY_TEXT[1];
            winText.enabled = true;
            yield return(new WaitForSeconds(winningTextDisplayTime));

            _EventBus.Publish <GameOver>(new GameOver(isGameWinner));
        }
        else
        {
            // === RESET PHASE ===
            yield return(new WaitForSeconds(winningTextDisplayTime));

            LeanTween.scale(tR.gameObject, tRScale, weaponFlyTime);
            LeanTween.scale(tL.gameObject, tlScale, weaponFlyTime);
            LeanTween.move(tL.gameObject, weaponL.weaponVisualInitPos, weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            LeanTween.move(tR.gameObject, weaponR.weaponVisualInitPos, weaponFlyTime).setEase(LeanTweenType.easeInOutExpo);
            _EventBus.Publish <GameStateOver>(new GameStateOver(GameController.instance.currState));
        }
    }