예제 #1
0
    private void _HandleActivateTileEvent(DiceGame.ActivateTileEvent activateTileEvent)
    {
        Debug.LogFormat("_HandleActivateTileEvent");
        activateTileEvent.shootVictimList.ForEach(shootVictimInfo => _ShootVictim(shootVictimInfo));

        if (activateTileEvent.removePipsInfo != null)
        {
            _RemovePips(activateTileEvent.removePipsInfo);
        }

        _pendingScore = activateTileEvent.score;
    }
예제 #2
0
        void IGameAction.Execute(GameState state, EventHandler eventHandler)
        {
            ActivateTileEvent activateTileEvent = new ActivateTileEvent();

            activateTileEvent.score = 0;

            string tileChosen = state[this._col, this._row];

            char [,] pattern = this._GetPattern(tileChosen);

            Trace.WriteLine(String.Format("Activate {0} at {1},{2}", tileChosen, this._col, this._row));
            Trace.WriteLine(_PatternAsString(pattern));

            // Multipliers (2x, 3x, ...)
            //   If you activate a die that shoots another die and the victim is the same die type as the shooter then
            //   you get a multiplier (2x), hit another in the same activation (3x), etc...
            //
            //   Hitting a multiplier on an activation does what you expect, it multiplies the score you get on that
            //   activation.  Beware, hitting ONLY multipliers gets ZERO pts.
            int currentMultiplier = 2;
            int scoreMultiplier   = 1;

            //
            // Destroy tiles based on pattern
            char multiplierTestChar = state[this._col, this._row][0];

            for (int col = 0; col < pattern.GetLength(0); ++col)
            {
                for (int row = 0; row < pattern.GetLength(1); ++row)
                {
                    if (pattern[col, row] == 'x')
                    {
                        int boardPosCol = this._col + (col - 1);
                        int boardPosRow = this._row + (row - 1);

                        if (boardPosCol >= 0 && boardPosCol < state.width && boardPosRow >= 0 && boardPosRow < state.height)
                        {
                            bool isSelf = (this._col == boardPosCol && this._row == boardPosRow);

                            // Only test first char, a '6' is a '6' regardless of orientation...
                            if (!isSelf && multiplierTestChar == state[boardPosCol, boardPosRow][0])
                            {
                                // "x" needs to go first to avoid matching this if-check on next pip hit...
                                state[boardPosCol, boardPosRow] = "x" + currentMultiplier.ToString();
                                ++currentMultiplier;
                            }
                            else
                            {
                                char scoreChar = state[boardPosCol, boardPosRow][0];
                                if (Char.IsNumber(scoreChar))
                                {
                                    int scoreCharAsInt = scoreChar - '0';
                                    activateTileEvent.score += scoreCharAsInt * 10;
                                }
                                else if (scoreChar == 'x')
                                {
                                    char multiplierChar      = state[boardPosCol, boardPosRow][1];
                                    int  multiplierCharAsInt = multiplierChar - '0';
                                    scoreMultiplier *= multiplierCharAsInt;
                                }

                                state[boardPosCol, boardPosRow] = "e"; // Empty
                            }

                            if (eventHandler != null)
                            {
                                activateTileEvent.shootVictimList.Add(new ActivateTileEvent.ShootVictimInfo(this._col, this._row, boardPosCol, boardPosRow));
                            }
                        }
                    }
                }
            }

            //
            // Deal with a blank die.  This happens when tileChosen returns a pattern of '-' for the center
            if (pattern[1, 1] == '-')
            {
                char scoreChar = state[this._col, this._row][0];
                if (Char.IsNumber(scoreChar))
                {
                    int scoreCharAsInt = scoreChar - '0';
                    activateTileEvent.score += scoreCharAsInt * 10;
                }

                state[this._col, this._row] = "b"; // Blank

                if (eventHandler != null)
                {
                    activateTileEvent.removePipsInfo = new ActivateTileEvent.RemovePipsInfo(this._col, this._row);
                }
            }

            activateTileEvent.score *= scoreMultiplier;
            eventHandler(this, activateTileEvent);
        }