예제 #1
0
        /// <summary>
        /// Returns the proper mixed number equivalent to the improper fraction.
        /// </summary>
        /// <param name="mixedNum"></param>
        /// <returns></returns>

        public bool MixedNumber ToProper(MixedNumber mixedNum)
        {
            MixedNumber returnValue = new MixedNumber();

            if (mixedNum.wholeNumber == -1)
            {
                returnValue.wholeNumber = -1 * (mixedNum.numerator / mixedNum.denominator);
                returnValue.numerator = mixedNum.numerator % mixedNum.denominator;
                returnValue.denominator = mixedNum.denominator;
            }
            else if (mixedNum.wholeNumber == 0)
            {
                returnValue.wholeNumber = mixedNum.numerator / mixedNum.denominator;
                returnValue.numerator = mixedNum.numerator % mixedNum.denominator;
                returnValue.denominator = mixedNum.denominator;
            }
            else
            {
                /////////////////////
                // Add Error code. //
                /////////////////////
            }

            return returnValue;
        }
        public static MixedNumber operator+(MixedNumber a, Fraction b)
        {
            MixedNumber result = new MixedNumber(a.wholeNumber, a.fraction + b);

            result.wholeNumber += result.fraction.Reduce();
            return(result);
        }
예제 #3
0
        MixedNumber ConvertFractionToMixedNumber(Fraction f)
        {
            int gcd         = 1;
            int wholeNumber = 0;

            do
            {
                if (f.Numerator > f.Denominator)
                {
                    gcd = GetGCD(f.Numerator, f.Denominator);
                }
                else
                {
                    gcd = GetGCD(f.Denominator, f.Numerator);
                }

                f.Numerator   = f.Numerator / gcd;
                f.Denominator = f.Denominator / gcd;
            } while (gcd != 1);

            if (f.Numerator > f.Denominator)
            {
                wholeNumber = f.Numerator / f.Denominator;
                f.Numerator = f.Numerator % f.Denominator;
            }


            MixedNumber m = new MixedNumber(wholeNumber, f.Numerator, f.Denominator, f.IsNegative);

            return(m);
        }
예제 #4
0
        /// <summary>
        /// This method takes two mixed numbers and an operator as input parameters and performs type of arithmetic as indicated by the operator
        /// </summary>
        /// <param name="m1"> First Mixed Number</param>
        /// <param name="m2"> Second Mixed Number</param>
        /// <param name="strOperator">Operator</param>

        string PerformArithmetic(MixedNumber m1, MixedNumber m2, string strOperator)
        {
            MixedNumber m3 = new MixedNumber();

            if (strOperator == "*")
            {
                FractionOperationsBC fractionOps = new FractionOperationsBC();
                m3 = fractionOps.Mulitply(m1, m2);
            }
            else if (strOperator == "+")
            {
                FractionOperationsBC fractionOps = new FractionOperationsBC();
                m3 = fractionOps.Add(m1, m2);
            }
            else if (strOperator == "-")
            {
                FractionOperationsBC fractionOps = new FractionOperationsBC();
                m3 = fractionOps.Subtract(m1, m2);
            }
            else if (strOperator == "/")
            {
                FractionOperationsBC fractionOps = new FractionOperationsBC();
                m3 = fractionOps.Divide(m1, m2);
            }
            else
            {
                throw new ArgumentException("Invalid Operator detected!. Only +,-,*,/ are allowed as operators");
            }

            return(m3.ToString());
        }
        public static MixedNumber operator +(Fraction a, MixedNumber b)
        {
            MixedNumber result = new MixedNumber(b.wholeNumber, b.fraction + a);

            result.wholeNumber += result.fraction.Reduce();
            return(result);
        }
예제 #6
0
 //debug
 public void ForceSubmit(MixedNumber number)
 {
     if (!mIsAnswerSubmitted)
     {
         mAnswerNumber      = number;
         mIsAnswerCorrect   = true;
         mIsAnswerSubmitted = true;
     }
 }
예제 #7
0
 void OnAnswerSubmit(bool correct)
 {
     if (!mIsAnswerSubmitted)
     {
         mAnswerNumber      = opsWidget.answerInput.number;
         mIsAnswerCorrect   = correct;
         mIsAnswerSubmitted = true;
     }
 }
예제 #8
0
 private static MixedNumber GetMixedNumber(decimal a, decimal b)
 {
     MixedNumber result = new MixedNumber();
     ulong num = (ulong)Math.Floor(a / b);
     result.Num = num;
     result.A = b;
     result.B = a - b * num;
     return result;
 }
예제 #9
0
        private static MixedNumber GetMixedNumber(decimal a, decimal b)
        {
            MixedNumber result = new MixedNumber();
            ulong       num    = (ulong)Math.Floor(a / b);

            result.Num = num;
            result.A   = b;
            result.B   = a - b * num;
            return(result);
        }
예제 #10
0
    public static string GetMeasureText(UnitMeasureType type, MixedNumber val)
    {
        mSB.Clear();

        val.ApplyString(mSB);
        //mSB.Append(' ');
        mSB.Append(GetText(type));

        return(mSB.ToString());
    }
예제 #11
0
        public string ReadAndProcessInput(string[] args)
        {
            string firstNumber  = args[0];
            string strOperator  = args[1];
            string secondNumber = args[2];

            MixedNumber m1 = ConvertArgumentToValidFraction(firstNumber);
            MixedNumber m2 = ConvertArgumentToValidFraction(secondNumber);

            return(PerformArithmetic(m1, m2, strOperator));
        }
예제 #12
0
        /// <summary>
        /// Returns whether the mixed number is proper.
        /// </summary>
        /// <param name="mixedNum"></param>
        /// <returns></returns>
        public bool IsProper(MixedNumber mixedNum)
        {
            bool returnValue;

            if (mixedNum.numerator < mixedNum.denominator)
                returnValue = true;
            else
                returnValue = false;

            return returnValue;
        }
예제 #13
0
        /// <summary>
        /// Returns the improper fraction equivalent tothe proper fraction.
        /// </summary>
        /// <param name="mixedNum"></param>
        /// <returns></returns>
        public MixedNumber ToImproper(MixedNumber mixedNum)
        {
            MixedNumber returnValue = new MixedNumber();

            returnValue.numerator = mixedNum.denominator * Math.Abs(mixedNum.wholeNumber) + mixedNum.numerator;
            returnValue.denominator = mixedNum.denominator;

            if (mixedNum.wholeNumber < 0)
                returnValue.numerator *= -1;

            return returnValue;
        }
예제 #14
0
    public void Play(Vector2 start, MixedNumber number)
    {
        //convert start, assume world space to screen space (UI)
        var     cam = M8.Camera2D.main.unityCamera;
        Vector2 pos = cam.WorldToScreenPoint(start);

        var widget = mPool.Spawn <MixedNumberWidget>("", transform, pos, null);

        widget.number = number;

        StartCoroutine(DoActive(widget));
    }
예제 #15
0
        /// <summary>
        /// This method will convert valid input fractions (string) into a MixedNumber
        /// The example valid fractions would be 1_1/3, 3/5, 6, -4/5, -3_7/8, +4_7/9, -6, 8, 5_3
        /// The example invalid fractions would be _1/3, +_6/8,7/0,-+6/7, 7/, 3_4/ in addtion to any other non-numeric characters in the string
        /// If the fraction turned out to be invalid, an ArgumentException would be raised
        /// </summary>
        /// <param name="strInput"> Input fraction (string)</param>
        /// <returns></returns>

        MixedNumber ConvertArgumentToValidFraction(string strInput)
        {
            MixedNumber m = new MixedNumber();

            int startPos = 0;

            if (strInput[0] != '-' && strInput[0] != '+' && !Char.IsDigit(strInput[0]))
            {
                throw new ArgumentException("One of the input operand is invalid!");
            }

            if (strInput[0] == '-' || strInput[0] == '+')
            {
                m.IsNegative = strInput[0] == '-' ? true : false;
                startPos     = 1;
            }

            try
            {
                int wholeSeparatorPos = strInput.IndexOf('_');

                if (wholeSeparatorPos > 0)
                {
                    m.Integral = Convert.ToInt32(strInput.Substring(startPos, wholeSeparatorPos - startPos));
                    startPos   = wholeSeparatorPos + 1;
                }


                int divisionPos = strInput.IndexOf('/');
                if (divisionPos > 0)
                {
                    m.Numerator   = Convert.ToInt32(strInput.Substring(startPos, divisionPos - startPos));
                    m.Denominator = Convert.ToInt32(strInput.Substring(divisionPos + 1, strInput.Length - divisionPos - 1));

                    if (m.Denominator == 0)
                    {
                        throw new ArgumentException("Invalid input.. One of the input parameter has 0 in the denominator");
                    }
                }
                else
                {
                    m.Numerator   = Convert.ToInt32(strInput.Substring(startPos, strInput.Length - startPos));
                    m.Denominator = 1;
                }

                return(m);
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException("One of the input operand is not a valid fraction/number", ex);
            }
        }
예제 #16
0
 private static Stack<ulong> GetContinuedFraction(decimal input_num)
 {
     Debug.Print(string.Format("{0}", input_num));
     Stack<ulong> astack = new Stack<ulong>();
     MixedNumber mx = new MixedNumber();
     mx.A = input_num;
     mx.B = 1m;
     do
     {
         mx = GetMixedNumber(mx.A, mx.B);
         Debug.Print(string.Format("{0}  {1}  {2}", mx.Num, mx.A, mx.B));
         astack.Push(mx.Num);
     } while (mx.B != 0);
     return astack;
 }
예제 #17
0
        private static Stack <ulong> GetContinuedFraction(decimal input_num)
        {
            Debug.Print(string.Format("{0}", input_num));
            Stack <ulong> astack = new Stack <ulong>();
            MixedNumber   mx     = new MixedNumber();

            mx.A = input_num;
            mx.B = 1m;
            do
            {
                mx = GetMixedNumber(mx.A, mx.B);
                Debug.Print(string.Format("{0}  {1}  {2}", mx.Num, mx.A, mx.B));
                astack.Push(mx.Num);
            } while (mx.B != 0);
            return(astack);
        }
예제 #18
0
        Fraction ConvertMixedNumberToFraction(MixedNumber m)
        {
            Fraction f = new Fraction();

            if (m.Integral != 0)
            {
                f.Numerator = m.Integral * m.Denominator + m.Numerator;
            }
            else
            {
                f.Numerator = m.Numerator;
            }

            f.Denominator = m.Denominator;
            f.IsNegative  = m.IsNegative;

            return(f);
        }
예제 #19
0
        /// <summary>
        /// This method takes two mixed numbers and applies the divide operator and returs a new mixed number
        /// </summary>
        /// <param name="m1"> First Mixed Number</param>
        /// <param name="m2">Second Mixed Number</param>
        /// <returns>Returns a mixed number</returns>
        public MixedNumber Divide(MixedNumber m1, MixedNumber m2)
        {
            Fraction f1 = ConvertMixedNumberToFraction(m1);
            Fraction f2 = ConvertMixedNumberToFraction(m2);

            Fraction rem = new Fraction();

            rem.Numerator   = f1.Numerator * f2.Denominator;
            rem.Denominator = f1.Denominator * f2.Numerator;

            //if one of the fractions were negative, the result would be negative too
            //But if both of the fractions are negative or positive, then the result would be positive
            if ((!f1.IsNegative && f2.IsNegative) || (f1.IsNegative && !f2.IsNegative))
            {
                rem.IsNegative = true;
            }

            return(ConvertFractionToMixedNumber(rem));
        }
예제 #20
0
        /// <summary>
        /// This method takes two mixed numbers as input and returns a third mixed number, which is a difference between first and second mixed numbers
        /// </summary>
        /// <param name="m1"></param>
        /// <param name="m2"></param>
        /// <returns></returns>
        public MixedNumber Subtract(MixedNumber m1, MixedNumber m2)
        {
            Fraction f1 = ConvertMixedNumberToFraction(m1);
            Fraction f2 = ConvertMixedNumberToFraction(m2);

            Fraction diff = new Fraction();

            //if the fraction is negative, the result is multiplied by -1, so we can preserve the appropriate sign of the result
            diff.Numerator   = (f1.IsNegative == true ? -1 : 1) * f1.Numerator * f2.Denominator - (f2.IsNegative == true ? -1 : 1) * f1.Denominator * f2.Numerator;
            diff.Denominator = f1.Denominator * f2.Denominator;

            if (diff.Numerator < 0)
            {
                diff.IsNegative = true;
                diff.Numerator  = -1 * diff.Numerator;
            }

            return(ConvertFractionToMixedNumber(diff));
        }
예제 #21
0
        /// <summary>
        /// This method takes two mixed numbers as input and returns a third mixed number, which is a summation of the first and second mixed numbers
        /// </summary>
        /// <param name="m1"></param>
        /// <param name="m2"></param>
        /// <returns></returns>
        public MixedNumber Add(MixedNumber m1, MixedNumber m2)
        {
            Fraction f1 = ConvertMixedNumberToFraction(m1);
            Fraction f2 = ConvertMixedNumberToFraction(m2);

            Fraction sum = new Fraction();

            //if the fraction is negative, the result is multiplied by -1, so we can preserve the appropriate sign of the result
            sum.Numerator   = (f1.IsNegative == true? -1: 1) * f1.Numerator * f2.Denominator + (f2.IsNegative == true ? -1 : 1) * f1.Denominator * f2.Numerator;
            sum.Denominator = f1.Denominator * f2.Denominator;

            if (sum.Numerator < 0)
            {
                sum.IsNegative = true;
                sum.Numerator  = -1 * sum.Numerator;
            }

            return(ConvertFractionToMixedNumber(sum));
        }
예제 #22
0
        /// <summary>
        /// This method takes two mixed numbers as input and returns a third mixed number, which is a product of the two input mixed numbers
        /// </summary>
        /// <param name="m1"></param>
        /// <param name="m2"></param>
        /// <returns></returns>
        public MixedNumber Mulitply(MixedNumber m1, MixedNumber m2)
        {
            Fraction f1 = ConvertMixedNumberToFraction(m1);
            Fraction f2 = ConvertMixedNumberToFraction(m2);

            Fraction product = new Fraction();

            //if the fraction is negative, the result is multiplied by -1, so we can preserve the appropriate sign of the result
            product.Numerator   = (f1.IsNegative == true ? -1 : 1) * f1.Numerator * (f2.IsNegative == true ? -1 : 1) * f2.Numerator;
            product.Denominator = f1.Denominator * f2.Denominator;

            //if the result numerator is negative, then the mixed number would be negative too
            if (product.Numerator < 0)
            {
                product.IsNegative = true;
                product.Numerator  = -1 * product.Numerator;
            }

            return(ConvertFractionToMixedNumber(product));
        }
예제 #23
0
    /// <summary>
    /// Animate and convert whole of number to fraction
    /// </summary>
    public void WholeToFraction()
    {
        //no animation if there's no whole to take
        if (mNumber.whole == 0)
        {
            return;
        }

        StopSwapRout();

        if (animator && !string.IsNullOrEmpty(takeWholeToFraction))
        {
            mNumberPrev = mNumber;
            mNumber.WholeToFraction();
            StartCoroutine(DoWholeToFractionAnimation());
        }
        else
        {
            var num = mNumber;
            num.WholeToFraction();
            number = num;
        }
    }
예제 #24
0
    /// <summary>
    /// Animate and convert fraction of number to whole
    /// </summary>
    public void FractionToWhole()
    {
        //no animation if there's no whole to take
        if (mNumber.denominator <= 0 || mNumber.numerator < mNumber.denominator)
        {
            return;
        }

        StopSwapRout();

        if (animator && !string.IsNullOrEmpty(takeFractionToWhole))
        {
            mNumberPrev = mNumber;
            mNumber.FractionToWhole();
            StartCoroutine(DoFractionToWholeAnimation());
        }
        else
        {
            var num = mNumber;
            num.FractionToWhole();
            number = num;
        }
    }
예제 #25
0
    public MixedNumber Evaluate()
    {
        //fail-safe
        if (operands.Length == 0)
        {
            return(new MixedNumber());
        }
        else if (operands.Length == 1)
        {
            return(operands[0].number);
        }

        MixedNumber result = operands[0].isEmpty ? new MixedNumber() : operands[0].number;

        for (int i = 0; i < operators.Length; i++)
        {
            var op2 = operands[i + 1];
            if (op2.isEmpty)
            {
                continue;
            }

            switch (operators[i])
            {
            case OperatorType.Add:
                result += op2.number;
                break;

            case OperatorType.Subtract:
                result -= op2.number;
                break;
            }
        }

        return(result);
    }
예제 #26
0
 public void ApplyNumber(MixedNumber toNumber)
 {
     mNumber  = toNumber;
     numbers  = null;
     mIsEmpty = false;
 }
예제 #27
0
    IEnumerator DoPlay()
    {
        if (animator)
        {
            animator.gameObject.SetActive(true);

            //ready animation countdown thing
            if (!string.IsNullOrEmpty(takeEnter))
            {
                yield return(animator.PlayWait(takeEnter));
            }

            yield return(new WaitForSeconds(readyDelay));

            if (!string.IsNullOrEmpty(takeExit))
            {
                yield return(animator.PlayWait(takeExit));
            }

            animator.gameObject.SetActive(false);
        }

        //show interfaces
        opsWidget.gameObject.SetActive(true);

        opsWidget.Show();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        if (timerWidget)
        {
            timerWidget.Show();
        }
        if (counterWidget)
        {
            counterWidget.Show();
        }
        //

        //timerWidget.ResetValue();

        attackTotalNumber = new MixedNumber();

        var waitBrief = new WaitForSeconds(0.3f);

        //loop
        for (int attackIndex = 0; attackIndex < attackCount; attackIndex++)
        {
            //show and fill deck
            if (deckWidget)
            {
                deckWidget.gameObject.SetActive(true);
                deckWidget.Show();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }
            }

            FillSlots();
            yield return(waitBrief);

            if (timerWidget)
            {
                timerWidget.SetActive(true);
            }
            //

            //listen for answer
            mIsAnswerSubmitted     = false;
            signalAnswer.callback += OnAnswerSubmit;

            //wait for correct answer, or time expired
            while (true)
            {
                if (mIsAnswerSubmitted)
                {
                    if (mIsAnswerCorrect)
                    {
                        mCurNumbersIndex++;
                        if (mCurNumbersIndex == numberGroups.Length)
                        {
                            mCurNumbersIndex = 0;
                        }

                        break;
                    }

                    mIsAnswerSubmitted = false;
                }

                //ignore timer expire if we are at first attack
                if (attackIndex > 0 && IsTimerExpired())
                {
                    break;
                }

                yield return(null);
            }

            //ready for next
            if (timerWidget)
            {
                timerWidget.SetActive(false);
            }

            signalAnswer.callback -= OnAnswerSubmit;

            RefreshOperands();

            if (deckWidget)
            {
                deckWidget.Clear();

                deckWidget.Hide();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }

                deckWidget.gameObject.SetActive(false);
            }
            //

            //add answer if submitted and correct
            if (mIsAnswerSubmitted && mIsAnswerCorrect)
            {
                mAttackNumbers.Add(mAnswerNumber);
                attackTotalNumber += mAnswerNumber;

                if (counterWidget)
                {
                    counterWidget.FillIncrement();
                }
            }

            //check if time expired
            if (IsTimerExpired())
            {
                break;
            }
        }

        //hide interfaces
        if (timerWidget)
        {
            timerWidget.Hide();
        }
        if (counterWidget)
        {
            counterWidget.Hide();
        }

        opsWidget.Hide();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        opsWidget.gameObject.SetActive(false);
        //

        //do attack routine
        mAttacker.action = CombatCharacterController.Action.AttackEnter;
        mDefender.action = CombatCharacterController.Action.Defend;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        mAttacker.action = CombatCharacterController.Action.Attack;
        mDefender.action = CombatCharacterController.Action.Hurt;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        //show defender's hp
        mDefender.hpWidget.Show();
        while (mDefender.hpWidget.isBusy)
        {
            yield return(null);
        }

        //do hits
        var waitHit = new WaitForSeconds(hitPerDelay);

        for (int i = 0; i < mAttackNumbers.Count; i++)
        {
            var attackNum = mAttackNumbers[i];

            mDefender.hpCurrent -= attackNum.fValue;

            M8.SoundPlaylist.instance.Play(audioHit, false);

            //do fancy hit effect
            if (damageFloater)
            {
                damageFloater.Play(damageFloaterAnchor.position, attackNum);
            }

            yield return(waitHit);
        }

        //return to idle, death for defender if hp = 0
        mAttacker.action = CombatCharacterController.Action.Idle;

        yield return(waitHit);

        //hide defender's hp
        mDefender.hpWidget.Hide();

        if (mDefender.hpCurrent > 0f)
        {
            mDefender.action = CombatCharacterController.Action.Idle;
        }
        else
        {
            M8.SoundPlaylist.instance.Play(audioDeath, false);

            mDefender.action = CombatCharacterController.Action.Death;
        }

        while (mAttacker.isBusy || mDefender.isBusy)
        {
            yield return(null);
        }
        //

        if (postAttackDelay > 0f)
        {
            yield return(new WaitForSeconds(postAttackDelay));
        }

        mRout = null;
    }
예제 #28
0
    public void Init(bool isWholeEnabled, bool isNegative)
    {
        number = new MixedNumber();

        mCurSelect = SelectType.None;

        mIsWholeEnabled  = isWholeEnabled;
        numberIsNegative = isNegative;

        mIsLocked = false;
        ApplyLocked();

        if (mIsWholeEnabled)
        {
            if (wholeRootGO)
            {
                wholeRootGO.SetActive(mIsWholeEnabled);
            }
            if (negativeSignGO)
            {
                negativeSignGO.SetActive(false);
            }
        }
        else
        {
            if (wholeRootGO)
            {
                wholeRootGO.SetActive(false);
            }
            if (negativeSignGO)
            {
                negativeSignGO.SetActive(numberIsNegative);
            }
        }

        if (wholeActiveGO)
        {
            wholeActiveGO.SetActive(false);
        }
        if (wholeText)
        {
            wholeText.text = mIsWholeEnabled && numberIsNegative ? "-" : "";
        }

        if (numeratorActiveGO)
        {
            numeratorActiveGO.SetActive(false);
        }
        if (numeratorText)
        {
            numeratorText.text = "";
        }

        if (denominatorActiveGO)
        {
            denominatorActiveGO.SetActive(false);
        }
        if (denominatorText)
        {
            denominatorText.text = "";
        }
    }
예제 #29
0
    IEnumerator DoPlay()
    {
        if (animator)
        {
            animator.gameObject.SetActive(true);

            //ready animation countdown thing
            if (!string.IsNullOrEmpty(takeEnter))
            {
                yield return(animator.PlayWait(takeEnter));
            }

            yield return(new WaitForSeconds(readyDelay));

            if (!string.IsNullOrEmpty(takeExit))
            {
                yield return(animator.PlayWait(takeExit));
            }

            animator.gameObject.SetActive(false);
        }

        //attack animation towards defender
        mAttacker.action = CombatCharacterController.Action.Attack;
        mDefender.action = CombatCharacterController.Action.Defend;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }
        //

        //show interfaces
        opsWidget.gameObject.SetActive(true);
        opsWidget.Show();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        if (timerWidget)
        {
            timerWidget.Show();
        }
        //

        //timerWidget.ResetValue();

        mAnswerNumber = new MixedNumber();

        defenseTotalNumber = new MixedNumber();

        var waitBrief = new WaitForSeconds(0.3f);

        while (!IsTimerExpired())
        {
            //show and fill deck
            if (deckWidget)
            {
                deckWidget.gameObject.SetActive(true);
                deckWidget.Show();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }
            }

            FillSlots();
            yield return(waitBrief);

            if (timerWidget)
            {
                timerWidget.SetActive(true);
            }
            //

            //listen for answer
            mIsAnswerSubmitted     = false;
            signalAnswer.callback += OnAnswerSubmit;

            //wait for correct answer, or time expired
            while (!IsTimerExpired())
            {
                if (mIsAnswerSubmitted)
                {
                    if (mIsAnswerCorrect)
                    {
                        break;
                    }

                    mIsAnswerSubmitted = false;
                }

                yield return(null);
            }

            //ready for next
            if (timerWidget)
            {
                timerWidget.SetActive(false);
            }

            signalAnswer.callback -= OnAnswerSubmit;

            if (deckWidget)
            {
                deckWidget.Clear();

                deckWidget.Hide();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }

                deckWidget.gameObject.SetActive(false);
            }
            //

            //add answer if submitted and correct, move to first operand
            if (mIsAnswerSubmitted && mIsAnswerCorrect)
            {
                for (int i = 1; i < opsWidget.operation.operands.Length; i++)
                {
                    defenseTotalNumber += opsWidget.operation.operands[i].number;
                }

                if (mAnswerNumber.fValue <= 0f) //no longer need to accumulate
                {
                    break;
                }

                opsWidget.MoveAnswerToOperand(0);
            }

            yield return(waitBrief);
        }

        if (mAnswerNumber.fValue == 0f)
        {
            mAnswerNumber = mOperations.operands[0].number;
        }

        //hide interfaces
        if (timerWidget)
        {
            timerWidget.Hide();
        }

        opsWidget.Hide();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        opsWidget.gameObject.SetActive(false);
        //

        //hurt defender based on final answer
        var fval = mAnswerNumber.fValue;

        if (fval < 0f)
        {
            fval = 0f;
        }

        if (fval > 0f)
        {
            //show defender's hp
            mDefender.hpWidget.Show();
            while (mDefender.hpWidget.isBusy)
            {
                yield return(null);
            }

            mDefender.hpCurrent -= fval;
            mDefender.action     = CombatCharacterController.Action.Hurt;

            M8.SoundPlaylist.instance.Play(audioHit, false);

            //do fancy hit effect
            if (damageFloater)
            {
                damageFloater.Play(damageFloaterAnchor.position, mAnswerNumber);
            }

            //fancy floaty number
            yield return(new WaitForSeconds(postHurtDelay));

            //hide defender's hp
            mDefender.hpWidget.Hide();
        }

        mAttacker.action = CombatCharacterController.Action.Idle;
        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        if (mDefender.hpCurrent > 0f)
        {
            mDefender.action = CombatCharacterController.Action.Idle;
        }
        else
        {
            M8.SoundPlaylist.instance.Play(audioDeath, false);

            mDefender.action = CombatCharacterController.Action.Death;
        }

        if (postDefenseDelay > 0f)
        {
            yield return(new WaitForSeconds(postDefenseDelay));
        }

        mRout = null;
    }
 /// <summary>
 /// Copy constuctor
 /// </summary>
 /// <param name="m">Instance to copy</param>
 public MixedNumber(MixedNumber m)
 {
     wholeNumber = m.wholeNumber;
     fraction    = new Fraction(m.fraction);
 }
예제 #31
0
 public void ResetNumber()
 {
     mNumber = new MixedNumber();
     RefreshDisplay();
 }
예제 #32
0
    private void RefreshDimensionInfoDisplay()
    {
        GridCell    size;
        MixedNumber volume;

        var editCtrl = GridEditController.instance;

        switch (editCtrl.editMode)
        {
        case GridEditController.EditMode.Move:
        case GridEditController.EditMode.Expand:
            //use ghost info
            size   = editCtrl.ghostController.cellSize;
            volume = editCtrl.ghostController.volume;
            break;

        default:
            //use entity info
            if (mCurEntity)
            {
                size   = mCurEntity.cellSize;
                volume = mCurEntity.volume;
            }
            else
            {
                size   = GridCell.zero;
                volume = new MixedNumber();
            }
            break;
        }

        //generate dimension measurement
        var measureStr = UnitMeasure.GetText(editCtrl.levelData.measureType);

        mStrBuff.Clear();

        mStrBuff.AppendLine(size.ToString());

        MixedNumber num;

        num = size.col * editCtrl.levelData.sideMeasure; num.SimplifyImproper();
        mStrBuff.Append(num);
        mStrBuff.Append(measureStr);
        mStrBuff.Append(" x ");

        num = size.row * editCtrl.levelData.sideMeasure; num.SimplifyImproper();
        mStrBuff.Append(num);
        mStrBuff.Append(measureStr);
        mStrBuff.Append(" x ");

        num = size.b * editCtrl.levelData.sideMeasure; num.SimplifyImproper();
        mStrBuff.Append(num);
        mStrBuff.Append(measureStr);

        mStrBuff.Append('\n');

        volume.FractionToWhole();

        mStrBuff.Append(UnitMeasure.GetVolumeText(editCtrl.levelData.measureType, volume));

        detailText.text = mStrBuff.ToString();

        //display insufficient resources
        var availableCount = GridEditController.instance.GetAvailableCount();

        insufficientResourcesGO.SetActive(availableCount < 0);
    }
예제 #33
0
        public EvaluateData(List <GridEntity> aEntities)
        {
            if (aEntities != null)
            {
                entityEdits = new GridEntityEditController[aEntities.Count];
                for (int i = 0; i < aEntities.Count; i++)
                {
                    entityEdits[i] = aEntities[i].GetComponent <GridEntityEditController>();
                }
            }
            else
            {
                entityEdits = null;
            }

            var sideVal = GridEditController.instance.levelData.sideMeasure;

            var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            volume    = new MixedNumber();
            minHeight = instance.entityContainer.controller.cellSize.b * sideVal;
            maxHeight = new MixedNumber {
                whole = -1
            };

            for (int i = 0; i < entityEdits.Length; i++)
            {
                var entEdit = entityEdits[i];

                volume += entEdit.entity.volume;

                var height = entEdit.entity.cellSize.b * sideVal;

                if (height < minHeight)
                {
                    minHeight = height;
                }
                if (height > maxHeight)
                {
                    maxHeight = height;
                }

                var b = entEdit.entity.bounds;

                var lpos = entEdit.transform.localPosition;
                var bMin = lpos + b.min;
                var bMax = lpos + b.max;

                if (bMin.x < min.x)
                {
                    min.x = bMin.x;
                }
                if (bMin.y < min.y)
                {
                    min.y = bMin.y;
                }
                if (bMin.z < min.z)
                {
                    min.z = bMin.z;
                }

                if (bMax.x > max.x)
                {
                    max.x = bMax.x;
                }
                if (bMax.y > max.y)
                {
                    max.y = bMax.y;
                }
                if (bMax.z > max.z)
                {
                    max.z = bMax.z;
                }
            }

            volume.SimplifyImproper();
            //volume.Simplify();

            bounds     = new Bounds();
            bounds.min = min;
            bounds.max = max;
        }
예제 #34
0
    protected override IEnumerator Start()
    {
        yield return(base.Start());

        //enter both contestant
        playerControl.action = CombatCharacterController.Action.Enter;
        enemyControl.action  = CombatCharacterController.Action.Enter;

        while (playerControl.isBusy || enemyControl.isBusy)
        {
            yield return(null);
        }

        if (signalReady)
        {
            signalReady.Invoke();
        }
        //

        //wait for signal
        while (mIsBeginWait)
        {
            yield return(null);
        }

        //show vs. animation

        //some dialog/tutorial depending on level

        var waitReviveEndDelay = new WaitForSeconds(reviveEndDelay);

        //combat loop
        while (true)
        {
            mRoundCount++;

            /////////////////////////////////////
            //attack state
            if (attackControl)
            {
                attackControl.Init(playerControl, enemyControl);
                attackControl.Play();

                yield return(null);

                while (attackControl.isPlaying)
                {
                    yield return(null);
                }

                mAttackDamage += attackControl.attackTotalNumber;

                //check if enemy is dead
                if (enemyControl.hpCurrent <= 0f)
                {
                    break;
                }
            }
            /////////////////////////////////////

            /////////////////////////////////////
            //defend state
            if (defenseControl)
            {
                defenseControl.Init(enemyControl, playerControl);
                defenseControl.Play();

                yield return(null);

                while (defenseControl.isPlaying)
                {
                    yield return(null);
                }

                mDefenseAmount += defenseControl.defenseTotalNumber;

                //check if player is dead
                if (playerControl.hpCurrent <= 0f)
                {
                    //revive
                    mReviveCount++;

                    playerControl.action = CombatCharacterController.Action.Revive;
                    while (playerControl.isBusy)
                    {
                        yield return(null);
                    }

                    //animation of hp going back up
                    playerControl.hpWidget.Show();
                    while (playerControl.hpWidget.isBusy)
                    {
                        yield return(null);
                    }

                    playerControl.hpCurrent = playerControl.hpMax;

                    yield return(waitReviveEndDelay);

                    playerControl.hpWidget.Hide();
                }

                if (!attackControl) //only one round if no attack control
                {
                    break;
                }
            }
            /////////////////////////////////////

            yield return(null);
        }

        //player victory
        playerControl.action = CombatCharacterController.Action.Victory;

        while (playerControl.isBusy)
        {
            yield return(null);
        }

        var victoryInfo = new VictoryInfo();

        victoryInfo.toScene = nextScene;

        if (attackControl && mAttackDamage.fValue > 0f)
        {
            victoryInfo.attackValue = mAttackDamage;
            victoryInfo.flags      |= VictoryStatFlags.Attack;
        }

        if (defenseControl && mDefenseAmount.fValue > 0f)
        {
            victoryInfo.defenseValue = mDefenseAmount;
            victoryInfo.flags       |= VictoryStatFlags.Defense;
        }

        if (victoryRoundsEnabled)
        {
            victoryInfo.roundsCount = mRoundCount;
            victoryInfo.flags      |= VictoryStatFlags.Rounds;
        }

        if (victoryReviveEnabled && mReviveCount > 0)
        {
            victoryInfo.reviveCount = mReviveCount;
            victoryInfo.flags      |= VictoryStatFlags.Revive;
        }

        GameData.instance.OpenVictory(victoryInfo);
    }
예제 #35
0
        static void Main(string[] args)
        {
            string command;
            bool   quitNow = false;

            while (!quitNow)
            {
                Console.Write("input: ");
                command = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(command))
                {
                    continue;
                }

                command = command.Trim();
                if (command.ToLower() == "quit")
                {
                    break;
                }

                var inputs = command.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x));
                if (inputs.Count() != 3)
                {
                    Console.WriteLine("Incorrect input");
                    continue;
                }

                var ipArray = inputs.ToArray();
                if (ipArray[1] != "+" && ipArray[1] != "-" && ipArray[1] != "*" && ipArray[1] != "/")
                {
                    Console.WriteLine("Incorrect input");
                    continue;
                }

                try
                {
                    var one = new MixedNumber(ipArray[0]);
                    var two = new MixedNumber(ipArray[2]);

                    var result = string.Empty;
                    switch (ipArray[1])
                    {
                    case "+":
                        result = MixedNumberHelper.Add(one, two).ToString();
                        break;

                    case "-":
                        result = MixedNumberHelper.Subtract(one, two).ToString();
                        break;

                    case "*":
                        result = MixedNumberHelper.Multiply(one, two).ToString();
                        break;

                    case "/":
                        result = MixedNumberHelper.Divide(one, two).ToString();
                        break;
                    }

                    Console.WriteLine("output: {0}", result);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }