示例#1
0
        public bool HandleEvent(GameEvent gameEvent)
        {
            int playerIndex = gameEvent.PlayerIndex;

            switch (gameEvent.EventType)
            {
            case GameEvent.GameEventType.SCORING_POSITION:
            {
                if ((int)mPathBehaviors[playerIndex] < (int)PathBehavior.HasSingleConnections)
                {
                    mNumberCharactersExp[playerIndex]++;
                    // spawn from one side, and loop

                    if (playerIndex == 0)
                    {
                        if (gameEvent.WhichDomino.Controller.Row == 0 || gameEvent.WhichDomino.Controller.Row == 1)
                        {
                            mPlayer1LowerConnections = true;
                            //considered has single connection only if the path reach the holes line
                            mPathBehaviors[playerIndex] = PathBehavior.HasSingleConnections;
                        }
                        else
                        {
                            mPlayer1UpperConnections = true;
                        }
                    }
                    else
                    {
                        if (gameEvent.WhichDomino.Controller.Column == 0 || gameEvent.WhichDomino.Controller.Column == 1)
                        {
                            mPlayer2LowerConnections = true;
                            //considered has single connection only if the path reach the holes line
                            mPathBehaviors[playerIndex] = PathBehavior.HasSingleConnections;
                        }
                        else
                        {
                            mPlayer2UpperConnections = true;
                        }
                    }
                }
                else
                {
                    if (mNumberCharactersExp[playerIndex] < kMaxCharactersNullScore)
                    {
                        mNumberCharactersExp[playerIndex]++;
                    }
                }
                break;
            }

            case GameEvent.GameEventType.SCORE:
            {
                if ((mNumberCharactersExp[0] + mNumberCharactersExp[1]) < kMaxCharacters)
                {
                    mNumberCharactersExp[playerIndex] = mNumberCharactersExp[playerIndex] + 2;
                }
                else
                {
                    int scorePlayer1 = mBoardController.CalculatePlayer1Score();
                    int scorePlayer2 = mBoardController.CalculatePlayer2Score();
                    mNumberCharactersExp[0] = Math.Max((int)(kMaxCharacters * scorePlayer1 / (scorePlayer1 + scorePlayer2)), mNumberCharactersExp[0]);
                    mNumberCharactersExp[1] = Math.Max((int)(kMaxCharacters * scorePlayer2 / (scorePlayer1 + scorePlayer2)), mNumberCharactersExp[1]);
                }

                if ((int)mPathBehaviors[playerIndex] < (int)PathBehavior.HasFullConnections)
                {
                    // spawn from side to side
                    mPathBehaviors[playerIndex] = PathBehavior.HasFullConnections;
                    if (playerIndex == 0)
                    {
                        if (gameEvent.WhichDomino.Controller.Row == 0 || gameEvent.WhichDomino.Controller.Row == 1)
                        {
                            mPlayer1LowerConnections = true;
                        }
                        else
                        {
                            mPlayer1UpperConnections = true;
                        }
                    }
                    else
                    {
                        if (gameEvent.WhichDomino.Controller.Column == 0 || gameEvent.WhichDomino.Controller.Column == 1)
                        {
                            mPlayer2LowerConnections = true;
                        }
                        else
                        {
                            mPlayer2UpperConnections = true;
                        }
                    }
                }
                break;
            }

            case GameEvent.GameEventType.GAME_OVER_WIN:
            {
                mIsGameOver = true;
                List <IRoadCharacter> winChars  = (playerIndex == 0) ? mPlayer1Characters : mPlayer2Characters;
                List <IRoadCharacter> loseChars = (playerIndex == 0) ? mPlayer2Characters : mPlayer1Characters;
                foreach (IRoadCharacter character in winChars)
                {
                    character.BehaviorController.HandleEvent((int)CharacterController.CharacterEvents.To_WinDance, null);
                }
                foreach (IRoadCharacter character in loseChars)
                {
                    character.BehaviorController.HandleEvent((int)CharacterController.CharacterEvents.To_Idle, null);
                }
                break;
            }

            case GameEvent.GameEventType.GAME_OVER_LOSE:
            {
                mIsGameOver = true;
                List <IRoadCharacter> winChars  = (playerIndex == 0) ? mPlayer2Characters : mPlayer1Characters;
                List <IRoadCharacter> loseChars = (playerIndex == 0) ? mPlayer1Characters : mPlayer2Characters;
                foreach (IRoadCharacter character in winChars)
                {
                    character.BehaviorController.HandleEvent((int)CharacterController.CharacterEvents.To_WinDance, null);
                }
                foreach (IRoadCharacter character in loseChars)
                {
                    character.BehaviorController.HandleEvent((int)CharacterController.CharacterEvents.To_Lost, null);
                }
                break;
            }
            }
#if DEBUG
            if (gameEvent.EventType == GameEvent.GameEventType.TEST_SPAWN)
            {
                int targetFood = -1;
                List <IRoadCharacter> characterList = gameEvent.PlayerIndex == 0 ? mPlayer1Characters : mPlayer2Characters;
                Queue <Vec2>          path          = new Queue <Vec2>();
                BuildCharacterPath(path, mPathBehaviors[gameEvent.PlayerIndex], gameEvent.PlayerIndex, true, ref targetFood);
                IRoadCharacter character;
                character = BuildCharacter(
                    4,
                    5,
                    CardinalPoint.E,
                    0,
                    mBoardController.Size,
                    false);
                character.TargetFood = targetFood;
                characterList.Add(character);
                characterList[characterList.Count - 1].BehaviorController.SetNavigationPath(path);
            }
#endif
            return(false);
        }