Example #1
0
    public void EndMatch()
    {
        m_matchInProgress = false;
        Time.timeScale    = 0.0f;
        m_matchTimer      = 0.0f;

        // Damage given
        result_agent0.damageGiven = behave_agent1.TotalDamageTaken;
        result_agent1.damageGiven = behave_agent0.TotalDamageTaken;

        // Healthscore
        result_agent0.healthRemaining =
            behave_agent0.Health + behave_agent0.TotalDamageHealed;

        if (result_agent0.healthRemaining < 0)
        {
            result_agent0.healthRemaining = 0;
        }

        result_agent1.healthRemaining =
            behave_agent1.Health + behave_agent1.TotalDamageHealed;

        if (result_agent1.healthRemaining < 0)
        {
            result_agent1.healthRemaining = 0;
        }


        // Set who won If both win => draw? GA determines.
        result_agent0.winner = behave_agent0.StateOfAgent != ShooterAgent.AgentState.dead;
        result_agent1.winner = behave_agent1.StateOfAgent != ShooterAgent.AgentState.dead;
        // Invoke that a match is over.
        MatchOver.Invoke(this, new EventArgs());
    }
    // Method for invoking the MatchOver event
    private void OnMatchOver()
    {
        // Send a message to the UI with the match result
        view.SubmitMessage(string.Format("Game Over, {0}",
                                         Result == Winner.Draw
                ? "it's a draw"
                : $"{PlrNameColor(Result.ToPColor())} won"));

        // Set internal matchOver variable to true; this will stop further
        // Update()s
        matchOver = true;

        // Notify MatchOver listeners
        MatchOver?.Invoke();
    }
Example #3
0
        /// <summary>
        /// Отметить указанную клетку. Если после этого хода игра была закончена, то вызывается событие GameOver
        /// </summary>
        /// <param name="row">Строка</param>
        /// <param name="col">Колонка</param>
        /// <param name="mark">Отметка</param>
        /// <returns>Возвращает true, если клетка была отмечена</returns>
        /// <seealso cref="MatchOver"/>
        public bool SetMark(int row, int col, MarkType mark)
        {
            if (this.state[GetIndex(row, col)] != MarkType.None)
            {
                return(false);
            }

            this.state[GetIndex(row, col)] = mark;
            countMoves++;

            if (CheckCombinations(row, col))
            {
                MatchOver?.Invoke(this, new GameOverEventArgs(mark));
            }
            else if (countMoves == state.Length)
            {
                MatchOver?.Invoke(this, new GameOverEventArgs(MarkType.None));
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Runs the match.
        /// </summary>
        /// <returns>The match result.</returns>
        public Winner Run()
        {
            // Initially there's no winner
            Winner winner = Winner.None;

            // Notify listeners match is about to start
            MatchStart?.Invoke(
                matchConfig,
                new string[] {
                matchData.GetThinker(PColor.White).ToString(),
                matchData.GetThinker(PColor.Red).ToString()
            });

            // Notify listeners that we have a new empty board
            BoardUpdate?.Invoke(board);

            // Game loop
            while (true)
            {
                // Next player plays
                winner = Play();
                // Break loop if a winner is found
                if (winner != Winner.None)
                {
                    break;
                }
            }

            // Notify listeners that match is over
            MatchOver?.Invoke(
                winner,
                solution,
                new string[] {
                matchData.GetThinker(PColor.White).ToString(),
                matchData.GetThinker(PColor.Red).ToString()
            });

            // Return match result
            return(winner);
        }
Example #5
0
    void AddScore(Players playerID)
    {
        if (playerID == Players.player1)
        {
            PlayerOneScore += scorePerPot;
            whitePotted++;
        }
        else
        {
            blackPotted++;
            PlayerTwoScore += scorePerPot;
        }

        if (whitePotted == GameManager.instance.GettotalPieces)
        {
            MatchOver?.Invoke((int)Players.player1);
        }
        else if (blackPotted == GameManager.instance.GettotalPieces)
        {
            MatchOver?.Invoke((int)Players.player2);
        }
    }
 protected virtual void OnMatchOver()
 {
     MatchOver?.Invoke(this, EventArgs.Empty);
 }