Пример #1
0
    public void OnUndoButtonClicked()
    {
        if (piecesInZone.Count > 0 && (gapFilled < fractionData.Value))
        {
            int pieceIndex = piecesInZone.Count - 1;

            gapFilled -= piecesInZone[pieceIndex].Value;

            // animation of returning to inventory
            piecesInZone[pieceIndex].AnimatedPiece.transform.parent = null;
            piecesInZone[pieceIndex].AnimatedPiece.SetActive(true);

            // cleanup original object
            Destroy(piecesInZone[pieceIndex].gameObject);
            piecesInZone.RemoveAt(pieceIndex);

            // update visual
            if (gapMask.transform.localScale.x > 0)
            {
                gapMask.transform.localScale = new Vector3(4 * (1f - (float)(gapFilled / fractionData.Value)), 2, 1);
            }
            else
            {
                gapMask.transform.localScale = new Vector3(-4 * (1f - (float)(gapFilled / fractionData.Value)), 2, 1);
            }
            UpdateEquationUI();
        }
    }
Пример #2
0
    /// <summary>
    /// Creates a dictionary of keys 1-5
    /// For each level, takes every fraction combination from the previous level and adds an atomic fraction to it to generate the next level
    /// </summary>
    /// <returns>
    /// FractionDatabase consisting of a Dictionary with 5 levels of fraction combinations
    ///     Level 1: All fractions made up of adding 1 atomic fraction from 1/2 to 1/10
    ///     Level 2: All fractions made up of adding 2 atomic fraction
    /// </returns>
    private static FractionDatabase BuildFractionDatabase()
    {
        FractionDatabase database = new FractionDatabase();

        /* Create every combination of single pieces, two pieces, ..., up to a limit of 5 (for now?) */
        /* For each difficulty level (number of pieces) */
        List <FractionData> atomicList = new List <FractionData>();

        /* Build the atomicList of fractions with one component (atomic) */
        /* For every possible atomic fraction */
        for (int denominator = 2; denominator <= 10; denominator++)
        {
            FractionData data     = new FractionData();
            Fraction     fraction = new Fraction(1, denominator);
            data.Value += fraction;
            data.Components.Add(fraction);

            /* Add it to the atomicList */
            atomicList.Add(data);
        }
        database.Data.Add(1, atomicList);

        /* If more than one component needs to be generated, combine every item in atomicList with every possible atomic fraction */
        for (int numComponents = 2; numComponents <= 5; numComponents++)
        {
            List <FractionData> fractionList = new List <FractionData>();
            /* Loop through the previous difficulty level, adding every combination of atomic fraction */
            foreach (FractionData fractionFromPreviousLevel in database.Data[numComponents - 1])
            {
                /* For every possible atomic fraction */
                for (int denominator = 2; denominator <= 10; denominator++)
                {
                    Fraction fraction = new Fraction(1, denominator);

                    /* Only add the new fraction if the base is within 2-10 */
                    Fraction sum = fractionFromPreviousLevel.Value + fraction;
                    if (sum.denominator <= 10)
                    {
                        FractionData data = new FractionData(fractionFromPreviousLevel)
                        {
                            Value = sum
                        };
                        data.Components.Add(fraction);

                        /* Ensure this new item is unique (1/2 + 1/4 === 1/4 + 1/2) */
                        if (IsDistinct(data, fractionList))
                        {
                            /* Add this fraction data to the list */
                            fractionList.Add(data);
                        }
                    }
                }
            }
            /* Add the list of fractionData to the database */
            database.Data.Add(numComponents, fractionList);
        }

        return(database);
    }
Пример #3
0
 public void AtomizeFractionWithOnesTest()
 {
     FractionTools.Fraction   testFraction = new FractionTools.Fraction(1, 1);
     FractionTools.Fraction[] atoms        = FractionTools.AtomizeFraction(testFraction, true);
     Assert.IsNotNull(atoms, "AtomizeFraction did not return anything");
     Assert.IsTrue(testFraction.numerator == 1 && testFraction.denominator == 1, "AtomizeFraction mutated its input");
     Assert.IsTrue(atoms.Length == 1, "AtomizeFraction did not break into largest chunks, (returned " + atoms.Length + " items)");
     Assert.IsTrue(atoms[0].numerator == 1 && atoms[0].denominator == 1, "AtomizeFraction didn't return 1/1 as expected");
 }
Пример #4
0
 public void AtomizeFractionNoBreakingTest()
 {
     FractionTools.Fraction   testFraction = new FractionTools.Fraction(1, 12);
     FractionTools.Fraction[] atoms        = FractionTools.AtomizeFraction(testFraction);
     Assert.IsNotNull(atoms, "AtomizeFraction did not return anything");
     Assert.IsTrue(testFraction.numerator == 1 && testFraction.denominator == 12, "AtomizeFraction mutated its input");
     Assert.IsTrue(atoms.Length == 1, "AtomizeFraction broke an already atomic fratcion");
     Assert.IsTrue(atoms[0].numerator == 1 && atoms[0].denominator == 12, "AtomizeFraction didn't return 1/12 as expected");
 }
Пример #5
0
 public void AtomizeFractionLargestChunkTest()
 {
     FractionTools.Fraction   testFraction = new FractionTools.Fraction(16, 12);
     FractionTools.Fraction[] atoms        = FractionTools.AtomizeFraction(testFraction);
     Assert.IsNotNull(atoms, "AtomizeFraction did not return anything");
     Assert.IsTrue(testFraction.numerator == 16 && testFraction.denominator == 12, "AtomizeFraction mutated its input");
     Assert.IsTrue(atoms.Length == 2, "AtomizeFraction did not break into largest chunks");
     Assert.IsTrue(atoms[0].numerator == 1 && atoms[0].denominator == 1, "AtomizeFraction didn't return 1/1 as expected");
     Assert.IsTrue(atoms[1].numerator == 1 && atoms[1].denominator == 3, "AtomizeFraction didn't return 1/3 as expected");
 }
Пример #6
0
 void Start()
 {
     gc           = GameController.Instance;
     inv          = Inventory.Instance;
     value        = new FractionTools.Fraction(1, (int)length);
     sprite.color = Constants.trackColor;
     if (cuttableList)
     {
         myCuttables = Instantiate(cuttableList, inv.transform);
     }
 }
Пример #7
0
//    private Inventory inv;

    public bool TryPlacePiece(Placeable p)
    {
        //Debug.Log("Trying to place the piece...");
        //Debug.Log("Gap: " + fractionData.Value + ", piece:" + p.Value + ", filled: " + gapFilled);
        bool successful = false;

        if (p.Value + gapFilled <= fractionData.Value)
        {
            successful = true;
            EffectsManager.Instance.PlayEffect(EffectsManager.Effects.Correct);
            //SnapPiece(p);
            p.gameObject.SetActive(false);
            piecesInZone.Add(p);
            gapFilled += p.Value;
            if (gapMask.transform.localScale.x > 0)
            {
                gapMask.transform.localScale = new Vector3(4 * (1f - (float)(gapFilled / fractionData.Value)), 2, 1);
            }
            else
            {
                gapMask.transform.localScale = new Vector3(-4 * (1f - (float)(gapFilled / fractionData.Value)), 2, 1);
            }
            UpdateEquationUI();
            /* Check if the gap has been filled */
            //Debug.Log("Gap filled: " + gapFilled + ", gap size: " + fractionData.Value);
            if (gapFilled == fractionData.Value)
            {
                /* Disable the slow zone in case the coaster didn't even hit it yet (player was really quick) */
                if (slowDownTrigger != null)
                {
                    slowDownTrigger.SetActive(false);
                }
                /* Notify the GameController that a gap has been filled */
                StartCoroutine(GameController.Instance.OnGapFilled());
            }
        }
        else
        {
            Debug.Log("Piece doesn't want to take a fit! Gap filled: " + gapFilled + ", piece size: " + p.Value + ", gap size: " + fractionData.Value);
            EffectsManager.Instance.PlayEffect(EffectsManager.Effects.Incorrect);
        }

        return(successful);
    }
 public FractionData(FractionData toCopy)
 {
     Value      = new FractionTools.Fraction(toCopy.Value);
     Components = new List <FractionTools.Fraction>(toCopy.Components);
 }
 public FractionData()
 {
     Value      = FractionTools.Fraction.Zero;
     Components = new List <FractionTools.Fraction>();
 }