Ejemplo n.º 1
0
 private void InvalidateTextures(IdentifiedTwistData itd)
 {
     foreach (Cell master in itd.AffectedMasterCells)
     {
         m_renderToTexture.InvalidateTexture(master);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Scramble.
        /// </summary>
        /// <param name="numTwists"></param>
        public void Scramble(int numTwists)
        {
            System.Random rand = new System.Random();
            List <IdentifiedTwistData> allTwistData = m_puzzle.AllTwistData;

            if (allTwistData.Count == 0)
            {
                return;
            }

            bool earthquake = m_puzzle.Config.Earthquake;

            for (int i = 0; i < numTwists; i++)
            {
                m_currentTwist = new SingleTwist();
                m_currentTwist.IdentifiedTwistData = allTwistData[rand.Next(allTwistData.Count)];
                m_currentTwist.LeftClick           = rand.Next(2) == 1;

                // Try to avoid repeats of last (suggested by Melinda).
                IdentifiedTwistData last = m_twistHistory.AllTwists.Count == 0 ? null : m_twistHistory.AllTwists.Last().IdentifiedTwistData;
                if (last != null && allTwistData.Count > 2)
                {
                    while (last == m_currentTwist.IdentifiedTwistData)
                    {
                        m_currentTwist.IdentifiedTwistData = allTwistData[rand.Next(allTwistData.Count)];
                    }
                }
                else
                {
                    m_currentTwist.IdentifiedTwistData = allTwistData[rand.Next(allTwistData.Count)];
                }

                TwistData td          = m_currentTwist.IdentifiedTwistData.TwistDataForStateCalcs.First();
                int       numSlices   = td.NumSlices;
                int       randomSlice = rand.Next(numSlices);
                if (!earthquake)
                {
                    randomSlice += 1;
                }
                m_currentTwist.SliceMask = SliceMask.SliceToMask(randomSlice);

                if (earthquake)
                {
                    int       choppedSeg   = m_currentTwist.SliceMask * 2;
                    Vector3D  lookup       = td.Pants.TinyOffset(choppedSeg);
                    Vector3D  reflected    = td.Pants.Hexagon.Segments[choppedSeg].ReflectPoint(lookup);
                    TwistData tdEarthQuake = m_puzzle.ClosestTwistingCircles(reflected);

                    m_currentTwist.IdentifiedTwistDataEarthquake = tdEarthQuake.IdentifiedTwistData;

                    // Fix scrambing here.
                    m_currentTwist.SliceMaskEarthquake = tdEarthQuake.Pants.Closest(reflected) / 2;
                }

                // Apply the twist.
                FinishRotate(updateStatus: false);
            }

            m_twistHistory.Scrambles += numTwists;

            InvalidateAllAndUpdateStatus();
        }