private bool TryMatching(BaseMathchingStategy strategy = null) { if (strategy == null) { strategy = _standartMatchingStategy; } return(strategy.TryMatch(_field, null, null)); }
private void Start() { _field = new FieldBuilder().BuildField(_fieldGameobject, _fieldModel); _pool.Initialize(_levelModel); if (_mainCamera == null) { _mainCamera = Camera.main; } StartCoroutine(FillInTheLevel()); _currentMatchingStrategy = _standartMatchingStategy; }
private void Update() { //Wait until level filling ends if (_levelIsFilling) { return; } //Wait until switching animation ends if (_firstTile != null && _secondTile != null) { if (_firstTile.Element.IsAnimating || _secondTile.Element.IsAnimating) { return; } } //Perform matching if (_currentMatchingStrategy != null) { if (TryMatching(_currentMatchingStrategy)) { //Forget previous move _firstTile = null; _secondTile = null; StartCoroutine(FillInTheLevel()); return; } else { //Undo last move if (_firstTile != null && _secondTile != null) { SwitchElements(_firstTile, _secondTile); } _currentMatchingStrategy = null; return; } } // if there is no animations get user interaction if (Input.GetMouseButtonDown(0)) { var mousePosition = Input.mousePosition; mousePosition = _mainCamera.ScreenToWorldPoint(mousePosition); mousePosition.z = -1.0f; Physics.Raycast(mousePosition, new Vector3(0, 0, 1), out _hit, _tileLayers); if (_hit.transform != null) { var hitTile = _hit.transform.GetComponent <TileController> (); if (hitTile != null) { if (_firstTile == null) { _firstTile = hitTile; _firstTile.Element.IsSelected = true; } else { _secondTile = hitTile; _secondTile.Element.IsSelected = true; //Deselect item if (_secondTile == _firstTile) { _secondTile = null; _firstTile.Element.IsSelected = false; _firstTile = null; } } //Switch pair selected - perform switch if (_firstTile != null && _secondTile != null) { _firstTile.Element.IsSelected = false; _secondTile.Element.IsSelected = false; SwitchElements(_firstTile, _secondTile); _currentMatchingStrategy = _firstTile.Element.Model.Strategy; if (_currentMatchingStrategy == null) { _currentMatchingStrategy = _standartMatchingStategy; } } } } } }