Beispiel #1
0
        private void NotifyAboutCheckMate(Player initiator, Player opponent, ChessPoint from, ChessPoint to)
        {
            var field = _virtualField.CloneMatrix();

            _turnColor = _turnColor.Invert();
            var winner = initiator.PlayerColor;

            var winnerGameInfo = new WcfGameInfo(
                initiator.PlayerColor,
                opponent.PlayerName,
                field.ToJaggedArray(),
                _turnColor,
                winner);

            var loserGameInfo = new WcfGameInfo(
                initiator.PlayerColor,
                opponent.PlayerName,
                field.ToJaggedArray(),
                _turnColor,
                winner);

            initiator.Callback.GameHasEnded(winnerGameInfo, from.FromBusiness(), to.FromBusiness());
            opponent.Callback.GameHasEnded(loserGameInfo, from.FromBusiness(), to.FromBusiness());

            GameEnded?.Invoke(this, EventArgs.Empty);
        }
Beispiel #2
0
 protected virtual void OnEndedGame(EventArgs e)
 {
     if (GameEnded != null)
     {
         GameEnded.Invoke(this, e);
     }
 }
Beispiel #3
0
        public Player MoveToNextPlayer()
        {
            if (stepBack || (makaoStack.TopCard == new Card(CardRank.King, CardSuit.Pike) && TopCardActive))
            {
                return(HandleStepBack());
            }

            if (playersInGame[currentPlayerIndex].Cards.Count == 0)
            {
                playersInGame.RemoveAt(currentPlayerIndex);

                if (playersInGame.Count < 2)
                {
                    GameEnded?.Invoke(this, EventArgs.Empty);
                    return(null);
                }

                currentPlayerIndex %= playersInGame.Count;
            }
            else
            {
                currentPlayerIndex = (currentPlayerIndex + 1) % playersInGame.Count;
            }

            CurrentPlayerChanged?.Invoke(this, EventArgs.Empty);

            return(CurrentPlayer);
        }
Beispiel #4
0
        private void EndGameInvoke()
        {
            var winner = Score[BoardColor.Black] > Score[BoardColor.White]
                ? BoardColor.Black : BoardColor.White;

            GameEnded?.Invoke(Score[BoardColor.Black], Score[BoardColor.White], winner);
        }
Beispiel #5
0
        public void Next()
        {
            if (_questionIndex > 0 && Enumerable.SequenceEqual(CurrentQuestion.CorrectIndexes, SelectedAnswerIndexes))
            {
                Score++;
            }

            if (Questions == null)
            {
                return;
            }

            if (Questions.Count <= _questionIndex)
            {
                GameEnded?.Invoke(this, Score);
                return;
            }

            CurrentQuestion = Questions[_questionIndex++];

            for (var i = 0; i < SelectedAnswerIndexes.Length; i++)
            {
                SelectedAnswerIndexes[i] = false;
            }

            //notificate ui, because [Reactive] works bad with array
            this.RaisePropertyChanged(nameof(SelectedAnswerIndexes));

            _isAnswering = false;
        }
Beispiel #6
0
    //

    public static void ReadGameState(GameState currentState, float remainingGameTime)
    {
        CurrentState      = currentState;
        RemainingGameTime = remainingGameTime;

        switch (CurrentState)
        {
        case GameState.Waiting:
            WaitingForGame?.Invoke();
            break;

        case GameState.Playing:
            GameActivated?.Invoke(RemainingGameTime);
            break;

        case GameState.Ended:
            GameEnded?.Invoke();
            break;

        case GameState.Restarting:
            GameRestarting?.Invoke();
            break;

        case GameState.ShuttingDown:
            ServerShuttingDown?.Invoke();
            break;
        }
    }
Beispiel #7
0
        /// <summary>
        /// Game loop.
        /// </summary>
        private void GameLoop()
        {
            Broadcast(Protocol.Type.TYPE_START);

            // Time for the client to build the interface(gui).
            Thread.Sleep(2000);

            bool end = false;

            while (!end)
            {
                Thread.Sleep((int)FramesPerMillisecond);
                Update();
                end = CheckGameEnd();
                Broadcast();
            }

            int winner          = 0;
            var lastManStanding = _Players.FirstOrDefault(p => p.Death == false);

            if (lastManStanding != null)
            {
                winner = lastManStanding.Player.Id;
            }
            else
            {
                winner = _Players.First(ep => ep.Length == _Players.Select(p => p.Length).Max()).Player.Id;
            }
#if DEBUG
            DrawStateAndSave();
#endif
            GameEnded?.Invoke(new GameEndedArguments(winner));
        }
Beispiel #8
0
 private void OnGameEnded()
 {
     if (GameEnded != null)
     {
         GameEnded.Invoke(r_GameEngine.PreviousPlayer.Name, r_GameEngine.GetPlayerScore(1), r_GameEngine.GetPlayerScore(2));
     }
 }
Beispiel #9
0
        protected void OnPlayerMoved(TicTacToePlayer player, Tuple <int, int> cell)
        {
            player.CanMove = false;

            if (this[cell] == TicTacToeCellType.Empty)
            {
                var newCells = Cells.ToArray();
                newCells[ConvertToIndex(cell.Item1, cell.Item2)] = player.CellType;
                Cells = newCells;

                var endType = CheckWin();
                if (endType != null)
                {
                    PrintSchema();
                    GameEnded?.Invoke(this, endType.Value);
                }
                else
                {
                    if (player == _player1)
                    {
                        MovePlayer(_player2);
                    }
                    else if (player == _player2)
                    {
                        MovePlayer(_player1);
                    }
                }
            }
            else
            {
                MovePlayer(player);
            }
        }
Beispiel #10
0
    private void EndGame(bool gameWon)
    {
        LevelState.End(gameWon);

        gameEndedEvent.Invoke();
        MenuManager.GoToMenu(MenuName.GameFinished);
    }
Beispiel #11
0
    private void OnUnitDestroyed(object sender, AttackEventArgs e)
    {
        (sender as Unit).gameObject.SetActive(false);
        Units.Remove(sender as Unit);
        var totalPlayersAlive = Units.Select(u => u.PlayerNumber).Distinct().ToList(); //Checking if the game is over

        //Check if game is ended
        if (totalPlayersAlive.Count == 1)
        {
            //Diasable walking anim
            modelAnim.SetBool("walk", false);

            //Clear all menu
            GameObject.Find("characterStatus").GetComponent <Animator>().SetBool("isEnable", false);
            GameObject.Find("attackAction").GetComponent <Animator>().SetBool("isEnable", false);
            GameObject.Find("mainAction").GetComponent <Animator>().SetBool("isEnable", false);

            Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => {
                //Trigger victory anim
                u.transform.Find("hero").gameObject.GetComponent <Animator>().SetTrigger("victory");
            });
            //Trigger victory scene
            GameObject.Find("victoryScene").GetComponent <Animator>().SetTrigger("victory");

            if (GameEnded != null)
            {
                GameEnded.Invoke(this, new EventArgs());
            }
        }
    }
        private IEnumerator TimerCoroutine()
        {
            while (seconds > 0)
            {
                yield return(new WaitForSeconds(1));

                seconds--;

                TimeChanged?.Invoke(seconds);
            }

            int index    = 0;
            int maxScore = 0;

            for (int i = 0; i < scores.Count; i++)
            {
                if (scores[i] > maxScore)
                {
                    maxScore = scores[i];
                    index    = i;
                }
            }

            GameEnded?.Invoke(index);
        }
Beispiel #13
0
    private bool CheckGameEnd()
    {
        switch (vc.CheckVectory(Units))
        {
        case 0:
            break;

        case 1:
            Win();
            if (GameEnded != null)
            {
                GameEnded.Invoke(this, new EventArgs());
            }
            return(true);

        case 2:
            Lose();
            if (GameEnded != null)
            {
                GameEnded.Invoke(this, new EventArgs());
            }
            return(true);
        }
        return(false);
    }
Beispiel #14
0
 private void OnGameEnded()
 {
     if (GameEnded != null)
     {
         GameEnded.Invoke(this);
     }
 }
Beispiel #15
0
        private void KickLoser(Player player)
        {
            var players = _players.ToList();

            players.Remove(player);
            var updatedPlayers = new Queue <Player>();

            foreach (var p in players)
            {
                updatedPlayers.Enqueue(p);
            }

            if (updatedPlayers.Count == 1)
            {
                GameEnded?.Invoke(this, new GameEndedEvent
                {
                    Winner = updatedPlayers.First()
                });
            }

            _players = updatedPlayers;
            PlayerKicked?.Invoke(this, new PlayerKickedEvent
            {
                Player = player
            });
        }
Beispiel #16
0
        /// <summary>
        /// 盤上に駒を配置します。
        /// ゲームがすでに終了している場合、指定した位置にすでに駒が置かれている場合は何もしません。
        /// </summary>
        /// <param name="row">配置する行</param>
        /// <param name="column">配置する列</param>
        /// <param name="player">配置する駒</param>
        public void PutPiece(int row, int column, PlayerForm player)
        {
            if (GameStatus == GameStatus.Finished)
            {
                return;
            }

            if (this.board.BoardStatuses[row, column] != PlayerForm.None)
            {
                return;
            }

            this.board.PutPiece(row, column, player);
            BoardChanged?.Invoke(this, EventArgs.Empty);
            SwitchCurrentPleyer();
            (bool isGameEnded, PlayerForm winner) = CheckIfGameEnded(BoardSize, AlignNumber);
            if (isGameEnded)
            {
                this.GameStatus = GameStatus.Finished;
            }
            this.Winner = winner;
            if (isGameEnded)
            {
                GameEnded.Invoke(this, new GameEndedEventArgs(this.Winner));
            }
        }
Beispiel #17
0
    private IEnumerator OnGameEnded(bool win)
    {
        if (GameEnded != null)
        {
            GameEnded.Invoke(this, new EventArgs());
        }
        gameEnded = true;
        SkillManager.GetInstance().skillQueue.Clear();
        Units.ForEach(u => u.gameObject.layer = 2);
        yield return(StartCoroutine(DialogManager.GetInstance().PlayFinalDialog(win)));

        if (win)
        {
            yield return(StartCoroutine(Reward()));

            UnloadLevel();
            yield return(new WaitForSeconds(2f));

            Global.GetInstance().BattleIndex++;
            Global.GetInstance().NextScene("Gal");
            //Restart();
        }
        else
        {
            GameOver();
        }
    }
Beispiel #18
0
        void OnEnable()
        {
            remainingTime  = 60;
            TimerText.text = $"{remainingTime}";
            ScoreText.text = "0";

            StartCoroutine(DelayedStart());

            IEnumerator DelayedStart()
            {
                yield return(new WaitForSeconds(0.3f));

                ReticlePrefab.gameObject.SetActive(true);

                StartCoroutine(Timer());

                IEnumerator Timer()
                {
                    while (remainingTime > 0)
                    {
                        yield return(delay);

                        remainingTime--;
                        TimerText.text = $"{remainingTime}";
                    }

                    GameEnded?.Invoke(null, null);
                }
            }
        }
Beispiel #19
0
        public void MakeMove(Cell i_Source, Cell i_Destination)
        {
            Move move = new Move(this, i_Source, i_Destination);

            if (move.Result)
            {
                i_Source.Piece.Position = new Tuple <int, int>(i_Destination.Row, i_Destination.Col);
                i_Destination.Piece     = i_Source.Piece;
                i_Source.Piece          = null;

                if (move.IsJump)
                {
                    int    inBetweenCol  = i_Destination.Col > i_Source.Col ? i_Source.Col + 1 : i_Source.Col - 1;
                    int    inBetweenRow  = i_Destination.Row > i_Source.Row ? i_Source.Row + 1 : i_Source.Row - 1;
                    IPiece pieceToRemove = m_Board.GetCell(inBetweenRow, inBetweenCol).Piece;

                    if (m_Player1.RemovePiece(pieceToRemove))
                    {
                        m_Board.GetCell(inBetweenRow, inBetweenCol).Piece = null;
                    }
                    else
                    {
                        m_Player2.RemovePiece(pieceToRemove);
                        m_Board.GetCell(inBetweenRow, inBetweenCol).Piece = null;
                    }
                }

                //isKing?
                CheckToMakeKing(i_Destination.Piece);

                MoveHaveBeenMade.Invoke();

                //is game ended?
                if (DoesGameEnded())
                {
                    GameEnded.Invoke();
                    return;
                }

                //another turn?
                if (move.IsJump)
                {
                    if (isAnotherTurn(move))
                    {
                        if (m_CurrentPlayer is PcPlayer)
                        {
                            (m_CurrentPlayer as PcPlayer).getNextMoveFromPc(this, move);
                            return;
                        }
                        else
                        {
                            //next move from human
                            return;
                        }
                    }
                }
                switchCurrentTurn();
            }
        }
        public void EndGame(Guid gameId)
        {
            var gameWrapper = GameStore[gameId];

            GameStore.Remove(gameId);

            GameEnded?.Invoke(this, new GameEndedEvent(gameId, gameWrapper.Player1, gameWrapper.Player2));
        }
        public void ChangeScore(int scorePoints)
        {
            _score += scorePoints;

            if (_score >= GlobalProperties.SCORE_TO_WIN)
            {
                GameEnded.Invoke(_score);
            }
        }
Beispiel #22
0
        public async Task GameLoop()
        {
            try
            {
                //wait for players to join
                await Task.Delay(20000);

                lock (locker)
                {
                    State = GameState.Playing;
                }
                await PrintState();

                //if no users joined the game, end it
                if (!Players.Any())
                {
                    State = GameState.Ended;
                    var end = GameEnded?.Invoke(this);
                    return;
                }
                //give 1 card to the dealer and 2 to each player
                Dealer.Cards.Add(Deck.Draw());
                foreach (var usr in Players)
                {
                    usr.Cards.Add(Deck.Draw());
                    usr.Cards.Add(Deck.Draw());

                    if (usr.GetHandValue() == 21)
                    {
                        usr.State = User.UserState.Blackjack;
                    }
                }
                //go through all users and ask them what they want to do
                foreach (var usr in Players.Where(x => !x.Done))
                {
                    while (!usr.Done)
                    {
                        _log.Info($"Waiting for {usr.DiscordUser}'s move");
                        await PromptUserMove(usr);
                    }
                }
                await PrintState();

                State = GameState.Ended;
                await Task.Delay(2500);

                _log.Info("Dealer moves");
                await DealerMoves();
                await PrintState();

                var _ = GameEnded?.Invoke(this);
            }
            catch (Exception ex)
            {
                _log.Warn(ex);
            }
        }
Beispiel #23
0
        public void DecreaseHealthCount()
        {
            if (--_currentHealthCount == 0)
            {
                GameEnded?.Invoke();
            }

            HealthCountUpdated?.Invoke(_currentHealthCount);
        }
        private void onGameEnded()
        {
            if (GameEnded != null)
            {
                bool   isaDraw = Player1.Score == Player2.Score;
                Player winner  = Player1.Score >= Player2.Score ? Player1 : Player2;

                GameEnded.Invoke(new PostGameInfo(winner, isaDraw));
            }
        }
Beispiel #25
0
 public void EndGame(IPlayer winner = null)
 {
     if (winner == null)
     {
         winner = DiceEngine.CurrentPlayer;
     }
     _is_game_alive = false;
     _timer.Enabled = false;
     GameEnded?.Invoke(this, new GameEndedEventArgs(winner));
 }
Beispiel #26
0
        private void OnUnitDestroyed(Unit unit, AttackEventArgs e)
        {
            Units.Remove(unit);
            var totalPlayersAlive = Units.Select(u => u.PlayerNumber).Distinct().Count(); //Checking if the game is over

            if (totalPlayersAlive == 1)
            {
                GameEnded?.Invoke(this);
            }
        }
 private Task EndGame(string winner)
 {
     if (debug)
     {
         Console.WriteLine($"OBSERVER: NetworkManagerClient EndGame");
     }
     SceneManager.Instance.LoadScene <EndGameScene>();
     GameEnded?.Invoke(winner);
     return(Task.CompletedTask);
 }
Beispiel #28
0
        private void TriggerEvents(bool recursive)
        {
            int originalCount = eventQueue.Count;

            // Do not use foreach as eventQueue might change
            for (int i = 0; i < (recursive ? eventQueue.Count : originalCount); i++)
            {
                // Performance is not a problem since events are rare!
                var arg = eventQueue[i];
                if (arg is GamerJoinedEventArgs)
                {
                    if (GamerJoined != null)
                    {
                        GamerJoined.Invoke(this, arg as GamerJoinedEventArgs);
                    }
                }
                else if (arg is GamerLeftEventArgs)
                {
                    if (GamerLeft != null)
                    {
                        GamerLeft.Invoke(this, arg as GamerLeftEventArgs);
                    }
                }
                else if (arg is GameStartedEventArgs)
                {
                    if (GameStarted != null)
                    {
                        GameStarted.Invoke(this, arg as GameStartedEventArgs);
                    }
                }
                else if (arg is GameEndedEventArgs)
                {
                    if (GameEnded != null)
                    {
                        GameEnded.Invoke(this, arg as GameEndedEventArgs);
                    }
                }
                else if (arg is NetworkSessionEndedEventArgs)
                {
                    if (SessionEnded != null)
                    {
                        SessionEnded.Invoke(this, arg as NetworkSessionEndedEventArgs);
                    }
                }
            }

            if (recursive)
            {
                eventQueue.Clear();
            }
            else
            {
                eventQueue.RemoveRange(0, originalCount);
            }
        }
Beispiel #29
0
    public static void TrySpendHP(int hp)
    {
        Debug.Log("Попытка нанести урон зафиксирована");
        _hp -= hp;
        if (_hp <= 0)
        {
            _hp = 0; GameEnded?.Invoke();
        }

        HpChanges?.Invoke(_hp);
    }
        private void CheckGameEnd()
        {
            List <PlayerModel> alivePlayerCollection = PlayerCollection.Where(p => p.IsAlive).ToList();

            if (alivePlayerCollection.Count <= 1)
            {
                PlayerModel winner = alivePlayerCollection.SingleOrDefault();
                isRunning = false;
                GameEnded?.Invoke(this, winner);
            }
        }