Esempio n. 1
0
 public override bool OnElementDestruction(BoardManager board)
 {
     if (hasBeenDestroyed)
     {
         return(false);
     }
     MoneyManager.ChangeBalanceBy(GetCashValue());
     hasBeenDestroyed = true;
     return(false);
 }
Esempio n. 2
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;
        }
    }