Exemple #1
0
    /// <summary>Checks each element on the board for matches and flags them</summary>
    public int CheckBoardForMatches()
    {
        AlexDebugger.GetInstance().AddMessage("Checking board for new matches...", AlexDebugger.tags.Aftermatch);
        int totalMatches = 0;

        // Search for matches and flag them
        for (int row = 0; row < elementsPositions.GetLength(1); row++)
        {
            for (int collum = 0; collum < elementsPositions.GetLength(0); collum++)
            {
                // case of cash element has reached bottom
                if (row == elementsPositions.GetLength(1) - 1 && elementsPositions[collum, row].GetElementClassType() == typeof(CashBoardElement))
                {
                    matchedElemPositions[collum, row] = true;
                    AlexDebugger.GetInstance().AddMessage("A cash element has reached bottom at position: " + collum + ", " + row, AlexDebugger.tags.Aftermatch);
                    totalMatches++;
                }
                else if (matchedElemPositions[collum, row] == true || !changedPotitions[collum, row])
                {
                    continue;
                }
                else
                {
                    totalMatches += BoardFunctions.CheckElementForMatches(collum, row, elementsPositions, ref matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows, true);
                }
            }
        }
        return(totalMatches);
    }
Exemple #2
0
    private bool PlayEffectsStep()
    {
        BoardElement lastElementProcessed   = secondElement;
        bool         areThereChangesOnBoard = false;

        for (int row = 0; row < elementsPositions.GetLength(1); row++)
        {
            for (int collum = 0; collum < elementsPositions.GetLength(0); collum++)
            {
                if (matchedElemPositions[collum, row] == true)
                {
                    BoardFunctions.PlayMatchEffectAnimations(collum, row, this);
                    if (BoardFunctions.DestroyBoardElement(collum, row, this, lastElementProcessed))
                    {
                        areThereChangesOnBoard = true;
                    }
                }
                lastElementProcessed = elementsPositions[collum, row];
                BoardFunctions.ToggleHighlightCell(collum, row, this, false);
            }
        }

        if (!areThereChangesOnBoard)
        {
            AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, go to Step3: -reorient elements- " + messagesToClient.Count, AlexDebugger.tags.Step2);
            return(true);
        }
        else
        {
            AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, new elements has been destroyed, repeating step ", AlexDebugger.tags.Step2);
            return(false);
        }
    }
Exemple #3
0
 public static AlexDebugger GetInstance()
 {
     if (instance == null)
     {
         AlexDebugger obj = (AlexDebugger)Resources.Load(pathToDB, typeof(AlexDebugger));
         if (obj == null)
         {
             Debug.LogError("No asset AlexDebugger found");
         }
         else if (obj is AlexDebugger)
         {
             instance = (AlexDebugger)obj;
         }
     }
     return(instance);
 }
Exemple #4
0
    public bool HandleInputForElement(BoardElement element, BoardElement otherElement)
    {
        bool areThereMatches = false;

        if (element.GetElementClassType() == typeof(CashBoardElement) || otherElement.GetElementClassType() == typeof(CashBoardElement))
        {
            return(false);
        }
        else if (element.GetElementClassType() == typeof(BombBoardElement))
        {
            if (otherElement.GetElementClassType() == typeof(CrossBoardElement))
            {
                //AlexDebugger.GetInstance().AddMessage(BoardFunctions.GetTransformByIndex(element.GetTransformIndex()) + " bomb style set to cross", AlexDebugger.tags.Step1);
                ((BombBoardElement)element).SetExplosionStyleTo(BombBoardElement.BombExplosionStyle.CrossStyle);
            }
            else if (otherElement.GetElementClassType() == typeof(BombBoardElement))
            {
                //AlexDebugger.GetInstance().AddMessage(BoardFunctions.GetTransformByIndex(element.GetTransformIndex()) + " bomb style set to double bomb", AlexDebugger.tags.Step1);
                ((BombBoardElement)element).SetExplosionStyleTo(BombBoardElement.BombExplosionStyle.DoubleBombStyle);
            }
            element.OnElementDestruction(this);
            AlexDebugger.GetInstance().AddMessage("first element was a bomb, go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
            areThereMatches = true;
        }
        else if (element.GetElementClassType() == typeof(BellBoardElement))
        {
            AlexDebugger.GetInstance().AddMessage("first element was a bell, go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
            element.OnElementDestruction(this, otherElement);
            areThereMatches = true;
        }
        else
        {
            KeyValuePair <int, int> firstPosition = BoardFunctions.GetBoardPositionOfElement(element, elementsPositions);
            int numberOfMatchesForFirst           = BoardFunctions.CheckElementForMatches(firstPosition.Key, firstPosition.Value, elementsPositions, ref matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows, true);
            // if there are matches
            if (numberOfMatchesForFirst > 0)
            {
                AlexDebugger.GetInstance().AddMessage("Matches found for first element " + numberOfMatchesForFirst + ", go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
                // allow Update() to play effects
                areThereMatches = true;
            }
        }
        return(areThereMatches);
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        // Do nothing.
        if (areAnimationsPlaying)
        {
            return;
        }
        switch (currentStep)
        {
        case GameStep.WaitingInput:
            //OnDragEvent.hasDragBegin = false;

            break;

        // Step1: check if input create matches and if true move to step2
        case GameStep.CheckingInput:
            BoardFunctions.SwapElements(firstElement, secondElement, this, rewire: false, ConstantValues.swappingSpeed / 2);
            //Debug.Log("Checking for matches based on input");
            // check if input create matches
            if (HandleInputForElement(firstElement, secondElement))
            {
                if (firstElement.GetElementClassType() != typeof(BellBoardElement))
                {
                    HandleInputForElement(secondElement, firstElement);
                }
                //AlexDebugger.GetInstance().AddMessage("Step1 finished with matches, going to Step2: -play effects for matched elements-, input1:" + firstElement.GetAttachedGameObject().transform.name + ", input2: " + secondElement.GetAttachedGameObject().transform.name, AlexDebugger.tags.Step1);
                // Remove tokens
                MoneyManager.ChangeBalanceBy(-MoneyManager.GetSwapCost());
                // Swap the elements on the board
                // Allow Update() to check if matches are created
                AddWaitMessage();
                currentMessageID += 1;
                Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, false));
                currentStep = GameStep.PlayingEffects;
            }
            else if (HandleInputForElement(secondElement, firstElement))
            {
                //AlexDebugger.GetInstance().AddMessage("Step1 finished with matches, going to Step2: -play effects for matched elements-, input1:" + firstElement.GetAttachedGameObject().transform.name + ", input2: " + secondElement.GetAttachedGameObject().transform.name, AlexDebugger.tags.Step1);
                // Remove tokens
                MoneyManager.ChangeBalanceBy(-MoneyManager.GetSwapCost());
                // Swap the elements on the board
                AddWaitMessage();
                Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, false));

                currentStep = GameStep.PlayingEffects;
            }
            else
            {
                BoardFunctions.SwapElements(firstElement, secondElement, this, rewire: false);
                AddWaitMessage();
                AlexDebugger.GetInstance().AddMessage("No matches found, when finish, go back to step0: -waiting for input-", AlexDebugger.tags.Step1);
                SendMessagesToClient();
                currentMessageID += 1;
                Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, true));
                currentStep = GameStep.WaitingInput;
            }
            firstElement  = null;
            secondElement = null;
            break;

        // Step2: -Play effects for matched elements- and move to step3
        case GameStep.PlayingEffects:
            AlexDebugger.GetInstance().AddMessage("Entering Step2: -play effects for matched elements-", AlexDebugger.tags.Step2);
            if (PlayEffectsStep())
            {
                // AlexDebugger.GetInstance().AddMessage("Sending total animations to client: " + playingAnimations.Count, AlexDebugger.tags.Step2);
                AddWaitMessage();
                currentStep = GameStep.OrientingElements;
            }
            break;

        // Step3: repeat until non-destroyed elements have droped to lower position and then move to step4
        case GameStep.OrientingElements:
            AlexDebugger.GetInstance().AddMessage("Entering Step3: -reorienting board-", AlexDebugger.tags.Step3);
            ReorientElements();
            AddWaitMessage();
            //AlexDebugger.GetInstance().AddMessage("Step3: -reorienting board- has finished, moving to Step4: -replace destroyed elements", AlexDebugger.tags.Step3);
            currentStep = GameStep.GeneratingElements;
            break;

        // Step4: -Replace destroyed elements-, by assigning new color,  move to step5
        case GameStep.GeneratingElements:
            //AlexDebugger.GetInstance().AddMessage("Entering Step4: -replace destroyed elements-", AlexDebugger.tags.Step4);
            GenerateNewElemetns();
            //AlexDebugger.GetInstance().AddMessage("Sending total animations to client: " + playingAnimations.Count, AlexDebugger.tags.Step4);
            AddWaitMessage();
            // AlexDebugger.GetInstance().AddMessage("Element: " + positions[bestInputCollum, bestInputRow].GetAttachedGameObject().name + " has the best score possible: " + maxOutput, AlexDebugger.tags.Step4);
            //AlexDebugger.GetInstance().AddMessage("Step4 -Replace destroyed elements- has finished, moving to Step5 -Aftermatch-", AlexDebugger.tags.Step4);
            currentStep = GameStep.CheckingBoardForMatches;
            break;

        // Step5: check for new matches
        case GameStep.CheckingBoardForMatches:
            AlexDebugger.GetInstance().AddMessage("Entering Step5: -Aftermatch-", AlexDebugger.tags.Step5);
            //Debug.Log("### AfterMatch ### Checking board for combos");
            int newTotalMatches = CheckBoardForMatches();
            // Go back to step2
            if (newTotalMatches > 0)
            {
                //Debug.Log("### AfterMatch ### Total new matches found: " + newTotalMatches);
                AlexDebugger.GetInstance().AddMessage("Total new matches found on board: " + newTotalMatches, AlexDebugger.tags.Step5);
                AlexDebugger.GetInstance().AddMessage("Step5 -Aftermatch- has finished, with state -new matches found-,  moving to Step2 -Play effects for matched elements-", AlexDebugger.tags.Step5);
                currentStep = GameStep.PlayingEffects;
            }
            // Check for possible inputs
            else
            {
                AlexDebugger.GetInstance().AddMessage("No new matches found, flagging potential input", AlexDebugger.tags.Step5);
                currentStep = GameStep.MarkingPossibleInputs;
            }
            AddWaitMessage();
            break;

        case GameStep.MarkingPossibleInputs:
            //Debug.Log("### AfterMatch ### No new matches found");
            if (!CheckForPossibleInputs())
            {
                currentMessageID += 1;
                messagesToClient.Add(new Messages.AnimationMessage.PopBoxMessage(currentMessageID, currentMessageID - 1, "No possible inputs found. Regenerating board.", -1));
                //Debug.Log("### AfterMatch ### No possible inputs found, re-generating board");
                //AlexDebugger.GetInstance().AddMessage("No potential input found, all elements are flagged as destroyed", AlexDebugger.tags.Step5);
                MarkAllElementsAsDestroyed();
                //AlexDebugger.GetInstance().AddMessage("Step5 -Aftermatch- has finished, with state -No available input-,  moving to Step4 -Replace destroyed elements-", AlexDebugger.tags.Step5);
                currentStep = GameStep.GeneratingElements;
            }
            else
            {
                AlexDebugger.GetInstance().AddMessage("Step5 -Aftermatch- has finished, with state -Has available input-,  moving to Step0 -Wait for input-", AlexDebugger.tags.Step5);
                currentMessageID += 1;
                Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, true));
                currentStep = GameStep.WaitingInput;
            }
            AddWaitMessage();
            SendMessagesToClient();
            break;
        }
    }
    void OnGUI()
    {
        if (!hasInit)
        {
            tagsAndMessages = new Dictionary <AlexDebugger.tags, List <string> >();
            tagsFoldouts    = new Dictionary <AlexDebugger.tags, bool>();
            scrollPos       = new Dictionary <AlexDebugger.tags, Vector2>();

            foreach (DebugMessage msg in AlexDebugger.GetInstance().messages)
            {
                if (tagsAndMessages.ContainsKey(msg.tag) == false)
                {
                    if (msg.obj != null)
                    {
                        msg.message += ", Trigger script: " + msg.name;
                    }
                    tagsAndMessages.Add(msg.tag, new List <string>()
                    {
                        msg.message
                    });
                    tagsFoldouts.Add(msg.tag, false);
                    scrollPos.Add(msg.tag, Vector2.zero);
                }
                else
                {
                    tagsAndMessages[msg.tag].Add(msg.message);
                }
            }

            hasInit = true;
        }
        else
        {
            foldoutsScroll = EditorGUILayout.BeginScrollView(foldoutsScroll);
            foreach (AlexDebugger.tags tag in tagsAndMessages.Keys)
            {
                EditorGUILayout.BeginHorizontal();
                tagsFoldouts[tag] = EditorGUILayout.Foldout(tagsFoldouts[tag], "Show debug for tag: " + tag);
                GUILayout.Space(10);
                if (GUILayout.Button("Clear debug for tag:  " + tag, GUILayout.Width(300)))
                {
                    AlexDebugger.GetInstance().ClearMessagesForTag(tag);
                    hasInit = false;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            messagScroll = EditorGUILayout.BeginScrollView(messagScroll, false, false);
            foreach (AlexDebugger.tags tag in tagsFoldouts.Keys)
            {
                if (tagsFoldouts[tag] == true)
                {
                    scrollPos[tag] = EditorGUILayout.BeginScrollView(scrollPos[tag], false, false);
                    foreach (string message in tagsAndMessages[tag])
                    {
                        EditorGUILayout.TextArea(message);
                        EditorGUILayout.Separator();
                    }
                    EditorGUILayout.EndScrollView();
                }
            }
            EditorGUILayout.EndScrollView();
        }
        showAllMessageFoldout = EditorGUILayout.Foldout(showAllMessageFoldout, "Show all messages based on time created");
        if (showAllMessageFoldout)
        {
            allMessagesScroll = EditorGUILayout.BeginScrollView(allMessagesScroll);
            List <DebugMessage> messages = AlexDebugger.GetInstance().messages;
            foreach (DebugMessage msg in messages)
            {
                EditorGUILayout.TextArea(msg.message + ". -[tag]- " + msg.tag + ", -[trigger]- " + ((msg.obj == null) ? "" : msg.obj.name));
                EditorGUILayout.Separator();
            }
            EditorGUILayout.EndScrollView();
        }
        if (GUILayout.Button("Destroy all messages"))
        {
            foreach (AlexDebugger.tags tag in tagsAndMessages.Keys)
            {
                for (int i = 0; i < tagsAndMessages[tag].Count; i++)
                {
                    tagsAndMessages[tag].Remove(tagsAndMessages[tag][i]);
                }
            }
            hasInit = false;
        }
    }