Example #1
0
    public static void PuzzleInit(int size = 3, int puzzleNumber = 0)
    {
        InitIconSets();
        if (Puzzle == null)
        {
            History    = new ActionHistory();
            PuzzleSize = size;
            Puzzle     = new LogicMatrix.Puzzle(puzzleNumber, PuzzleSize, 1);

            // Choose icon sets
            string[]      puzzleIconSets = new string[PuzzleSize];
            List <string> availableSets  = new List <string>(IconSets);
            for (int i = 0; i < PuzzleSize; i++)
            {
                int selection = Random.Range(0, availableSets.Count);
                puzzleIconSets[i] = availableSets[selection];
                availableSets.RemoveAt(selection);
            }

            // Load icon sets
            PuzzleIcons = new Sprite[PuzzleSize][];
            for (int i = 0; i < PuzzleSize; i++)
            {
                PuzzleIcons[i] = Resources.LoadAll <Sprite>(puzzleIconSets[i]);
            }
        }
    }
Example #2
0
        public static double LoadPuzzle(Puzzle P, int puzzleSize, int puzzleIndex)
        {
            double elapsedTime = 0;
            string saveName = PuzzleSaveName(puzzleSize, puzzleIndex);
            if (File.Exists(saveName))
            {
                FileStream fs = File.OpenRead(saveName);
                BinaryReader br = new BinaryReader(fs);

                int iVersion = br.ReadInt32();
                if (iVersion == m_iVersion)
                {
                    elapsedTime = br.ReadDouble();
                    for (int iRow = 0; iRow < P.m_iSize; iRow++)
                    {
                        for (int iCol = 0; iCol < P.m_iSize; iCol++)
                        {
                            for (int iIcon = 0; iIcon < P.m_iSize; iIcon++)
                            {
                                P.m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon] = br.ReadBoolean();
                            }
                            P.m_Rows[iRow].m_Cells[iCol].m_iFinalIcon = P.m_Rows[iRow].m_Cells[iCol].GetRemainingIcon();
                        }
                    }
                }

                br.Close();
                File.Delete(saveName);
            }

            return elapsedTime;
        }
Example #3
0
        public bool Init(Puzzle P, Clue C)
        {
            theClue = C;
            if (!theClue.GetHintAction(P, out m_bSetFinalIcon, out m_iRow, out m_iCol, out m_iIcon))
                return false;

            return true;
        }
Example #4
0
 public bool ShouldHide(Puzzle P)
 {
     if ((P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon == m_iIcon && m_bSetFinalIcon) ||
         (!P.m_Rows[m_iRow].m_Cells[m_iCol].m_bValues[m_iIcon] && !m_bSetFinalIcon))
     {
         return true;
     }
     return false;
 }
Example #5
0
        public Action(eActionType type, int iRow, int iCol, int iIcon, Puzzle P)
        {
            m_Type = type;
            m_iRow = iRow;
            m_iCol = iCol;
            m_iIcon = iIcon;

            SavePuzzle(P);
        }
Example #6
0
 public void Analyze(Puzzle P)
 {
     switch (m_Type)
     {
         case eClueType.Given:
             AnalyzeGiven(P);
             break;
         case eClueType.Vertical:
             AnalyzeVertical(P);
             break;
         case eClueType.Horizontal:
             AnalyzeHorizontal(P);
             break;
     }
 }
Example #7
0
 public void Perform(Puzzle P)
 {
     switch (m_Type)
     {
         case eActionType.eAT_EliminateIcon:
             P.EliminateIcon(m_iRow, m_iCol, m_iIcon);
             break;
         case eActionType.eAT_SetFinalIcon:
             P.SetFinalIcon(m_iRow, m_iCol, m_iIcon);
             break;
         case eActionType.eAT_RestoreIcon:
             P.m_Rows[m_iRow].m_Cells[m_iCol].m_bValues[m_iIcon] = true;
             P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon = P.m_Rows[m_iRow].m_Cells[m_iCol].GetRemainingIcon();
             break;
     }
 }
Example #8
0
        private void AnalyzeHorizontalLeftOf(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = P.m_Solution[m_iRow2, m_iCol2];

            int iFirstPossibleLeft = 0;
            for( iFirstPossibleLeft = 0; iFirstPossibleLeft < P.m_iSize; iFirstPossibleLeft++ )
            {
                if( P.m_Rows[m_iRow].m_Cells[iFirstPossibleLeft].m_bValues[iIcon1] )
                    break;
            }

            int iFirstPossibleRight = P.m_iSize - 1;
            for (iFirstPossibleRight = P.m_iSize - 1; iFirstPossibleRight >= 0; iFirstPossibleRight--)
            {
                if (P.m_Rows[m_iRow2].m_Cells[iFirstPossibleRight].m_bValues[iIcon2])
                    break;
            }

            if (iFirstPossibleLeft + 1 == iFirstPossibleRight)
            {
                // we have a solution for this clue
                P.SetFinalIcon(this, m_iRow, iFirstPossibleLeft, iIcon1);
                P.SetFinalIcon(this, m_iRow2, iFirstPossibleRight, iIcon2);
            }
            else
            {
                // Remove all icon2's from the left side of the first possible left
                for (int i = 0; i <= iFirstPossibleLeft; i++)
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);
                }

                // Remove all the icon1's from the right side of the first possible right
                for (int i = iFirstPossibleRight; i < P.m_iSize; i++)
                {
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                }
            }
        }
Example #9
0
        private void AnalyzeHorizontalNextTo(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = P.m_Solution[m_iRow2, m_iCol2];

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    if (i == 0)
                    {
                        P.SetFinalIcon(this, m_iRow2, 1, iIcon2);

                    }
                    else if (i == P.m_iSize - 1)
                    {
                        P.SetFinalIcon(this, m_iRow2, i - 1, iIcon2);

                    }
                    else
                    {
                        for (int j = 0; j < P.m_iSize; j++)
                        {
                            if (j == (i - 1) || j == (i + 1))
                                continue;
                            P.EliminateIcon(this, m_iRow2, j, iIcon2);

                        }
                    }
                    break;
                }
                else if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    if (i == 0)
                    {
                        P.SetFinalIcon(this, m_iRow, 1, iIcon1);

                    }
                    else if (i == P.m_iSize - 1)
                    {
                        P.SetFinalIcon(this, m_iRow, i - 1, iIcon1);

                    }
                    else
                    {
                        for (int j = 0; j < P.m_iSize; j++)
                        {
                            if (j == (i - 1) || j == (i + 1))
                                continue;
                            P.EliminateIcon(this, m_iRow, j, iIcon1);

                        }
                    }
                    break;
                }
                else
                {
                    if (i == 0)
                    {
                        if (!P.m_Rows[m_iRow2].m_Cells[i + 1].m_bValues[iIcon2])
                        {
                            P.EliminateIcon(this, m_iRow, i, iIcon1);

                        }
                        if (!P.m_Rows[m_iRow].m_Cells[i + 1].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, m_iRow2, i, iIcon2);

                        }
                    }
                    else if (i == P.m_iSize - 1)
                    {
                        if (!P.m_Rows[m_iRow2].m_Cells[i - 1].m_bValues[iIcon2])
                        {
                            P.EliminateIcon(this, m_iRow, i, iIcon1);

                        }
                        if (!P.m_Rows[m_iRow].m_Cells[i - 1].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, m_iRow2, i, iIcon2);

                        }
                    }
                    else
                    {
                        if (!P.m_Rows[m_iRow2].m_Cells[i + 1].m_bValues[iIcon2] &&
                            !P.m_Rows[m_iRow2].m_Cells[i - 1].m_bValues[iIcon2])
                        {
                            P.EliminateIcon(this, m_iRow, i, iIcon1);

                        }
                        if (!P.m_Rows[m_iRow].m_Cells[i + 1].m_bValues[iIcon1] &&
                            !P.m_Rows[m_iRow].m_Cells[i - 1].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, m_iRow2, i, iIcon2);

                        }
                    }
                }
            }
        }
Example #10
0
        private void GenerateHorizontal(Puzzle P, Random rand)
        {
            // Generate the horizontal type
            double dfVal = rand.NextDouble();
            if (dfVal <= 0.125)
            {
                m_HorizontalType = eHorizontalType.NextTo;

                while (true)
                {
                    // Pick first icon randomly
                    m_iRow = rand.Next(0, P.m_iSize);
                    m_iCol = rand.Next(0, P.m_iSize);

                    // Pick neighboring column
                    if (m_iCol == 0)
                        m_iCol2 = 1;
                    else if (m_iCol == (P.m_iSize - 1))
                        m_iCol2 = m_iCol - 1;
                    else
                    {
                        dfVal = rand.NextDouble();
                        if (dfVal <= 0.5f)
                            m_iCol2 = m_iCol - 1;
                        else
                            m_iCol2 = m_iCol + 1;
                    }

                    // Pick a neighboring row
                    m_iRow2 = rand.Next(0, P.m_iSize);

                    // Make sure this clue is useful
                    if (P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon < 0 ||
                        P.m_Rows[m_iRow2].m_Cells[m_iCol2].m_iFinalIcon < 0)
                        break;
                }
                m_iRow3 = m_iRow;
            }
            else if (dfVal <= 0.250)
            {
                m_HorizontalType = eHorizontalType.NotNextTo;

                // Pick first icon randomly
                m_iRow = rand.Next(0, P.m_iSize);
                m_iCol = rand.Next(0, P.m_iSize);

                // Pick a neighboring row
                m_iRow2 = rand.Next(0, P.m_iSize);

                // Pick an icon that is not in m_iRow2 on either side of m_iCol
                int iTries = 0;
                while (true)
                {
                    if (iTries++ > 25)
                    {
                        GenerateHorizontal(P, rand);
                        return;
                    }

                    // Pick one randomly
                    m_iHorizontal1 = rand.Next(0, P.m_iSize);

                    // Make sure its not the same as the first icon
                    if (m_iRow2 == m_iRow && P.m_Solution[m_iRow, m_iCol] == m_iHorizontal1)
                        continue;

                    // Make sure its not on the left of the first column
                    if (m_iCol > 0 && P.m_Solution[m_iRow2, m_iCol - 1] == m_iHorizontal1)
                        continue;

                    // Make sure its not on the right of the first column
                    if (m_iCol < (P.m_iSize - 1) && P.m_Solution[m_iRow2, m_iCol + 1] == m_iHorizontal1)
                        continue;

                    // This one looks fine
                    break;
                }
                m_iRow3 = m_iRow;
            }
            else if (dfVal <= 0.375)
            {
                m_HorizontalType = eHorizontalType.LeftOf;

                while (true)
                {
                    // Pick first icon randomly
                    m_iCol = rand.Next(0, P.m_iSize - 1);
                    m_iRow = rand.Next(0, P.m_iSize);

                    // Pick second icon
                    m_iCol2 = rand.Next(m_iCol + 1, P.m_iSize);
                    m_iRow2 = rand.Next(0, P.m_iSize);

                    // Make sure this is useful
                    if (P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon < 0 ||
                        P.m_Rows[m_iRow2].m_Cells[m_iCol2].m_iFinalIcon < 0)
                        break;
                }
            }
            else if (dfVal <= 0.500)
            {
                m_HorizontalType = eHorizontalType.NotLeftOf;

                int iTries = 0;
                while (true)
                {
                    // Pick first icon randomly
                    m_iCol = rand.Next(1, P.m_iSize);
                    m_iRow = rand.Next(0, P.m_iSize);

                    // Pick second icon
                    m_iCol2 = rand.Next(0, m_iCol);
                    m_iRow2 = rand.Next(0, P.m_iSize);

                    // Make sure this is useful
                    if (P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon < 0 ||
                        P.m_Rows[m_iRow2].m_Cells[m_iCol2].m_iFinalIcon < 0)
                        break;

                    iTries++;
                    if (iTries > 5)
                    {
                        GenerateClue(P, rand);
                        return;
                    }
                }
            }
            else if (dfVal <= 0.625)
            {
                m_HorizontalType = eHorizontalType.Span;

                GenerateHorizontalSpan(P, rand);
            }
            else if (dfVal <= 0.750)
            {
                m_HorizontalType = eHorizontalType.SpanNotLeft;

                GenerateHorizontalSpan(P, rand);

                // Find an icon that is not the correct icon for m_iCol
                int iTries = 0;
                while (true)
                {
                    if (iTries++ > 25)
                    {
                        GenerateHorizontal(P, rand);
                        return;
                    }

                    m_iHorizontal1 = rand.Next(0, P.m_iSize);

                    if (P.m_Solution[m_iRow, m_iCol] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow2, m_iCol2] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow3, m_iCol3] == m_iHorizontal1)
                        continue;

                    break;
                }
            }
            else if (dfVal <= 0.875)
            {
                m_HorizontalType = eHorizontalType.SpanNotMid;

                GenerateHorizontalSpan(P, rand);

                // Find an icon that is not the correct icon for m_iCol2
                int iTries = 0;
                while (true)
                {
                    if (iTries++ > 25)
                    {
                        GenerateHorizontal(P, rand);
                        return;
                    }

                    m_iHorizontal1 = rand.Next(0, P.m_iSize);

                    if (P.m_Solution[m_iRow, m_iCol] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow2, m_iCol2] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow3, m_iCol3] == m_iHorizontal1)
                        continue;

                    break;
                }
            }
            else
            {
                m_HorizontalType = eHorizontalType.SpanNotRight;

                GenerateHorizontalSpan(P, rand);

                // Find an icon that is not the correct icon for m_iCol3
                int iTries = 0;
                while (true)
                {
                    if (iTries++ > 25)
                    {
                        GenerateHorizontal(P, rand);
                        return;
                    }

                    m_iHorizontal1 = rand.Next(0, P.m_iSize);

                    if (P.m_Solution[m_iRow, m_iCol] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow2, m_iCol2] == m_iHorizontal1)
                        continue;

                    if (P.m_Solution[m_iRow3, m_iCol3] == m_iHorizontal1)
                        continue;

                    break;
                }
            }
        }
Example #11
0
        private void GenerateGiven(Puzzle P, Random rand)
        {
            bool bGoodRowCol = false;

            while (!bGoodRowCol)
            {
                // Pick a random row/col to give
                m_iRow = rand.Next(0, P.m_iSize);
                m_iCol = rand.Next(0, P.m_iSize);

                // Check to see if we should give this one
                if (P.m_Rows[m_iRow].m_Cells[m_iCol].m_iFinalIcon < 0)
                    bGoodRowCol = true;
            }
        }
Example #12
0
        private void GenerateClue(Puzzle p, Random rand)
        {
            // Pick the clue type randomly
            PickClueType(p, rand);

            // Generate the clue
            switch (m_Type)
            {
                case eClueType.Given:
                    GenerateGiven(p, rand);
                    break;
                case eClueType.Vertical:
                    GenerateVertical(p, rand);
                    break;
                case eClueType.Horizontal:
                    GenerateHorizontal(p, rand);
                    break;
            }
        }
Example #13
0
 public Clue(Puzzle p, Random rand)
 {
     GenerateClue(p, rand);
 }
Example #14
0
 private void AnalyzeHorizontal(Puzzle P)
 {
     switch (m_HorizontalType)
     {
         case eHorizontalType.NextTo:
             AnalyzeHorizontalNextTo(P);
             break;
         case eHorizontalType.NotNextTo:
             AnalyzeHorizontalNotNextTo(P);
             break;
         case eHorizontalType.LeftOf:
             AnalyzeHorizontalLeftOf(P);
             break;
         case eHorizontalType.NotLeftOf:
             AnalyzeHorizontalNotLeftOf(P);
             break;
         case eHorizontalType.Span:
             AnalyzeHorizontalSpan(P);
             break;
         case eHorizontalType.SpanNotLeft:
             AnalyzeHorizontalSpanNotLeft(P);
             break;
         case eHorizontalType.SpanNotMid:
             AnalyzeHorizontalSpanNotMid(P);
             break;
         case eHorizontalType.SpanNotRight:
             AnalyzeHorizontalSpanNotRight(P);
             break;
     }
 }
Example #15
0
        private void AnalyzeVerticalEitherOr(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = (m_iRow2 == m_iNotCell) ? m_iHorizontal1 : P.m_Solution[m_iRow2, m_iCol];
            int iIcon3 = (m_iRow3 == m_iNotCell) ? m_iHorizontal1 : P.m_Solution[m_iRow3, m_iCol];

            int iIcon2Col = -1;
            int iIcon3Col = -1;
            for( int i = 0; i < P.m_iSize; i++ )
            {
                if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    P.EliminateIcon(this, m_iRow3, i, iIcon3);
                    iIcon2Col = i;
                }
                if (P.m_Rows[m_iRow3].m_Cells[i].m_iFinalIcon == iIcon3)
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);
                    iIcon3Col = i;
                }
                if (!P.m_Rows[m_iRow2].m_Cells[i].m_bValues[iIcon2] &&
                    !P.m_Rows[m_iRow3].m_Cells[i].m_bValues[iIcon3])
                {
                    // If neither icon is in this column, icon1 cant be here either
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                }

                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    for (int j = 0; j < P.m_iSize; j++)
                    {
                        if( j == i )
                            continue;

                        if (P.m_Rows[m_iRow2].m_Cells[j].m_iFinalIcon == iIcon2)
                        {
                            P.SetFinalIcon(this, m_iRow3, i, iIcon3);
                        }
                        else if (P.m_Rows[m_iRow3].m_Cells[j].m_iFinalIcon == iIcon3)
                        {
                            P.SetFinalIcon(this, m_iRow2, i, iIcon2);
                        }
                    }
                }
            }

            if (iIcon2Col >= 0 && iIcon3Col >= 0)
            {
                for (int i = 0; i < P.m_iSize; i++)
                {
                    if (i != iIcon2Col && i != iIcon3Col)
                    {
                        P.EliminateIcon(this, m_iRow, i, iIcon1);
                    }
                }
            }
        }
Example #16
0
 private void SavePuzzle(Puzzle P)
 {
     m_SavedPuzzle = new bool[P.m_iSize, P.m_iSize, P.m_iSize];
     for (int iRow = 0; iRow < P.m_iSize; iRow++)
     {
         for (int iCol = 0; iCol < P.m_iSize; iCol++)
         {
             for (int i = 0; i < P.m_iSize; i++)
             {
                 m_SavedPuzzle[iRow, iCol, i] = P.m_Rows[iRow].m_Cells[iCol].m_bValues[i];
             }
         }
     }
 }
Example #17
0
 private void AnalyzeVertical(Puzzle P)
 {
     switch (m_VerticalType)
     {
         case eVerticalType.Two:
             AnalyzeVerticalTwo(P);
             break;
         case eVerticalType.Three:
             AnalyzeVerticalThree(P);
             break;
         case eVerticalType.EitherOr:
             AnalyzeVerticalEitherOr(P);
             break;
         case eVerticalType.TwoNot:
             AnalyzeVerticalTwoNot(P);
             break;
         case eVerticalType.ThreeTopNot:
             AnalyzeVerticalThreeTopNot(P);
             break;
         case eVerticalType.ThreeMidNot:
             AnalyzeVerticalThreeMidNot(P);
             break;
         case eVerticalType.ThreeBotNot:
             AnalyzeVerticalThreeBotNot(P);
             break;
     }
 }
Example #18
0
        private void AnalyzeHorizontalSpanNotRight(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = P.m_Solution[m_iRow2, m_iCol2];
            int iIcon3 = m_iHorizontal1;

            // Icon2 cant be on either end
            P.EliminateIcon(this, m_iRow2, 0, iIcon2);
            P.EliminateIcon(this, m_iRow2, P.m_iSize - 1, iIcon2);

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (SolveSpan(i, m_iRow, iIcon1, false, m_iRow2, iIcon2, false, m_iRow3, iIcon3, true, P))
                    return;
                if (SolveSpan(i, m_iRow3, iIcon3, true, m_iRow2, iIcon2, false, m_iRow, iIcon1, false, P))
                    return;
            }
        }
Example #19
0
        private void AnalyzeHorizontalSpanNotMid(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = m_iHorizontal1;
            int iIcon3 = P.m_Solution[m_iRow3, m_iCol3];

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (SolveSpan(i, m_iRow, iIcon1, false, m_iRow2, iIcon2, true, m_iRow3, iIcon3, false, P))
                    return;
                if (SolveSpan(i, m_iRow3, iIcon3, false, m_iRow2, iIcon2, true, m_iRow, iIcon1, false, P))
                    return;
            }
        }
Example #20
0
        public bool LoadPuzzle(out Puzzle P, out int iDifficulty, out int iPuzzleNumber)
        {
            bool bSuccess = false;

            P = null;
            iDifficulty = 0;
            iPuzzleNumber = 0;
            if (m_bIsValid)
            {
                #if XBOX
                StorageContainer container = m_Storage.OpenContainer("Happiness");
                string filename = Path.Combine(container.Path, "Happiness.sav");
                #else
                string filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Happiness\\Happiness.sav";
                #endif

                try
                {
                    BinaryReader br = new BinaryReader(File.OpenRead(filename));

                    int iVersion = br.ReadInt32();
                    if (iVersion == m_iVersion)
                    {
                        int iSeed = br.ReadInt32();
                        iDifficulty = iSeed & 0x3;
                        int iSize = ((iSeed >> 2) & 0x7) + 3;
                        iPuzzleNumber = iSeed;
                        P = new Puzzle(iSeed, iSize, iDifficulty);
                        for (int iRow = 0; iRow < P.m_iSize; iRow++)
                        {
                            for (int iCol = 0; iCol < P.m_iSize; iCol++)
                            {
                                for (int iIcon = 0; iIcon < P.m_iSize; iIcon++)
                                {
                                    P.m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon] = br.ReadBoolean();
                                }
                                P.m_Rows[iRow].m_Cells[iCol].m_iFinalIcon = P.m_Rows[iRow].m_Cells[iCol].GetRemainingIcon();
                            }
                        }

                        bSuccess = true;
                    }

                    br.Close();
                }
                finally
                {
            #if XBOX
                    if (container != null)
                        container.Dispose();
            #endif
                }
            }

            return bSuccess;
        }
Example #21
0
        private void AnalyzeHorizontalNotLeftOf(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = P.m_Solution[m_iRow2, m_iCol2];

            // If both icons are on the same row
            if (m_iRow == m_iRow2)
            {
                // Icon1 cant be in the zero column, because that would ensure that it is always left of Icon2
                P.EliminateIcon(this, m_iRow, 0, iIcon1);

                // Icon2 cant be in the last column, because that would ensure that it is always right of Icon1
                P.EliminateIcon(this, m_iRow2, P.m_iSize - 1, iIcon2);

            }

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    // Icon1 is known, remove all instances of icon2 to the right
                    for (int j = i + 1; j < P.m_iSize; j++)
                    {
                        P.EliminateIcon(this, m_iRow2, j, iIcon2);

                    }
                    break;
                }
                else if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    // Icon2 is known, remove all instances of icon1 to the left
                    for (int j = 0; j < i; j++)
                    {
                        P.EliminateIcon(this, m_iRow, j, iIcon1);

                    }
                    break;
                }
            }
        }
Example #22
0
        public bool SavePuzzle(Puzzle P)
        {
            bool bSuccess = false;
            if (DoesSaveGameExist(true))
            {
                #if XBOX
                StorageContainer container = m_Storage.OpenContainer("Happiness");
                string filename = Path.Combine(container.Path, "Happiness.sav");
                #else
                string filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Happiness\\Happiness.sav";
                #endif

                try
                {
                    BinaryWriter bw = new BinaryWriter(File.OpenWrite(filename));

                    bw.Write(m_iVersion);
                    bw.Write(P.m_iSeed);
                    for (int iRow = 0; iRow < P.m_iSize; iRow++)
                    {
                        for (int iCol = 0; iCol < P.m_iSize; iCol++)
                        {
                            for (int iIcon = 0; iIcon < P.m_iSize; iIcon++)
                            {
                                bw.Write(P.m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon]);
                            }
                        }
                    }
                    bw.Close();
                    bSuccess = true;
                    m_bIsValid = true;
                }
                finally
                {
            #if XBOX
                    if (container != null)
                        container.Dispose();
            #endif
                }
            }
            return bSuccess;
        }
Example #23
0
        private bool SolveSpan(int iCol, int iRow1, int iIcon1, bool bNot1, int iRow2, int iIcon2, bool bNot2, int iRow3, int iIcon3, bool bNot3, Puzzle P)
        {
            int iFinal1 = P.m_Rows[iRow1].m_Cells[iCol].m_iFinalIcon;
            if (iFinal1 == iIcon1)
            {
                if (iCol < 2)
                {
                    if (bNot1)
                    {
                        int iFinal2Right = P.m_Rows[iRow2].m_Cells[iCol + 1].m_iFinalIcon;
                        if (iFinal2Right == iIcon2)
                        {
                            P.SetFinalIcon(this, iRow3, iCol, iIcon3);

                        }
                    }
                    else
                    {
                        if (bNot2)
                        {
                            P.EliminateIcon(this, iRow2, iCol + 1, iIcon2);

                        }
                        else
                        {
                            P.SetFinalIcon(this, iRow2, iCol + 1, iIcon2);

                        }

                        if (bNot3)
                        {
                            P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);

                        }
                        else
                        {
                            P.SetFinalIcon(this, iRow3, iCol + 2, iIcon3);

                        }
                        return true;
                    }
                }
                else if (iCol > P.m_iSize - 3)
                {
                    if (bNot1)
                    {
                        int iFinal2Left = P.m_Rows[iRow2].m_Cells[iCol - 1].m_iFinalIcon;
                        if (iFinal2Left == iIcon2)
                        {
                            P.SetFinalIcon(this, iRow3, iCol, iIcon3);

                        }
                    }
                    else
                    {
                        if (bNot2)
                            P.EliminateIcon(this, iRow2, iCol - 1, iIcon2);
                        else
                            P.SetFinalIcon(this, iRow2, iCol - 1, iIcon2);

                        if (bNot3)
                            P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);
                        else
                            P.SetFinalIcon(this, iRow3, iCol - 2, iIcon3);

                        return true;
                    }
                }
                else
                {
                    int iFinal2Left = P.m_Rows[iRow2].m_Cells[iCol - 1].m_iFinalIcon;
                    int iFinal2Right = P.m_Rows[iRow2].m_Cells[iCol + 1].m_iFinalIcon;
                    if (iFinal2Left == iIcon2)
                    {
                        if (bNot1)
                        {
                            P.SetFinalIcon(this, iRow3, iCol, iIcon3);

                        }
                        else if (bNot2)
                        {
                            P.SetFinalIcon(this, iRow3, iCol + 2, iIcon3);

                        }
                        else if (bNot3)
                        {
                            P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);

                        }
                        else
                        {
                            P.SetFinalIcon(this, iRow3, iCol - 2, iIcon3);

                        }
                        return true;
                    }
                    else if (iFinal2Right == iIcon2)
                    {
                        if (bNot1)
                        {
                            P.SetFinalIcon(this, iRow3, iCol, iIcon3);

                        }
                        else if (bNot2)
                        {
                            P.SetFinalIcon(this, iRow3, iCol - 2, iIcon3);

                        }
                        else if (bNot3)
                        {
                            P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);

                        }
                        else
                        {
                            P.SetFinalIcon(this, iRow3, iCol + 2, iIcon3);

                        }
                        return true;
                    }
                    else if (!P.m_Rows[iRow2].m_Cells[iCol - 1].m_bValues[iIcon2] && !bNot1 && !bNot2)
                    {
                        P.SetFinalIcon(this, iRow2, iCol + 1, iIcon2);
                        if (bNot3)
                            P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);
                        else
                            P.SetFinalIcon(this, iRow3, iCol + 2, iIcon3);

                        return true;
                    }
                    else if (!P.m_Rows[iRow2].m_Cells[iCol + 1].m_bValues[iIcon2] && !bNot1 && !bNot2)
                    {
                        P.SetFinalIcon(this, iRow2, iCol - 1, iIcon2);
                        if (bNot3)
                            P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);
                        else
                            P.SetFinalIcon(this, iRow3, iCol - 2, iIcon3);

                        return true;
                    }
                    else if (!bNot3)
                    {
                        int iFinal3Left = P.m_Rows[iRow3].m_Cells[iCol - 2].m_iFinalIcon;
                        int iFinal3Right = P.m_Rows[iRow3].m_Cells[iCol + 2].m_iFinalIcon;
                        if (iFinal3Left == iIcon3)
                        {
                            if (bNot1)
                            {
                                P.SetFinalIcon(this, iRow2, iCol - 3, iIcon2);

                                return true;
                            }
                            else if (bNot2)
                            {
                                P.EliminateIcon(this, iRow2, iCol - 1, iIcon2);

                            }
                            else
                            {
                                P.SetFinalIcon(this, iRow2, iCol - 1, iIcon2);

                                return true;
                            }
                        }
                        else if (iFinal3Right == iIcon3)
                        {
                            if (bNot1)
                            {
                                P.SetFinalIcon(this, iRow2, iCol + 3, iIcon2);

                                return true;
                            }
                            else if (bNot2)
                            {
                                P.EliminateIcon(this, iRow2, iCol + 1, iIcon2);

                            }
                            else
                            {
                                P.SetFinalIcon(this, iRow2, iCol + 1, iIcon2);

                                return true;
                            }
                        }
                        else if (!P.m_Rows[iRow3].m_Cells[iCol - 2].m_bValues[iIcon3] && !bNot1 && !bNot2)
                        {
                            P.SetFinalIcon(this, iRow2, iCol + 1, iIcon2);
                            P.SetFinalIcon(this, iRow3, iCol + 2, iIcon3);

                            return true;
                        }
                        else if (!P.m_Rows[iRow3].m_Cells[iCol + 2].m_bValues[iIcon3] && !bNot1 && !bNot2)
                        {
                            P.SetFinalIcon(this, iRow2, iCol - 1, iIcon2);
                            P.SetFinalIcon(this, iRow3, iCol - 2, iIcon3);

                            return true;
                        }
                        else if( !bNot1 )
                        {
                            for (int j = 0; j < P.m_iSize; j++)
                            {
                                if (!bNot2 && j != (iCol - 1) && j != (iCol + 1))
                                {
                                    P.EliminateIcon(this, iRow2, j, iIcon2);

                                }
                                if (j != (iCol - 2) && j != (iCol + 2))
                                {
                                    P.EliminateIcon(this, iRow3, j, iIcon3);

                                }
                            }
                        }
                    }
                }
            }
            else if (iFinal1 >= 0 && !bNot1 && !bNot2 && !bNot3)
            {
                int iFinal3 = P.m_Rows[iRow3].m_Cells[iCol].m_iFinalIcon;
                if (iFinal3 != iIcon3 && iFinal3 >= 0)
                {
                    if (iCol == 0)
                    {
                        P.EliminateIcon(this, iRow2, iCol + 1, iIcon2);

                    }
                    else if (iCol == P.m_iSize - 1)
                    {
                        P.EliminateIcon(this, iRow2, iCol - 1, iIcon2);

                    }
                    else if (iCol == P.m_iSize - 3)
                    {
                        P.EliminateIcon(this, iRow1, iCol + 2, iIcon1);
                        P.EliminateIcon(this, iRow2, iCol + 1, iIcon2);
                        P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);

                    }
                    else if (iCol == 2)
                    {
                        P.EliminateIcon(this, iRow1, iCol - 2, iIcon1);
                        P.EliminateIcon(this, iRow2, iCol - 1, iIcon2);
                        P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);

                    }
                }
            }
            if (!P.m_Rows[iRow1].m_Cells[iCol].m_bValues[iIcon1] && !bNot1)
            {
                if (!bNot3)
                {
                    if (iCol + 4 < P.m_iSize)
                    {
                        if (!P.m_Rows[iRow1].m_Cells[iCol + 4].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);
                        }
                    }
                    else if (iCol + 2 < P.m_iSize)
                    {
                        P.EliminateIcon(this, iRow3, iCol + 2, iIcon3);
                    }
                    if (iCol - 4 >= 0)
                    {
                        if (!P.m_Rows[iRow1].m_Cells[iCol - 4].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);
                        }
                    }
                    else if (iCol - 2 >= 0)
                    {
                        P.EliminateIcon(this, iRow3, iCol - 2, iIcon3);
                    }
                }
                if (!bNot2)
                {
                    if (iCol + 2 < P.m_iSize)
                    {
                        if (!P.m_Rows[iRow1].m_Cells[iCol + 2].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, iRow2, iCol + 1, iIcon2);
                        }
                    }
                    if (iCol - 2 >= 0)
                    {
                        if (!P.m_Rows[iRow1].m_Cells[iCol - 2].m_bValues[iIcon1])
                        {
                            P.EliminateIcon(this, iRow2, iCol - 1, iIcon2);
                        }
                    }
                }
            }
            if (P.m_Rows[iRow2].m_Cells[iCol].m_iFinalIcon == iIcon2 && !bNot2)
            {
                // Middle icon is known, eliminate impossible end icons
                for (int i = 0; i < P.m_iSize; i++)
                {
                    if (i != iCol - 1 && i != iCol + 1)
                    {
                        if (!bNot1)
                            P.EliminateIcon(this, iRow1, i, iIcon1);
                        if (!bNot3)
                            P.EliminateIcon(this, iRow3, i, iIcon3);
                    }
                }
            }

            return false;
        }
Example #24
0
        public static void SavePuzzle(Puzzle P, int puzzleIndex, double elapsedSeconds)
        {
            string saveName = PuzzleSaveName(P.m_iSize, puzzleIndex);
            FileStream fs = File.Open(saveName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(m_iVersion);
            bw.Write(elapsedSeconds);
            for (int iRow = 0; iRow < P.m_iSize; iRow++)
            {
                for (int iCol = 0; iCol < P.m_iSize; iCol++)
                {
                    for (int iIcon = 0; iIcon < P.m_iSize; iIcon++)
                    {
                        bw.Write(P.m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon]);
                    }
                }
            }
            bw.Close();
        }
Example #25
0
        private void AnalyzeHorizontalNotNextTo(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = m_iHorizontal1;

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    if (i == 0)
                    {
                        P.EliminateIcon(this, m_iRow2, i + 1, iIcon2);

                    }
                    else if (i == P.m_iSize - 1)
                    {
                        P.EliminateIcon(this, m_iRow2, i - 1, iIcon2);

                    }
                    else
                    {
                        P.EliminateIcon(this, m_iRow2, i - 1, iIcon2);
                        P.EliminateIcon(this, m_iRow2, i + 1, iIcon2);

                    }
                    break;
                }
                else if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    if (i == 0)
                    {
                        P.EliminateIcon(this, m_iRow, i + 1, iIcon1);

                    }
                    else if (i == P.m_iSize - 1)
                    {
                        P.EliminateIcon(this, m_iRow, i - 1, iIcon1);

                    }
                    else
                    {
                        P.EliminateIcon(this, m_iRow, i - 1, iIcon1);
                        P.EliminateIcon(this, m_iRow, i + 1, iIcon1);

                    }
                    break;
                }
            }
        }
Example #26
0
        private void AnalyzeVerticalThreeMidNot(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = m_iNotCell;
            int iIcon3 = P.m_Solution[m_iRow3, m_iCol];

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                    P.EliminateIcon(this, m_iRow3, i, iIcon3);

                }
                else if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);
                    P.SetFinalIcon(this, m_iRow3, i, iIcon3);
                    return;
                }
                else if (P.m_Rows[m_iRow3].m_Cells[i].m_iFinalIcon == iIcon3)
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);
                    P.SetFinalIcon(this, m_iRow, i, iIcon1);
                    return;
                }
                else if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon >= 0)
                {
                    P.EliminateIcon(this, m_iRow3, i, iIcon3);
                }
                else if (P.m_Rows[m_iRow3].m_Cells[i].m_iFinalIcon >= 0)
                {
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                }
            }
        }
Example #27
0
        private void AnalyzeVerticalTwo(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = P.m_Solution[m_iRow2, m_iCol];
            for (int i = 0; i < P.m_iSize; i++)
            {
                if (!P.m_Rows[m_iRow].m_Cells[i].m_bValues[iIcon1])
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);
                }
                else if (!P.m_Rows[m_iRow2].m_Cells[i].m_bValues[iIcon2])
                {
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                }

                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    P.SetFinalIcon(this, m_iRow2, i, iIcon2);
                    return;
                }
                else if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    P.SetFinalIcon(this, m_iRow, i, iIcon1);
                    return;
                }
            }
        }
Example #28
0
 public void Revert(Puzzle P)
 {
     for (int iRow = 0; iRow < P.m_iSize; iRow++)
     {
         for (int iCol = 0; iCol < P.m_iSize; iCol++)
         {
             for (int iIcon = 0; iIcon < P.m_iSize; iIcon++)
             {
                 P.m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon] = m_SavedPuzzle[iRow, iCol, iIcon];
             }
             P.m_Rows[iRow].m_Cells[iCol].m_iFinalIcon = P.m_Rows[iRow].m_Cells[iCol].GetRemainingIcon();
         }
     }
 }
Example #29
0
        private void AnalyzeVerticalTwoNot(Puzzle P)
        {
            int iIcon1 = P.m_Solution[m_iRow, m_iCol];
            int iIcon2 = m_iNotCell;

            for (int i = 0; i < P.m_iSize; i++)
            {
                if (P.m_Rows[m_iRow].m_Cells[i].m_iFinalIcon == iIcon1)
                {
                    P.EliminateIcon(this, m_iRow2, i, iIcon2);

                }
                else if (P.m_Rows[m_iRow2].m_Cells[i].m_iFinalIcon == iIcon2)
                {
                    P.EliminateIcon(this, m_iRow, i, iIcon1);
                }
            }
        }
Example #30
0
        public void Initialize(int puzzleIndex, int puzzleSize, bool load)
        {
            m_PuzzleStart = DateTime.Now;
            m_PauseSeconds = 0;
            m_bVerifyHintPurchase = true;
            m_bVerifyMegaHintPurchase = true;
            m_iHintCount = 0;
            m_iMegaHintCount = 0;
            m_History = new List<Action>();

            // Create the puzzle
            m_iPuzzleIndex = puzzleIndex;
            m_Puzzle = new Puzzle(puzzleIndex, puzzleSize, 1);
            if( load )
                LoadPuzzle();

            // Initialize the UI
            int buttonPanelWidth = (int)(Constants.ButtonPanel_Width * Game.ScreenWidth);
            int helpPanelHeight = (int)(Constants.HelpPanel_Height * Game.ScreenHeight);
            m_HorizontalCluePanel = new HorizontalCluePanel(this, m_Puzzle.HorizontalClues);
            m_VerticalCluePanel = new VerticalCluePanel(this, m_Puzzle.VerticalClues, Game.ScreenWidth - m_HorizontalCluePanel.Rect.Width);
            m_GamePanel = new GamePanel(this, new Rectangle(buttonPanelWidth, helpPanelHeight, Game.ScreenWidth - (m_HorizontalCluePanel.Rect.Width + buttonPanelWidth), Game.ScreenHeight - (m_VerticalCluePanel.Rect.Height + helpPanelHeight)));
            m_HelpPanel = new HelpPanel(this, new Rectangle(buttonPanelWidth, 0, m_GamePanel.Rect.Width, m_GamePanel.Rect.Top));
            m_ButtonPanel = new ButtonPanel(this, new Rectangle(0, 0, buttonPanelWidth, m_VerticalCluePanel.Rect.Top));

            HappinessNetwork.VipDataArgs vip = NetworkManager.Net.VipData;
            m_ButtonPanel.SetHintCount(vip.Hints - m_iHintCount, vip.Hints);
            m_ButtonPanel.SetMegaHintCount(vip.MegaHints - m_iMegaHintCount, vip.MegaHints);
            m_ButtonPanel.SetUndoCount(m_History.Count, vip.UndoSize);
            m_ButtonPanel.SetCoins(NetworkManager.Net.HardCurrency);

            m_UIPanels = new List<UIPanel>();
            m_UIPanels.Add(m_GamePanel);
            m_UIPanels.Add(m_HorizontalCluePanel);
            m_UIPanels.Add(m_VerticalCluePanel);
            m_UIPanels.Add(m_HelpPanel);
            m_UIPanels.Add(m_ButtonPanel);

            // Init Icons
            InitIcons();

            int gamePanelCenterX = m_GamePanel.Rect.Left + (m_GamePanel.Rect.Width / 6);
            Vector2 clueArrow = new Vector2(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight >> 1));
            Rectangle bottomTutorialRect = new Rectangle(gamePanelCenterX + Game.Tutorial.ArrowHeight, m_GamePanel.Rect.Bottom + 10, m_GamePanel.Rect.Width - ((m_GamePanel.Rect.Width / 6) + (Game.Tutorial.ArrowHeight >> 1)), 0);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.GameStart, new Vector2(gamePanelCenterX, m_GamePanel.Rect.Bottom), Constants.ArrowUp,
                                                                               bottomTutorialRect, "The object of the game is to figure out which icon belongs in each cell of the puzzle grid area.\nThe puzzle is solved when all of the icons are in the correct places.",
                                                                               TutorialSystem.TutorialPiece.HorizontalClueArea, Rectangle.Empty, true);
            Rectangle clue1Area = new Rectangle(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top, m_HorizontalCluePanel.Rect.Width, m_HorizontalCluePanel.ClueHeight);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClueArea, clueArrow, 0,
                bottomTutorialRect, "This area is for the horizontal clues.\nHorizontal clues give hints about the icons from left to right or right to left.\n\nTap this first Horizontal Clue.",
                TutorialSystem.TutorialPiece.SpanExplanation, clue1Area);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.SpanExplanation, clueArrow, 0,
                bottomTutorialRect, "The arrow across the top of the clue indicates that this is a span clue.\nA span clue describes a series of 3 neighboring columns. The span can go from left to right or right to left but the center column will always be inbetween the two outer columns.",
                TutorialSystem.TutorialPiece.ClueHelp, Rectangle.Empty, true);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.ClueHelp, new Vector2(m_HelpPanel.Rect.Left, m_HelpPanel.Rect.Bottom), Constants.ArrowDiagonalUpRight,
                bottomTutorialRect, "This area gives a brief description of the currently highlighted clue.\n\nSince this clue is a span type clue, it is showing that in a group of 3 columns {icon:Simpsons[2]} is on one edge of the group and {icon:Superheros[3]} is on the other edge.\nSince there is a NOT icon in the center of this span, in the center column can not have the {icon:Hubble[4]}.",
                TutorialSystem.TutorialPiece.SpanHelp1, Rectangle.Empty, true);

            Rectangle centerGridArea = new Rectangle(m_GamePanel.Rect.Left + m_GamePanel.CellWidth, m_GamePanel.Rect.Top + m_GamePanel.CellHeight, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.SpanHelp1, m_GamePanel.IconPosition(1, 1, 1), Constants.ArrowDiagonalUpRight,
                bottomTutorialRect, "This is a 3x3 puzzle so the center column of this span has to be the center column of this puzzle.\nWe can eliminate the {icon:Hubble[4]} from the center column.\n\nTap the center grid area.",
                TutorialSystem.TutorialPiece.EliminateRedNebula, centerGridArea);

            Rectangle centerBottomGridArea = new Rectangle(m_GamePanel.Rect.Left + m_GamePanel.CellWidth, m_GamePanel.Rect.Top + (m_GamePanel.CellHeight * 2), m_GamePanel.CellWidth, m_GamePanel.CellHeight);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.BartMan1, m_GamePanel.IconPosition(2, 1, 1), Constants.ArrowDown,
                bottomTutorialRect, "The {icon:Simpsons[2]} has to be on one of the edges of the column group so it can not be in the center column.\n\nTap the bottom grid area of the center column.",
                TutorialSystem.TutorialPiece.BartMan2, centerBottomGridArea);

            Rectangle centerTopGridArea = new Rectangle(m_GamePanel.Rect.Left + m_GamePanel.CellWidth, m_GamePanel.Rect.Top, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
            Vector2 iconBotOffset = new Vector2(m_GamePanel.IconSize >> 1, 0);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hulk1, Vector2.Add(m_GamePanel.IconPosition(0, 1, 0), iconBotOffset), Constants.ArrowUp,
                bottomTutorialRect, "The {icon:Superheros[3]} has to be on one of the edges of the column group so it can not be in the center column.\n\nTap the top grid area of the center column.",
                TutorialSystem.TutorialPiece.Hulk2, centerTopGridArea);

            Vector2 clue2Position = new Vector2(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight) + (m_HorizontalCluePanel.ClueHeight >> 1));
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue2a, clue2Position, 0,
                bottomTutorialRect, "We have done all we can right now with the first clue.\nLets move on to the next clue.\n\nTap the second horizontal clue.",
                TutorialSystem.TutorialPiece.HorizontalClue2b, new Rectangle(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight), m_HorizontalCluePanel.Rect.Width, m_HorizontalCluePanel.ClueHeight));

            Vector2 iconTopOffset = new Vector2(m_GamePanel.IconSize >> 1, -m_GamePanel.IconSize);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue2b, Vector2.Add(m_GamePanel.IconPosition(1, 1, 2), iconTopOffset), Constants.ArrowDown,
                bottomTutorialRect, "This clue is also a span type clue with the {icon:Hubble[2]} in the center column, the {icon:Superheros[2]} on one edge and NOT the {icon:Hubble[3]} on the other edge.\nSince this is a 3x3 puzzle, we know the center of the span is the center column of the puzzle so we now know where the {icon:Hubble[2]} goes.\n\nTap the center grid area.",
                TutorialSystem.TutorialPiece.CrabNebula1, centerGridArea);

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue2c, Vector2.Add(m_GamePanel.IconPosition(0, 1, 2), iconTopOffset), Constants.ArrowDown, bottomTutorialRect,
                "We know that the {icon:Superheros[2]} has to be on one of the outer edges, so it cant be in the center column.\n\nTap the top grid area of the center column.", TutorialSystem.TutorialPiece.GreenLantern1, centerTopGridArea);

            Vector2 iconSideOffset = new Vector2(0, -(m_GamePanel.IconSize >> 1));
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue2d, m_GamePanel.IconPosition(0, 1, 0), 0, bottomTutorialRect,
                "Notice that the {icon:Superheros[4]} is confirmed in the center column now. This is because it was the only posibility left after eliminating the {icon:Superheros[3]} and the {icon:Superheros[2]}.",
                TutorialSystem.TutorialPiece.HorizontalClue3a, Rectangle.Empty, true);

            Vector2 clueHeightOffset = new Vector2(0, m_HorizontalCluePanel.ClueHeight);
            Vector2 clue3Position = Vector2.Add(clue2Position, clueHeightOffset);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue3a, clue3Position, 0, bottomTutorialRect, "There is nothing else we can do with this clue for now so lets move on to the next clue.\n\nTap the third horizontal clue.\n", TutorialSystem.TutorialPiece.HorizontalClue3b,
                new Rectangle(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight * 2), m_HorizontalCluePanel.Rect.Width, m_HorizontalCluePanel.ClueHeight));

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue3b, m_GamePanel.IconPosition(2, 1, 0), Constants.ArrowDiagonalUpRight, bottomTutorialRect,
                "This is another span type clue. Most of what it is telling us, we already know. It is however telling us that the {icon:Simpsons[3]} is in the center column.\n\nTap the bottom grid area of the center column.",
                TutorialSystem.TutorialPiece.Homer1, centerBottomGridArea);

            Vector2 clue4Position = Vector2.Add(clue3Position, clueHeightOffset);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue4, clue4Position, 0, bottomTutorialRect, "The fourth clue doesn't have any useful information for us right now since we already know the {icon:Superheros[4]} is in the center column and we dont know where either the {icon:Hubble[4]} or the {icon:Superheros[2]} are.", TutorialSystem.TutorialPiece.HorizontalClue5a, Rectangle.Empty, true);

            Vector2 clue5Position = Vector2.Add(clue4Position, clueHeightOffset);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue5a, clue5Position, 0, bottomTutorialRect, "Tap the fifth clue to select it.", TutorialSystem.TutorialPiece.HorizontalClue5b,
                new Rectangle(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight * 4), m_HorizontalCluePanel.Rect.Width, m_HorizontalCluePanel.ClueHeight));

            Rectangle rightTopGridArea = new Rectangle(m_GamePanel.Rect.Right - m_GamePanel.CellWidth, m_GamePanel.Rect.Top, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue5b, Vector2.Add(iconSideOffset, m_GamePanel.IconPosition(0, 2, 2)), 0, bottomTutorialRect,
                "This clue tells us that the {icon:Superheros[2]} is in a column somewhere to the right of the {icon:Simpsons[3]}.\nSince we already know where the {icon:Simpsons[3]} is, and there is only one column to the right of it, we know where the {icon:Superheros[2]} is.\n\nTap the top right grid cell.", TutorialSystem.TutorialPiece.GreenLantern4, rightTopGridArea);

            bool online = !NetworkManager.Net.Disabled;

            Vector2 hideClueTarget = new Vector2(m_ButtonPanel.HideClueRect.Right, m_ButtonPanel.HideClueRect.Top + (m_ButtonPanel.HideClueRect.Height >> 1));
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HideClue1, hideClueTarget, Constants.ArrowLeft, bottomTutorialRect,
                "We have learned all we possibly can from this clue since we know where both the {icon:Simpsons[3]} and the {icon:Superheros[2]} are.\nWe can now hide this clue so we can more easily see the relevant clues.\nYou can unhide all the clues anytime you want in the pause menu.\n\nTap the 'HC' button to hide this clue.",
                online ? TutorialSystem.TutorialPiece.Hint1 : TutorialSystem.TutorialPiece.Hint2, m_ButtonPanel.HideClueRect);

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hint1, new Vector2(m_ButtonPanel.HintRect.Right, m_ButtonPanel.HintRect.Top + (m_ButtonPanel.HintRect.Height >> 1)), Constants.ArrowLeft, bottomTutorialRect,
                "If you get stuck on a puzzle you can spend {icon:GoldCoin}2 to get a hint of what to do next.\nThere are a maximum number of hints you can use per puzzle, this number increases with your VIP level.\n\nTap the 'H' button to get a hint.", TutorialSystem.TutorialPiece.Hint2, m_ButtonPanel.HintRect);

            if (online)
            {
                m_MessageBox = new MessageBox("Would you like to spend 2 coins for a hint?", MessageBoxButtons.YesNo, (int)MessageBoxContext.InsufficientFunds_Hint, Game.ScreenWidth, Game.ScreenHeight, "Don't ask again");
                Rectangle hintYes = m_MessageBox.GetButtonRect(0);
                m_MessageBox = null;
                Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hint2, m_GamePanel.IconPosition(2, 1, 0), Constants.ArrowDiagonalUpRight, bottomTutorialRect,
                    "When you tap the hint button, you are asked for confirmation before proceding. You can skip this confirmation for the rest of the puzzle by tapping the checkbox. If the box remains unchecked, you will be asked to confirm each hint used in this puzzle.\n\nTap the 'Yes' button to confirm we want a hint.",
                    TutorialSystem.TutorialPiece.Hint3, hintYes);

                Rectangle rightBottomGridArea = new Rectangle(m_GamePanel.Rect.Right - m_GamePanel.CellWidth, m_GamePanel.Rect.Bottom - m_GamePanel.CellHeight, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
                Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hint3, Vector2.Add(iconTopOffset, m_GamePanel.IconPosition(2, 2, 2)), Constants.ArrowDown, bottomTutorialRect,
                    "The hint is showing us that this clue should effect the {icon:Simpsons[2]} in the third column.\nThis span clue has the {icon:Superheros[3]} on one edge of the span and the {icon:Simpsons[2]} on the other edge. Since we know the {icon:Superheros[3]} is in the first column, the {icon:Simpsons[2]} belongs in the third column.\n\nTap the bottom right grid cell.",
                    TutorialSystem.TutorialPiece.Bartman5, rightBottomGridArea);
            }
            else
            {
                Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hint2, clueArrow, 0, bottomTutorialRect,
                    "Tap the first clue to select it again.",
                    TutorialSystem.TutorialPiece.Hint3, clue1Area);

                Rectangle rightBottomGridArea = new Rectangle(m_GamePanel.Rect.Right - m_GamePanel.CellWidth, m_GamePanel.Rect.Bottom - m_GamePanel.CellHeight, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
                Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Hint3, Vector2.Add(iconTopOffset, m_GamePanel.IconPosition(2, 2, 2)), Constants.ArrowDown, bottomTutorialRect,
                    "This span clue has the {icon:Superheros[3]} on one edge of the span and the {icon:Simpsons[2]} on the other edge. Since we know the {icon:Superheros[3]} is in the first column, the {icon:Simpsons[2]} belongs in the third column.\n\nTap the bottom right grid cell.",
                    TutorialSystem.TutorialPiece.Bartman5, rightBottomGridArea);
            }

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Undo, new Vector2(m_ButtonPanel.UndoRect.Right, m_ButtonPanel.UndoRect.Top + (m_ButtonPanel.UndoRect.Height >> 1)), Constants.ArrowLeft, bottomTutorialRect,
                "If you make a mistake, you can undo previous actions by tapping the 'U' button.\nThere are a limited number of actions that you can undo indicated by the number under the 'U' button. The number on the left is the number of actions currently in the history. The number on the right is the maximum number of actions stored in the history. The maximum increases with your VIP level.",
                TutorialSystem.TutorialPiece.HorizontalClue4b, Rectangle.Empty, true);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue4b, clue4Position, 0, bottomTutorialRect,
                "There are only two cells left to solve. We need to figure out which cells the {icon:Hubble[4]} and the {icon:Hubble[3]} belong in.\nLets go back to the fourth horizontal clue.\n\nTap the fourth horizontal clue.\n",
                TutorialSystem.TutorialPiece.HorizontalClue4c, new Rectangle(m_HorizontalCluePanel.Rect.Left, m_HorizontalCluePanel.Rect.Top + (m_HorizontalCluePanel.ClueHeight * 3), m_HorizontalCluePanel.Rect.Width, m_HorizontalCluePanel.ClueHeight));

            Rectangle rightCenterGridArea = new Rectangle(m_GamePanel.Rect.Right - m_GamePanel.CellWidth, m_GamePanel.Rect.Top + m_GamePanel.CellHeight, m_GamePanel.CellWidth, m_GamePanel.CellHeight);
            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.HorizontalClue4c, m_GamePanel.IconPosition(1, 2, 1), Constants.ArrowDiagonalUpRight, bottomTutorialRect,
                "This clue is telling us that the {icon:Superheros[4]} has the {icon:Hubble[4]} on one side and NOT the {icon:Superheros[3]} on the other side.\nSince the {icon:Superheros[3]} is in the first column, the {icon:Hubble[4]} can not be in the third column.\n\nTap the middle grid cell in the third column.",
                TutorialSystem.TutorialPiece.RedNebula4, rightCenterGridArea);

            if (!Game.Tutorial.IsPieceSetup(TutorialSystem.TutorialPiece.EndScreen1))
            {
                // Create a dummy end screen here just so that the tutorial data gets setup correctly for later
                EndPuzzleScreen tempEnd = new EndPuzzleScreen(false, 3, 0, Game.ScreenWidth, Game.ScreenHeight, Game);
            }

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Puzzle2, new Vector2(-1000, -1000), 0,
                new Rectangle(Game.ScreenWidth - 170, Game.ScreenHeight - 80, 150, 0), "Solve this puzzle", TutorialSystem.TutorialPiece.EndScreen4, new Rectangle(0, 0, Game.ScreenWidth, Game.ScreenHeight));

            Game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.Horizontal_NextTo, clue2Position, 0, bottomTutorialRect,
                "This clue is a Next To type clue. It tells us that the {icon:Superheros[5]} is in a column directly next to the column with the {icon:Flowers[2]}.\n\nThis doesn't help you any right now, but it will come in handy as you learn more about the puzzle.", TutorialSystem.TutorialPiece.None, Rectangle.Empty, true);

            Game.Tutorial.TriggerPiece(TutorialSystem.TutorialPiece.GameStart);
        }
Example #31
0
 private void PickClueType(Puzzle P, Random rand)
 {
     double dfVal = rand.NextDouble();
     if (dfVal < 0.1 && P.GetNumGivenClues() < 5)
         m_Type = eClueType.Given;
     else if (dfVal < 0.35)
         m_Type = eClueType.Vertical;
     else
         m_Type = eClueType.Horizontal;
 }