public void OnEvent(EventTypesEnum eventTypeEnum, object messageData)
        {
            switch (eventTypeEnum)
            {
            case EventTypesEnum.LMB_Down:
                _clickA = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                break;

            case EventTypesEnum.LMB_Up:
                _clickB = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                if (_gameStateEnum == GameStatesEnum.Ready)
                {
                    if (_clickA.x >= 0 && _clickA.x < _board.Width && _clickA.y >= 0 && _clickA.y < _board.Height &&
                        (Mathf.Abs(_clickB.x - _clickA.x) > Strings.SWIPE_SENSITIVITY ||
                         Mathf.Abs(_clickB.y - _clickA.y) > Strings.SWIPE_SENSITIVITY))
                    {
                        MoveDirectionTypesEnum swipeDirection = Helper.FindMoveDirection(_clickA, _clickB);
                        SwipeCells(swipeDirection);
                    }
                }

                break;

            case EventTypesEnum.Swipe:
                _gameStateEnum = GameStatesEnum.Wait;

                SetMacroCommand((ICommand[])messageData);
                ExecuteMacroCommand();
                break;

            case EventTypesEnum.BOARD_collapse:
                ExecuteMacroCommand();
                break;

            case EventTypesEnum.BOARD_EndDestroyMatchedCells:
                if (_powersDictionary.Count > 0)
                {
                    Vector2          pos             = _powersDictionary.First().Key;
                    PowerUpTypesEnum powerUpTypeEnum = _powersDictionary.First().Value;

                    List <ICell> cellsList = new List <ICell>(_checkManager.PowerCheck(powerUpTypeEnum, pos));
                    ICell        cell      = _board.Cells[(int)pos.x, (int)pos.y];

                    _matchedCellsDictionary.Add(cellsList, AxisTypesEnum.Undefined);
                    _matchedCellsWithAxisDictionary.Add(cell, _matchedCellsDictionary);

                    _powersDictionary.Remove(_powersDictionary.First());

                    StartCoroutine(MarkAndDestroy(_matchedCellsWithAxisDictionary));
                }
                else
                {
                    StartCoroutine(RefillBoard());
                }

                break;

            case EventTypesEnum.CELL_EndMove:
                TryCheckSwipedCells((ICell)messageData);
                break;

            case EventTypesEnum.CELL_EndMoveBack:
                ICell cellBack = (ICell)messageData;

                _board.Cells[cellBack.TargetX, cellBack.TargetY] = cellBack;
                cellBack.CellStateEnum = CellStatesEnum.Wait;

                _gameStateEnum = GameStatesEnum.Ready;
                break;

            case EventTypesEnum.CELL_Fall:
                ICell cellFall = (ICell)messageData;

                cellFall.CellStateEnum = CellStatesEnum.Wait;

                if (cellFall == _lastFallCell)
                {
                    CheckBoard();
                }
                break;

            case EventTypesEnum.CELL_Destroy:
                string cellTag = (string)messageData;
                Notify(EventTypesEnum.CELL_Destroy, cellTag);
                break;

            case EventTypesEnum.POWER_Use:
                ArrayList arr = (ArrayList)messageData;

                PowerUpTypesEnum powerUp  = Helper.StringToPowerType(arr[0].ToString());
                Vector3          position = (Vector3)arr[1];

                _powersDictionary.Add(position, powerUp);
                break;

            case EventTypesEnum.TASK_Finished:
                if (_gameStateEnum != GameStatesEnum.End)
                {
                    _navigationManager.MasterManager.UpdateManager.IsUpdate = false;
                    _gameStateEnum = GameStatesEnum.End;
                    Notify(EventTypesEnum.TASK_Finished, null);
                }
                break;

            default:
                Debug.Log("EVENT NOT FOUND");
                break;
            }
        }
예제 #2
0
        public void OnEvent(EventTypes eventType, object messageData)
        {
            switch (eventType)
            {
            case EventTypes.LMB_Down:
                _clickA = (Vector3)messageData;
                break;

            case EventTypes.LMB_Up:
                _clickB = (Vector3)messageData;

                if (_gameState == GameStates.Ready)
                {
                    if (_clickA.x >= 0 && _clickA.x < _board.Width && _clickA.y >= 0 && _clickA.y < _board.Height &&
                        (Mathf.Abs(_clickB.x - _clickA.x) > StringsAndConst.SWIPE_SENSITIVITY ||
                         Mathf.Abs(_clickB.y - _clickA.y) > StringsAndConst.SWIPE_SENSITIVITY))
                    {
                        MoveDirectionTypes swipeDirection = Helper.FindMoveDirection(_clickA, _clickB);
                        SwipeCells(swipeDirection);
                    }
                }

                break;

            case EventTypes.Swipe:
                _gameState = GameStates.Wait;
                ExecuteMacroCommand();
                break;

            case EventTypes.CELL_EndMove:
                TryCheckSwipedCells((ICell)messageData);
                break;

            case EventTypes.CELL_EndMoveBack:
                ICell cellBack = (ICell)messageData;

                _board.Cells[cellBack.TargetX, cellBack.TargetY] = cellBack;
                cellBack.CellState = CellStates.Wait;

                _gameState = GameStates.Ready;
                break;

            case EventTypes.CELL_Fall:
                ICell cellFall = (ICell)messageData;

                cellFall.CellState = CellStates.Wait;

                if (cellFall == _lastFallCell)
                {
                    CheckBoard();
                }

                break;

            case EventTypes.POWER_Use:
                ArrayList arr = (ArrayList)messageData;

                PowerUpTypes powerUp  = Helper.StringToPowerType(arr[0].ToString());
                Vector3      position = (Vector3)arr[1];

                _powersDictionary.Add(position, powerUp);

                break;

            case EventTypes.BOARD_Collapse:
                ExecuteMacroCommand();
                break;

            case EventTypes.BOARD_EndDestroyMatchedCells:
                if (_powersDictionary.Count > 0)
                {
                    _hasPowerUps = true;
                }

                if (_hasPowerUps)
                {
                    foreach (var power in _powersDictionary)
                    {
                        Vector2      pos         = power.Key;
                        PowerUpTypes powerUpType = power.Value;

                        if (powerUpType == PowerUpTypes.Gravity)
                        {
                            _reverseGravity = !_reverseGravity;
                        }

                        List <ICell> cellsList = new List <ICell>(_checkManager.PowerCheck(powerUpType, pos));
                        ICell        cell      = _board.Cells[(int)pos.x, (int)pos.y];

                        if (_matchedCellsDictionary.ContainsKey(cell) == false)
                        {
                            _matchedCellsDictionary.Add(cell, cellsList);
                        }
                    }

                    _powersDictionary.Clear();
                    _hasPowerUps = false;

                    StartCoroutine(DestroyMatchedCells(_matchedCellsDictionary));
                }
                else
                {
                    StartCoroutine(RefillBoard());
                }

                break;

            default:
                Debug.Log(StringsAndConst.EVENT_NOT_FOUND);
                break;
            }
        }