private IEnumerator DelayDeath() { yield return(new WaitForSeconds(SelfDestructDelay)); OnGameEnded?.Invoke(false); Destroy(gameObject); }
private async Task EndGame() { if (round == MaxRounds) { OnMaxRounds?.Invoke(this, new EventArgs()); } OnGameEnded?.Invoke(this, new GameEventArgs("game-ended") { Winner = Winner }); foreach (var player in Players) { var playerUnit = Units.First(u => PlayerLookup[u.Id] == player); try { await player.GameEnded( this, Units.Where(u => u.Type == playerUnit.Type).ToArray(), Units.Where(u => u.Type != playerUnit.Type).ToArray() ); } catch { /* We don't care */ } } Spec.Active = false; }
public void TakeDamage(int damage) { if (_isInvincible || _currentHealth <= 0 && _extraPlayerLives == 0) return; if (!_isHurtSoundPlayed) { _audioSource[PlayerHitAudioSourceIndex].Play(); StartCoroutine(DelayNextHurtSound()); } _currentHealth -= damage; if (_currentHealth <= 0) { if (_extraPlayerLives > 0) { ModifyExtraLife(false, 0.5f); _currentHealth = healthBar.GetCurrentMaxValue(); } else { var manager = GameManager.GameManagerInstance; if (manager == null) return; OnChangeSpecialBgm -= manager.ChangeToSpecialBgm; OnWeaponCollected -= PlayerAttack.PlayerAttackInstance.ObtainWeapon; OnGameEnded?.Invoke(true); } } healthBar.SetValue(_currentHealth); SetBarTextValue(ref playerHpUiValue, _currentHealth.ToString(), healthBar.GetCurrentMaxValue().ToString()); }
public void HandleAction(GameAction action) { switch (action) { case GameAction.CoinFlip: OnCoinFlipped?.Invoke(this, new PlayerEventArgs(_gameState.CurrentPlayer)); break; case GameAction.PlayerMakeMove: OnPlayerBeginTurn?.Invoke(this, new PlayerEventArgs(_gameState.CurrentPlayer)); OnGetPlayerMove?.Invoke(this, new PlayerEventArgs(_gameState.CurrentPlayer)); //evaluate the move _evaluateMove(); OnPlayerEndTurn?.Invoke(this, new PlayerEventArgs(_gameState.CurrentPlayer)); break; case GameAction.GameOverCatGame: OnGameEnded?.Invoke(this, new GameStateEventArgs(_gameState)); break; case GameAction.GameOverPlayerWins: OnGameEnded?.Invoke(this, new GameStateEventArgs(_gameState)); break; } }
/// <summary> /// Checks if game has ended. If true, OnGameEnded event is invoked. /// </summary> private bool CheckIfGameHasEnded() { GameResult?mateResult = null; if (Bitboard.IsMate(Color.White)) { mateResult = GameResult.BlackWon; } else if (Bitboard.IsMate(Color.Black)) { mateResult = GameResult.WhiteWon; } else if (Bitboard.IsStalemate(Color.White) || Bitboard.IsStalemate(Color.Black) || Bitboard.IsThreefoldRepetition()) { mateResult = GameResult.Draw; } if (mateResult.HasValue) { OnGameEnded?.Invoke(this, new GameEndedEventArgs(mateResult.Value)); return(true); } return(false); }
public void addAxisDone(int x) { done.Add(x); if (isEnded()) { OnGameEnded?.Invoke(); } }
public void EndGame() { OnGameEnded?.Invoke(false); GameStarted = false; OnGameEnded = null; OnGameStarted = null; FindObjectOfType <LevelChanger>().DelayedFadeToNextLevel(sceneSwapDelay); }
/// <summary> /// This method is used by host to invoke locally event connected with match message which is sent to other players. /// Should be always runned on host client after sending any message, otherwise some of the game logic would not be runned on host game instance. /// Don't use this method when client is not a host! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="opCode"></param> /// <param name="message"></param> public void SendMatchStateMessageSelf <T>(MatchMessageType opCode, T message) where T : MatchMessage <T> { //Choosing which event should be invoked basing on opCode and firing event switch (opCode) { //GAME case MatchMessageType.MatchEnded: OnGameEnded?.Invoke(message as MatchMessageGameEnded); break; //UNITS case MatchMessageType.UnitSpawned: OnUnitSpawned?.Invoke(message as MatchMessageUnitSpawned); break; /* * case MatchMessageType.UnitMoved: * OnUnitMoved?.Invoke(message as MatchMessageUnitMoved); * break; * * case MatchMessageType.UnitAttacked: * OnUnitAttacked?.Invoke(message as MatchMessageUnitAttacked); * break; */ //SPELLS /* * case MatchMessageType.SpellActivated: * OnSpellActivated?.Invoke(message as MatchMessageSpellActivated); * break; */ //CARDS /* * case MatchMessageType.CardPlayRequest: * OnCardRequested?.Invoke(message as MatchMessageCardPlayRequest); * break; * * case MatchMessageType.CardPlayed: * OnCardPlayed?.Invoke(message as MatchMessageCardPlayed); * break; * * case MatchMessageType.CardCanceled: * OnCardCancelled?.Invoke(message as MatchMessageCardCanceled); * break; * * case MatchMessageType.StartingHand: * OnStartingHandReceived?.Invoke(message as MatchMessageStartingHand); * break; */ default: break; } }
public virtual void EndGame() { CleanupGame(); PostScore(); OnGameEndedEventArgs args = new OnGameEndedEventArgs(); OnGameEnded.Invoke(this, args); }
public void EndGame(GameObject crushedAsteroid) { _flyingParticles.SetActive(false); _player.SetActive(false); _cameraFollow.SetCameraTarget(crushedAsteroid); OnGameEnded.Invoke(); }
// End game with saving level result // used when player dies public void EndGame() { //Update holder values PlayerDataHolder.SetCoins(coinsPerLevel + PlayerDataHolder.GetCoins()); PlayerDataHolder.SetLives(lives); coinsPerLevel = 0; OnGameEnded?.Invoke(); }
/// <summary> /// Ends a game, notifying the listeners of the OnGameEnded event /// </summary> /// <param name="winner">The side that won the game</param> public void EndGame(Side winner) { if (winner != null) { games[winner]++; } OnGameEnded?.Invoke(this, board, winner); }
public void StartRound() { if (!GameEnded) { IsPlayer1Selected = true; for (int i = 0; i < Player1.UnitStacks.Count; i++) { if (GameEnded) { break; } ActionCompleted = false; GameField.SelectCell(Player1.UnitStacks[i].Cell); while (!ActionCompleted) { } } } if (!GameEnded) { IsPlayer1Selected = false; for (int i = 0; i < Player2.UnitStacks.Count; i++) { if (GameEnded) { break; } ActionCompleted = false; GameField.SelectCell(Player2.UnitStacks[i].Cell); while (!ActionCompleted) { } } } if (!GameEnded) { StartRound(); } if (!IsGameStopped) { OnGameEnded?.Invoke(); OnGameEnded = null; } }
// Events // ---------- private static void clearEventDelegates() { if (OnGameEnded == null) { return; } foreach (Delegate d in OnGameEnded.GetInvocationList()) { OnGameEnded -= (EventHandler <GameEndEventArgs>)d; } }
private void CheckGameOutcome() { foreach (var player in GameManager.Players) { var score = player.Score; if (score.Kills >= KillsToWin) { OnGameEnded?.Invoke(this, new GameOutcomeEventArgs(new GameOutcome(player, GameManager.Players.Where(p => p != player).ToList()))); } } }
void IPlayer.AddTreasure() { _playerData.Treasures++; OnTreasuresChange?.Invoke(_playerData.Treasures); DataManager.Instance.SetPlayerData(_playerData); if (_playerData.Treasures >= _playerData.TargetTreasures) { OnGameEnded?.Invoke(); } }
public void EndGame() { try { OnGameEnded?.Invoke(this, EventArgs.Empty); } catch (Exception e) { Console.WriteLine(e); } }
void GoToNextLevel() { if (GameStarted) { OnGameEnded?.Invoke(true); FindObjectOfType <LevelChanger>().DelayedFadeToNextLevel(sceneSwapDelay); GameStarted = false; OnGameEnded = null; OnGameStarted = null; //; } }
public void Initialize(PlayerData data) { Instance = this; _playerData = data; OnShovelsChange?.Invoke(_playerData.Shovels); OnTreasuresChange?.Invoke(_playerData.Treasures); if (_playerData.Treasures >= _playerData.TargetTreasures) { OnGameEnded?.Invoke(); } }
private void GameIsDone(OnGameEnded info) { if (info.HasWon) { var currentLevel = GameManager.CurrentLevel; currentLevel.IsDone = true; if (_gameManager.CurrentScore > currentLevel.Score) { currentLevel.Score = _gameManager.CurrentScore; PlayerPrefs.SetInt(UserDataFetcher.USER_LEVEL_SCORE + currentLevel.Index, currentLevel.Score); } } }
private async Task GameLoop() { while (!Grid.IsSnakeDead) { Grid.Update(_currentDirection); await Task.Delay(LoopTimeMs); if (OnGameUpdated != null) { await OnGameUpdated?.Invoke(this); } } await OnGameEnded?.Invoke(this); }
private void HandleGameEnding(object sender, GameEventArgs args) { var winner = CurrentGame.Winner; OnGameEnded?.Invoke(this, new GameEventArgs("game-ended") { Winner = winner }); if (winner != null) { winner.Score += GameConfig.GameValue; OnPlayerUpdated?.Invoke(this, new PlayerEventArgs { EventType = "player-updated", Player = winner }); } }
public override void Act() { if (finishGame) { if (Time.fixedTime > endTimer) { OnGameEnded?.Invoke(); } } if (player) { player.Act(); } map.Act(); var score = 0.1f * (1.5f - map.GetClosestPlanet()); GameController.Multiplier += (Mathf.Max(0, score)) * GameLoop.NormalizedDeltaTime; if (boss) { boss.Act(); } if (!bossBattle) { for (int i = 0; i < enemies.Count; i++) { if (enemies[i]) { enemies[i].Act(); } } } for (int i = 0; i < projectileList.Count; i++) { if (projectileList[i]) { projectileList[i].Act(); } } timeScaleEffect?.Act(); bossBattleEffect?.Act(); }
private void EndGame() { Debug.Log("[GameController] Game ended"); PieceController.OnStateChanged -= PieceController_OnChange; foreach (PieceController piece in m_pieces) { piece.Interactable = false; } SFX.Instance.PlayOneShot(SFXData.Type.Win); MainController.Instance.ShowGameEnded(); OnGameEnded?.Invoke(this, new EventArgs()); }
private void OnStateUpdatedCallback(int state) { Logger.Debug($"OnStateUpdatedCallback - state={state}"); if (state == 1) { _changedLamps = new int[PinMameApi.PinmameGetMaxLamps() * 2]; _changedGIs = new int[PinMameApi.PinmameGetMaxGIs() * 2]; OnGameStarted?.Invoke(); } else { OnGameEnded?.Invoke(); RunningGame = null; } }
private bool UpdateTime() { // Check if the game time has run out if (m_GameTimeLeft >= 0) { m_GameTimeLeft -= Time.deltaTime; return(false); } else { m_GameTimeLeft = 0.0f; OnGameEnded?.Invoke(); GameManager.Instance.EndGame(); return(true); } }
public void Move(GameData gd) { var player = GetPlayerOf(gd.NextPlayer); var move = player.ProposeMove(gd); var data = Game.TryMakeMove(gd.NextPlayer, move); UpdateOpponentState(player, data); if (data.Code != ResponseCode.OK && Game.State != GameState.GameEnded) { return; } OnMoveCompleted?.Invoke(data); if (Game.State == GameState.GameEnded) { OnGameEnded?.Invoke(data); } }
bool IPlayer.TryUseShovel() { if (_playerData.Treasures >= _playerData.TargetTreasures) { return(false); } if (_playerData.Shovels > 0) { _playerData.Shovels--; OnShovelsChange?.Invoke(_playerData.Shovels); DataManager.Instance.SetPlayerData(_playerData); return(true); } else { OnGameEnded?.Invoke(); return(false); } }
public async Task RunAuto() { var data = Game.StartGame(Team.Blue); OnGameStarted?.Invoke(data); Console.WriteLine("Runner started an auto game!"); while (Game.State != GameState.GameEnded) { Point move; if (Game.PlayerTurn == Team.Blue) { move = PlayerBlue.ProposeMove(data); PlayerRed.UpdateState(data); } else { move = PlayerRed.ProposeMove(data); PlayerBlue.UpdateState(data); } data = Game.TryMakeMove(Game.PlayerTurn, move); if (data.Code == ResponseCode.OK) { await OnMoveCompleted?.Invoke(data); } if (Game.State == GameState.GameEnded) { await OnMoveCompleted?.Invoke(data); await OnGameEnded?.Invoke(data); return; } await Task.Delay(500); } //if (data.Code == ResponseCode.Draw) // Console.WriteLine("Draw!"); //else // Console.WriteLine("{0} Lost! (Point {1})", data.NextPlayer, data.Updated); }
public async Task Move(string id, int row, int col) { if (!EnsureExists(id, out var player)) { return; } var data = Game.TryMakeMove(player.Team, new Point(col, row)); UpdateOpponentState(player, data); if (data.Code != ResponseCode.OK && Game.State != GameState.GameEnded) { return; } await OnMoveCompleted?.Invoke(data); if (Game.State == GameState.GameEnded) { await OnGameEnded?.Invoke(data); } //Move(data); }