Exemplo n.º 1
0
    private IEnumerator HintRoutine(GameplayCell _hintCell)
    {
        _hintCell.ShowCellWithColor(colorConfiguration.hintColor);
        yield return(new WaitForSeconds(gameplayConfiguration.hintAvailableTime));

        _hintCell.MarkAsQuestion(colorConfiguration.hiddenBlockColor);
    }
Exemplo n.º 2
0
    private void RemoveCellFromAnswers(GameplayCell _answerCell, GameplayCell _questionCell)
    {
        m_answerCells.Remove(_answerCell);
        m_questionCells.Remove(_questionCell);

        m_feedbackUIReference.UpdateRemainingUIText(m_answerCells.Count);

        if (m_answerCells.Count == 0)
        {
            // [TO DO] Maybe the "You Won" text could be a const variable
            ShowGameOverPanel("You Won!");
        }
    }
Exemplo n.º 3
0
    private IEnumerator GiveFeedbackOnCellRoutine(GameplayCell _cell, Color _color)
    {
        // [TO DO]
        // some magic numbers here, these could be variables

        Color originalCellColor = _cell.CellColor;

        for (int i = 0; i < 3; i++)
        {
            _cell.CellColor = _color;
            yield return(new WaitForSeconds(0.1f));

            _cell.CellColor = originalCellColor;
            yield return(new WaitForSeconds(0.1f));
        }
    }
Exemplo n.º 4
0
    private void InitializeLevel()
    {
        LevelEditor.SerializableBoard boardToLoad = SerializeUtility.LoardBoardFromFile(m_levelToLoad);
        m_boardGridLayoutPanel.constraintCount = boardToLoad.boardSize;

        // Instantiating all cells
        foreach (LevelEditor.SerializableCell cell in boardToLoad.serializableGrid)
        {
            GameplayCell gameplayCell = Instantiate(gameplayCellPrefab, gridPanel.transform).GetComponent <GameplayCell>();
            gameplayCell.FetchDependencies();
            gameplayCell.Assign(cell, colorConfiguration);

            // see if it would be a hint or answer, and then do stuff...
            if (cell.cellType == (int)LevelEditor.CellScript.ECellType.Unused)
            {
                m_unusedCells.Add(gameplayCell);
            }
            else if (cell.cellStatus == (int)LevelEditor.CellScript.ECellStatus.Hidden)
            {
                gameplayCell.MarkAsQuestion(colorConfiguration.hiddenBlockColor);
                m_questionCells.Add(gameplayCell);

                // Instantiating the cell that will be shown on the answer bank and can be dragged
                GameplayCell answerCell = Instantiate(gameplayCellPrefab, solutionBank.transform).GetComponent <GameplayCell>();
                answerCell.FetchDependencies();
                answerCell.Assign(cell, colorConfiguration);

                // Adding the Drag Component and stablishing all the actions necessary
                CellDrag answerCellDragComponent = answerCell.gameObject.AddComponent <CellDrag>();
                answerCellDragComponent.OnInteractedWithCell += GiveFeedbackOnCell;
                answerCellDragComponent.OnCellWasMatched     += RemoveCellFromAnswers;

                answerCell.MarkAsAnswer();
                m_answerCells.Add(answerCell);
            }
            else if (cell.cellStatus == (int)LevelEditor.CellScript.ECellStatus.Visible)
            {
                gameplayCell.cellType = GameplayCell.ECellType.Hint;
                m_gameplayCells.Add(gameplayCell);
            }
        }

        m_feedbackUIReference.UpdateRemainingUIText(m_answerCells.Count);
    }
Exemplo n.º 5
0
    public void OnEndDrag(PointerEventData eventData)
    {
        // Raycasting to see which cells should be dealt with
        List <RaycastResult> raycastResults    = new List <RaycastResult>();
        GameplayCell         thisCell          = GetComponent <GameplayCell>();
        GameplayCell         otherCell         = null;
        GraphicRaycaster     graphicsRaycaster = FindObjectOfType <Canvas>().GetComponent <GraphicRaycaster>();

        graphicsRaycaster.Raycast(eventData, raycastResults);

        // Getting the gameplay cells from the results
        foreach (RaycastResult result in raycastResults)
        {
            GameplayCell cell = result.gameObject.GetComponent <GameplayCell>();
            if (cell != null && cell != thisCell)
            {
                otherCell = cell;
            }
        }

        if (otherCell != null && otherCell.IsQuestionCell())
        {
            if (thisCell.IsEqual(otherCell))
            {
                otherCell.MarkAsAnswered(thisCell);
                Destroy(thisCell.gameObject);

                OnInteractedWithCell?.Invoke(otherCell, true);
                OnCellWasMatched?.Invoke(thisCell, otherCell);
            }
            else
            {
                OnInteractedWithCell?.Invoke(otherCell, false);
            }
        }

        // if it is not, return the cell to the answer grid and refresh grid layout
        transform.position = m_originalPosition;
        // => Cache a reference?
        FindObjectOfType <GameplayController>().RefreshAnswersGridLayout();
    }
Exemplo n.º 6
0
    private void GiveFeedbackOnCell(GameplayCell _cell, bool _isPositive)
    {
        Color feedbackColor = _isPositive ? colorConfiguration.positiveFeedbackColor : colorConfiguration.negativeFeedbackColor;

        if (_isPositive)
        {
            m_timeRemaining += gameplayConfiguration.additionalTimeCorrectAnswer;
            m_feedbackUIReference.ShowVisualFeedbackText($"+{gameplayConfiguration.additionalTimeCorrectAnswer}", colorConfiguration.positiveFeedbackColor);
            m_soundManagerReference?.PlaySoundEffect(soundConfiguration?.positiveFeedbackClip);

            // [TO DO]
            // Play a fancy particle effect here also
        }
        else
        {
            m_timeRemaining -= gameplayConfiguration.timePenaltyWrongAnswer;
            m_feedbackUIReference.ShowVisualFeedbackText($"-{gameplayConfiguration.timePenaltyWrongAnswer}", colorConfiguration.negativeFeedbackColor);
            m_soundManagerReference?.PlaySoundEffect(soundConfiguration?.negativeFeedbackClip);
        }

        StartCoroutine(GiveFeedbackOnCellRoutine(_cell, feedbackColor));
    }
Exemplo n.º 7
0
 public bool IsEqual(GameplayCell _other)
 {
     return(m_textReference.text == _other.TextContent);
 }
Exemplo n.º 8
0
 public void MarkAsAnswered(GameplayCell _other)
 {
     cellType = ECellType.Hint;
     m_imageReference.color  = _other.CellColor;
     m_textReference.enabled = true;
 }