Ejemplo n.º 1
0
    public bool getNextBallValue()
    {
        //Debug.Log ("getNextBallValue : keyIndex = " + keyIndex);

        if (keyIndex < 0)
        {
            return(false);
        }

        string _key = "k" + (keyIndex - 1);

        keyIndex--;

        FormulaToken _ftoken = GetFormulaToken(_key);

        if (_ftoken != null)
        {
            _ball_value    = _ftoken.value;
            _ball_function = _ftoken.function;


            return(true);
        }

        return(false);
    }
Ejemplo n.º 2
0
    void AddBallToBucket()
    {
        GameObject mathBall = GetAvailableBall();

        if (mathBall == null)
        {
            return;
        }



        //FormulaFactory _formulaFactory = GameCommon.getFormulaFactoryClass();

        //FormulaFactory.Instance.getNextBallValue()

        if (FormulaFactory.Instance.getNextBallValue() == true)
        {
            MathBall _mathBallScript = mathBall.GetComponent <MathBall> ();
            _mathBallScript._state = MathBall.eState.InBucket;

            //debug
            GetNumBallsInBucket();

            MathBall.eFunction _ballFunction = FormulaFactory.Instance.ball_function;
            int _ballValue = FormulaFactory.Instance.ball_value;

            setBallFunctionAndValue(mathBall, _ballFunction, _ballValue);


            if (_ballFunction == MathBall.eFunction.Digit)
            {
                setBallColor(mathBall, ballColorBackDigit);
                setBallScale(mathBall, ballScaleDigit);

                setBallHiliteColor(mathBall, ballColorBackDigit);
            }
            else if (_ballFunction == MathBall.eFunction.Operand)
            {
                if (_ballValue == (int)MathBall.eOperator.Equals)
                {
                    setBallColor(mathBall, ballColorBackEquals);
                    setBallScale(mathBall, ballScaleEquals);
                    setBallHiliteColor(mathBall, ballColorBackEquals);
                }
                else
                {
                    setBallColor(mathBall, ballColorBackOperand);
                    setBallScale(mathBall, ballScaleOperand);
                    setBallHiliteColor(mathBall, ballColorBackOperand);
                }
            }


            mathBall.SetActive(true);
            setAllChildrenActive(mathBall, true);
        }
    }
Ejemplo n.º 3
0
    public void AddCalcToken(int value, MathBall.eFunction function)
    {
        CalcToken newToken = new CalcToken();

        newToken.key      = "k" + keyIndex;
        newToken.value    = value;
        newToken.function = function;

        //Debug.Log ("Token : key = " + newToken.key + " value = " + newToken.value.ToString() + " function = " + (MathBall.eFunction)newToken.function);

        CalcTokens.Add(newToken);

        keyIndex++;
    }
Ejemplo n.º 4
0
    public void AddFormulaToken(int value, MathBall.eFunction function)
    {
        //Debug.Log ("AddFormulaToken = " + value);
        FormulaToken newToken = new FormulaToken();

        newToken.key      = "k" + keyIndex;
        newToken.value    = value;
        newToken.function = function;

        //Debug.Log ("Token : key = " + newToken.key + " value = " + newToken.value.ToString() + " function = " + (MathBall.eFunction)newToken.function);

        FormulaTokens.Add(newToken);

        keyIndex++;

        //Debug.Log ("AddFormulaToken : keyIndex = " + keyIndex);
    }
Ejemplo n.º 5
0
    //deprecated
    public void setNextBallValues()
    {
        int chance = UnityEngine.Random.Range(0, 100);

        if (chance < 50)
        {
            int rn = UnityEngine.Random.Range(0, 9);
            _ball_value = rn;

            _ball_function = MathBall.eFunction.Digit;
        }
        else if (chance < 80)
        {
            int operand = UnityEngine.Random.Range(0, 5);
            _ball_value = operand;

            _ball_function = MathBall.eFunction.Operand;
        }
        else
        {
            _ball_value    = (int)MathBall.eOperator.Equals;
            _ball_function = MathBall.eFunction.Operand;
        }
    }
Ejemplo n.º 6
0
    public bool AnalyseCalcTokenList()
    {
        //Debug.Log ("AnalyseCalcTokenList");
        bool result = false;

        //equation
        int eix = 0;

        int[] equation = new int[128];

        //fill equation
        int nix = 0;

        string[] numberStrings = new string[32];

        int       _index  = 0;
        string    _key    = "k" + _index;
        CalcToken _ctoken = GetCalcToken(_key);

        int pMode = 0;

        while (_ctoken != null)
        {
            MathBall.eFunction _function = _ctoken.function;
            int _value = _ctoken.value;

            if (_function == MathBall.eFunction.Digit)
            {
                numberStrings [nix] += _value.ToString();
                pMode = 1;
            }
            else if (_function == MathBall.eFunction.Operand)
            {
                if (pMode == 1)
                {
                    equation [eix] = Int32.Parse(numberStrings [nix]);
                    eix++;
                    nix++;
                    pMode = 0;
                }
                else
                {
                    //Debug.Log ("Setting errorResult in loop...");
                    errorResult = 1;
                    return(result);
                }

                equation [eix++] = (int)_value;
            }

            //get next
            _index++;
            _key    = "k" + _index;
            _ctoken = GetCalcToken(_key);
            if (_ctoken == null)
            {
                if (pMode == 1)
                {
                    equation [eix] = Int32.Parse(numberStrings [nix]);
                    eix++;
                }
            }
        }

        //evaluate the equation
        bool bothSides = false;
        int  count     = eix;
        int  leftSide  = 0;
        int  rightSide = 9999;
        int  score     = 0;

        int idx = 0;

        MathBall.eOperator currentOp = MathBall.eOperator.Plus;

        int value = equation [idx];

        idx++;
        while (idx < count)
        {
            if (idx % 2 == 0)
            {
                //number
                switch (currentOp)
                {
                case MathBall.eOperator.Plus:
                    value += equation [idx];
                    score += 4;
                    break;

                case MathBall.eOperator.Minus:
                    value -= equation [idx];
                    score += 6;
                    break;

                case MathBall.eOperator.Multiply:
                    value *= equation [idx];
                    score += 8;
                    break;

                case MathBall.eOperator.Divide:
                    value /= equation [idx];
                    score += 10;
                    break;

                case MathBall.eOperator.Power:
                    value  = (int)Math.Pow(value, equation [idx]);
                    score += 12;
                    break;

                case MathBall.eOperator.Modulus:
                    value %= equation [idx];
                    score += 14;
                    break;
                }
            }
            else
            {
                //operand
                currentOp = (MathBall.eOperator)equation[idx];

                if (currentOp == MathBall.eOperator.Equals)
                {
                    if (bothSides == false)
                    {
                        leftSide = value;

                        idx++;
                        if (idx < count)                       //advance to right side if there is data there
                        {
                            value     = equation [idx];
                            bothSides = true;
                        }
                    }
                }
            }

            idx++;
        }

        if (bothSides == true)
        {
            rightSide = value;
        }

        //Debug.Log ("leftSide="+leftSide+":rightSide="+rightSide);

        if (bothSides == true && leftSide == rightSide)
        {
            result = true;
        }

        _calcScore = score;

        return(result);
    }
Ejemplo n.º 7
0
    void Update()
    {
        switch (_systemState)
        {
        case eSystemState.noop:
            break;

        case eSystemState.reboot:
            _score       = 0;
            _systemState = eSystemState.active;
            break;

        case eSystemState.active:
        {
            _elaspedTime += Time.deltaTime;

            if (_elaspedTime > _emmiterTime)
            {
                //insert ball into bucket
                AddBallToBucket();

                _elaspedTime = 0.0f;
            }



            if (Input.GetMouseButtonDown(0))
            {
                //Debug.Log ("Clicked");
                Vector2      pos     = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(pos), Vector2.zero);
                // RaycastHit2D can be either true or null, but has an implicit conversion to bool, so we can use it like this
                if (hitInfo)
                {
                    //Debug.Log( hitInfo.transform.gameObject.name );

                    GameObject _gObj           = hitInfo.transform.gameObject;
                    MathBall   _mathBallScript = _gObj.GetComponent <MathBall> ();
                    if (_mathBallScript.setBallSelected() == false)
                    {
                        ClearSelectedBalls();
                        //CentralCalculator _centralCalculator = GameCommon.getCentralCalculatorClass();
                        CentralCalculator.Instance.ResetCalcTokenList();

                        //is ball already selected?
                        //clear with zonk
                        //GameCommon.getAudioDepotClass().PlaySfx(AudioDepot.eSfxID.matchReset);
                        AudioDepot.Instance.PlaySfx(AudioDepot.eSfxID.matchReset);
                    }
                    else
                    {
                        //value & function
                        MathBall.eFunction function = _mathBallScript._function;
                        int value = _mathBallScript.ball_value;

                        //CentralCalculator _centralCalculator = GameCommon.getCentralCalculatorClass();

                        CentralCalculator.Instance.AddCalcToken(value, function);

                        if (CentralCalculator.Instance.AnalyseCalcTokenList() == true)
                        {
                            //success

                            //get score
                            _score += CentralCalculator.Instance.calcScore;

                            //clear selected balls
                            Debug.Log("SUCCESSFULL CALCULATION!!");
                            RemoveSelectedBalls();
                            CentralCalculator.Instance.ResetCalcTokenList();

                            if (GetNumBallsInBucket() == 0)
                            {
                                //GameCommon.getGameplayManagerClass().PuzzleCompete(_score);
                                GameplayManager.Instance.PuzzleCompete(_score);
                                //GameCommon.getAudioDepotClass().PlaySfx(AudioDepot.eSfxID.puzzleDone);
                                AudioDepot.Instance.PlaySfx(AudioDepot.eSfxID.puzzleDone);

                                //GameCommon.getParticleDepotClass().PlayBonus();
                                ParticleDepot.Instance.PlayBonus();
                            }
                            else
                            {
                                //GameCommon.getAudioDepotClass().PlaySfx(AudioDepot.eSfxID.matchMade);
                                AudioDepot.Instance.PlaySfx(AudioDepot.eSfxID.matchMade);
                            }
                        }
                        else if (CentralCalculator.Instance.ErrorReport() > 0)
                        {
                            //clear with zonk
                            Debug.Log("ERROR ... ERROR ... ERROR!!");
                            ClearSelectedBalls();
                            CentralCalculator.Instance.ResetCalcTokenList();
                        }
                    }
                }
            }
        }
        break;


        case eSystemState.done:
            break;
        }
    }
Ejemplo n.º 8
0
    private void setBallFunctionAndValue(GameObject _gObj, MathBall.eFunction _f, int _v)
    {
        MathBall _mathBallScript = _gObj.GetComponent <MathBall> ();

        _mathBallScript.SetFunctionAndValue(_f, _v);
    }