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()); }
private void on(MatchOver message) { // if message.ForfeitingPlayer > 0, the match ended in a forfeit by that player string forfeitingPlayerId = message.ForfeitingPlayer > 0 ? message.ForfeitingPlayer.ToString() : "none"; // if message.AbortingPlayer > 0, the match ended in an abort by that player string abortingPlayerId = message.AbortingPlayer > 0 ? message.AbortingPlayer.ToString() : "none"; Debug.Log("SyncGameController: On MatchOver, forfeiting player: " + forfeitingPlayerId + ", aborting player: " + abortingPlayerId); UserData.Instance.InPause = true; UserData.Instance.IsGameOver = true; ChatManager.Instance.SetChatEnabled(false); matchInfoDisplay.PlayerScore = message.PlayerScore; string winner = matchInfoDisplay.PlayerScore > matchInfoDisplay.OpponentScore ? "You Won!" : "Opponent Won!"; matchInfoDisplay.GameState = "Game Over! " + winner; matchInfoDisplay.SetInputAllowed(false); client.Disconnect(true); }
public static Offset <MatchOver> CreateMatchOver(FlatBufferBuilder builder, short opcode = 11, int playerScore = 0, int opponentScore = 0, long abortingPlayer = 0, long forfeitingPlayer = 0) { builder.StartTable(5); MatchOver.AddForfeitingPlayer(builder, forfeitingPlayer); MatchOver.AddAbortingPlayer(builder, abortingPlayer); MatchOver.AddOpponentScore(builder, opponentScore); MatchOver.AddPlayerScore(builder, playerScore); MatchOver.AddOpcode(builder, opcode); return(MatchOver.EndMatchOver(builder)); }
// 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(); }
/// <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); }
/// <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); }
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); }
public static MatchOver GetRootAsMatchOver(ByteBuffer _bb, MatchOver obj) { return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
private void Update() { if (doAbort) { doAbort = false; AbortGame(); } if (didConnectSuccessfully) { didConnectSuccessfully = false; OnConnected(); } if (doAttemptConnect) { doAttemptConnect = false; OnAttemptingReconnect(); } if (!client.IsConnected && tickCount > 0 && !UserData.Instance.IsGameOver) { matchInfoDisplay.GameState = "Disconnected"; } // Process all packets that have been received by the server thus far byte[] data; while (client.GetNextPacket(out data)) { if (UserData.Instance.IsGameOver) { return; } var packet = PacketFactory.BytesToPacket(data); var byteBuffer = new ByteBuffer(data); // Uncomment for logs containing which packet type you receive // Debug.Log("SyncGameController: Received packet: " + (Opcode)packet.Opcode); switch ((Opcode)packet.Opcode) { case Opcode.MatchSuccess: client.ResetReadTimer(); on(MatchSuccess.GetRootAsMatchSuccess(byteBuffer)); client.SetReadTimeout(2000); break; case Opcode.GameState: on(GameState.GetRootAsGameState(byteBuffer)); break; case Opcode.MatchOver: on(MatchOver.GetRootAsMatchOver(byteBuffer)); break; case Opcode.OpponentConnectionStatus: on(OpponentConnectionStatus.GetRootAsOpponentConnectionStatus(byteBuffer)); break; case Opcode.PlayerReconnected: on(PlayerReconnected.GetRootAsPlayerReconnected(byteBuffer)); break; case Opcode.OpponentPaused: on(OpponentPaused.GetRootAsOpponentPaused(byteBuffer)); break; case Opcode.OpponentResumed: on(OpponentResumed.GetRootAsOpponentResumed(byteBuffer)); break; case Opcode.Chat: on(Chat.GetRootAsChat(byteBuffer)); break; case Opcode.KeepAlive: break; default: Debug.Log("SyncGameController: Received packet with unimplemented/unsupported authcode: " + packet.Opcode); break; } } }