Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
    public void FinishEvaluationStage()
    {
        currentWord          = "";
        _inputString         = "";
        drawingWordCountdown = limitTimeDrawingWord;

        isInEvaluationStage = false;
        isWatchingWord      = false;
        isDrawingWord       = false;

        if (onLetterInputCallback != null)
        {
            onLetterInputCallback.Invoke(currentWord);
        }

        if (IsGameOver())
        {
            isGameOver = true;
            if (onGameEndedCallback != null)
            {
                onGameEndedCallback.Invoke();
            }
        }

        if (onDrawingCountdownFinishedCallback != null)
        {
            onDrawingCountdownFinishedCallback.Invoke();
        }
    }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        private IEnumerator DelayDeath()
        {
            yield return(new WaitForSeconds(SelfDestructDelay));

            OnGameEnded?.Invoke(false);
            Destroy(gameObject);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
 public void addAxisDone(int x)
 {
     done.Add(x);
     if (isEnded())
     {
         OnGameEnded?.Invoke();
     }
 }
Exemplo n.º 8
0
 public void EndGame()
 {
     OnGameEnded?.Invoke(false);
     GameStarted   = false;
     OnGameEnded   = null;
     OnGameStarted = null;
     FindObjectOfType <LevelChanger>().DelayedFadeToNextLevel(sceneSwapDelay);
 }
Exemplo n.º 9
0
        /// <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;
            }
        }
Exemplo n.º 10
0
    public virtual void EndGame()
    {
        CleanupGame();
        PostScore();

        OnGameEndedEventArgs args = new OnGameEndedEventArgs();

        OnGameEnded.Invoke(this, args);
    }
Exemplo n.º 11
0
    public void EndGame(GameObject crushedAsteroid)
    {
        _flyingParticles.SetActive(false);
        _player.SetActive(false);

        _cameraFollow.SetCameraTarget(crushedAsteroid);

        OnGameEnded.Invoke();
    }
Exemplo n.º 12
0
    // 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();
    }
Exemplo n.º 13
0
    /// <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);
    }
Exemplo n.º 14
0
        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;
            }
        }
Exemplo n.º 15
0
 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())));
         }
     }
 }
Exemplo n.º 16
0
 public void EndGame()
 {
     try
     {
         OnGameEnded?.Invoke(this, EventArgs.Empty);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemplo n.º 17
0
        void IPlayer.AddTreasure()
        {
            _playerData.Treasures++;
            OnTreasuresChange?.Invoke(_playerData.Treasures);
            DataManager.Instance.SetPlayerData(_playerData);

            if (_playerData.Treasures >= _playerData.TargetTreasures)
            {
                OnGameEnded?.Invoke();
            }
        }
Exemplo n.º 18
0
 void GoToNextLevel()
 {
     if (GameStarted)
     {
         OnGameEnded?.Invoke(true);
         FindObjectOfType <LevelChanger>().DelayedFadeToNextLevel(sceneSwapDelay);
         GameStarted   = false;
         OnGameEnded   = null;
         OnGameStarted = null;
         //;
     }
 }
Exemplo n.º 19
0
        public void Initialize(PlayerData data)
        {
            Instance    = this;
            _playerData = data;

            OnShovelsChange?.Invoke(_playerData.Shovels);
            OnTreasuresChange?.Invoke(_playerData.Treasures);

            if (_playerData.Treasures >= _playerData.TargetTreasures)
            {
                OnGameEnded?.Invoke();
            }
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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
                });
            }
        }
Exemplo n.º 22
0
        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();
        }
Exemplo n.º 23
0
    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());
    }
Exemplo n.º 24
0
        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;
            }
        }
Exemplo n.º 25
0
    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);
        }
    }
Exemplo n.º 26
0
        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);
            }
        }
Exemplo n.º 27
0
        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);
            }
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
    IEnumerator SpawningCoroutine()
    {
        timeRemain     = settings.playTime;
        Time.timeScale = 1;
        OnGameStarted?.Invoke(timeRemain);
        float spawnTime = 0;

        while (timeRemain > 0)
        {
            timeRemain -= Time.deltaTime;
            spawnTime  += Time.deltaTime;
            if (spawnTime > settings.ballCreatingFrequency)
            {
                spawnTime = 0;
                CreateBall();
            }

            yield return(null);
        }

        Time.timeScale = Mathf.Epsilon;
        OnGameEnded?.Invoke();
    }