Пример #1
0
 public void Update(MatchScoreInfo other)
 {
     if (other.score > score)
     {
         score = other.score;
     }
     if (other.time < time)
     {
         time = other.time;
     }
 }
Пример #2
0
    public void AddWin(MatchScoreInfo scoreInfo)
    {
        wins += 1;
        // determine if scoreboard already has info for given matchID
        bool found = false;

        for (var i = 0; i < scoreboard.Length; i++)
        {
            if (scoreboard[i].matchID == scoreInfo.matchID)
            {
                // update existing scoreboard w/ new match info
                scoreboard[i].Update(scoreInfo);
                found = true;
            }
        }
        // add new entry if not found
        if (!found)
        {
            Array.Resize(ref scoreboard, scoreboard.Length + 1);
            scoreboard[scoreboard.Length - 1] = scoreInfo;
        }
        Save();
    }
Пример #3
0
    IEnumerator StateFinish()
    {
        if (debug)
        {
            Debug.Log("StateFinish");
        }

        // notify channel
        if (gameEventChannel != null)
        {
            gameEventChannel.Raise(GameRecord.GameFinished());
        }

        // declare game over
        if (bannerMessage != null)
        {
            bannerMessage.Raise("Game Over!!!");
        }
        yield return(null);

        // disable bots
        for (var i = allBots.Items.Count - 1; i >= 0; i--)
        {
            allBots.Items[i].GetComponent <BotBrain>().DisableControls();
        }

        // stop match music
        if (gameInfo.matchInfo.matchMusicTrack != null)
        {
            gameInfo.matchInfo.matchMusicTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, gameInfo.matchInfo.matchMusicTrack));
        }

        // add win/loss for player
        if (winningBot == spawnedPlayer)
        {
            // create score for win
            var scoreInfo = new MatchScoreInfo();
            scoreInfo.matchID = gameInfo.matchInfo.id;
            scoreInfo.time    = timerTick;
            scoreInfo.score   = scoreKeeper.GetScore();
            gameInfo.playerInfo.AddWin(scoreInfo);

            // update scoreboard
            var json       = JsonStore.Load(JsonStore.SaveTag.Score, gameInfo.matchInfo.id);
            var scoreboard = MatchScoreboard.FromJson(json);
            if (scoreboard == null)
            {
                scoreboard = new MatchScoreboard(gameInfo.matchInfo.id);
            }
            scoreboard.AddScore(gameInfo.playerInfo.name, scoreInfo.score, scoreInfo.time);
        }
        else
        {
            gameInfo.playerInfo.AddLoss();
        }

        // start win/loss music
        if (winLossTrack != null)
        {
            winLossTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack));
        }

        // setup listener for doneConfirmed event
        var confirmed = false;
        var listener  = gameObject.AddComponent <GameEventListener>();

        listener.SetEvent(doneConfirmed);
        listener.Response.AddListener(() => { confirmed = true; });

        // instantiate modal for confirmation
        var panelGo = Instantiate(donePanelPrefab, GetCanvas().gameObject.transform);

        yield return(null);      // wait a frame for panel initialization

        // trigger event to notify player that match is complete,
        // causes confirmation modal to display message and wait for player to click ok
        var msg = System.String.Format("{0}:{1}", (winningBot == spawnedPlayer) ? "win" : "loss", gameInfo.playerInfo.name);

        wantDoneConfirm.Raise(msg);

        // wait for match info to be selected
        yield return(new WaitUntil(() => confirmed));

        if (winLossTrack != null)
        {
            winLossTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack));
        }

        // clean up, remove listener
        Destroy(panelGo);
        Destroy(listener);

        // signal that the match is done
        if (matchFinished != null)
        {
            matchFinished.Raise();
        }
    }