コード例 #1
0
        public HorizontalCluePanel(GameScene scene, Clue[] clues)
            : base(scene)
        {
            m_iSelectedIndex = -1;
            m_Clues = new List<Clue>(clues);
            int screenWidth = Scene.Game.ScreenWidth;
            int screenHeight = Scene.Game.ScreenHeight;

            int marginRight = (int)(Constants.MarginRight * screenWidth);
            int marginTop = (int)(Constants.MarginTop * screenHeight);

            m_IconSize = (int)(Constants.IconSize * screenHeight);
            m_ClueSpace = (int)(Constants.ClueSpace * screenHeight);
            int clueWidth = m_IconSize * 3;

            // Initialize the rectangle
            int width = clueWidth + marginRight;
            int x = screenWidth - width;
            m_Rect = new Rectangle(x, marginTop, width, screenHeight);

            // Setup scroll min/max
            float totalHeight = ((m_IconSize + m_ClueSpace) * clues.Length) - m_ClueSpace;
            m_ScrollMin = (-totalHeight + screenHeight) - marginTop;
            m_ScrollMax = marginTop;
            m_ScrollPosition = m_ScrollMax;
        }
コード例 #2
0
ファイル: Hint.cs プロジェクト: acid1789/Happiness
        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;
        }
コード例 #3
0
        public VerticalCluePanel(GameScene scene, Clue[] clues, int width)
            : base(scene)
        {
            m_Clues = new List<Clue>(clues);
            m_iSelectedIndex = -1;
            int screenHeight = scene.Game.ScreenHeight;

            m_IconSize = (int)(Constants.IconSize * screenHeight);
            m_ClueSpace = (int)(Constants.ClueSpace * screenHeight);

            int clueHeight = m_IconSize * 3;
            int bottomMargin = (int)(screenHeight * Constants.MarginBottom);
            int leftMargin = (int)(scene.Game.ScreenWidth * Constants.MarginLeft);

            int y = screenHeight - (clueHeight + bottomMargin);
            m_Rect = new Rectangle(leftMargin, y, width, screenHeight - y);

            // Setup scroll min/max
            float totalWidth = ((m_IconSize + m_ClueSpace) * clues.Length) - m_ClueSpace;
            m_ScrollMin = (-totalWidth + width) - leftMargin;
            m_ScrollMax = leftMargin;
            m_ScrollPosition = leftMargin;
        }
コード例 #4
0
 public void UnhideClues(Clue[] clues)
 {
     m_Clues = new List<Clue>(clues);
     ClearSelected();
 }
コード例 #5
0
ファイル: GameScene.cs プロジェクト: acid1789/Happiness
 public bool ShouldShowHint(Clue c)
 {
     bool bHintClue = false;
     if (m_Hint != null && m_Hint.ShouldDraw(c))
         bHintClue = true;
     return bHintClue;
 }
コード例 #6
0
ファイル: GameScene.cs プロジェクト: acid1789/Happiness
 public void SelectClue(Clue clue, UIPanel panel)
 {
     if (panel == m_HorizontalCluePanel)
     {
         m_VerticalCluePanel.ClearSelected();
     }
     else
     {
         m_HorizontalCluePanel.ClearSelected();
     }
     m_HelpPanel.SelectedClue = clue;
     m_ButtonPanel.HideClueEnabled = clue != null;
 }
コード例 #7
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        private bool ValidateClue(Clue C)
        {
            if (IsDuplicateClue(C))
                return false;

            if (C.m_Type == eClueType.Vertical)
            {
                int iRow1 = -1;
                int iRow2 = -1;
                int iCol = C.m_iCol;
                switch (C.m_VerticalType)
                {
                    case eVerticalType.Two:
                    case eVerticalType.ThreeBotNot:
                        iRow1 = C.m_iRow;
                        iRow2 = C.m_iRow2;
                        break;
                    case eVerticalType.ThreeMidNot:
                        iRow1 = C.m_iRow;
                        iRow2 = C.m_iRow3;
                        break;
                    case eVerticalType.ThreeTopNot:
                        iRow1 = C.m_iRow2;
                        iRow2 = C.m_iRow3;
                        break;
                }
                if (iRow1 >= 0)
                {
                    for (int i = 0; i < m_Clues.Count; i++)
                    {
                        Clue cTest = (Clue)m_Clues[i];
                        if (cTest.m_Type == eClueType.Vertical)
                        {
                            switch (cTest.m_VerticalType)
                            {
                                case eVerticalType.Two:
                                case eVerticalType.ThreeBotNot:
                                    if (iRow1 == cTest.m_iRow && iRow2 == cTest.m_iRow2)
                                        return false;
                                    break;
                                case eVerticalType.ThreeMidNot:
                                    if (iRow1 == cTest.m_iRow && iRow2 == cTest.m_iRow3)
                                        return false;
                                    break;
                                case eVerticalType.ThreeTopNot:
                                    if (iRow1 == cTest.m_iRow2 && iRow2 == cTest.m_iRow3)
                                        return false;
                                    break;
                            }
                        }
                    }
                }
            }
            return true;
        }
コード例 #8
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        private void OptimizeClues()
        {
            // Build the seperate clue lists
            BuildClueLists();

            // Reset the puzzle & apply all the givens
            Reset();

            // Solve again with the new clue order
            int iPass = 0;
            while (!IsSolved())
            {
                for (int i = 0; i < m_VeritcalClues.Count; i++)
                {
                    Clue c = m_VeritcalClues[i];
                    c.Analyze(this);
                }

                for (int i = 0; i < m_HorizontalClues.Count; i++)
                {
                    Clue c = m_HorizontalClues[i];
                    c.Analyze(this);
                }

                iPass++;
                if (iPass > 100)
                {
                    Debug.WriteLine("Unsolvable in the optimize stage?");
                    DumpPuzzle();
                    DebugError();
                    return;
                }
            }
            Debug.Write("Passes: ");
            Debug.WriteLine(iPass++);

            // Sort the list based on most used
            m_Clues.Sort();

            // Remove any zero use count clues
            for (int i = m_Clues.Count - 1; i > 0; i--)
            {
                Clue C = (Clue)m_Clues[i];
                if (C.m_iUseCount > 0)
                    break;

                m_Clues.RemoveAt(i);
            }

            // Resolve sorted
            Debug.WriteLine("Clue Count Before 2nd stage optimization: " + m_Clues.Count);
            BuildClueLists();
            Reset();
            iPass = 0;
            while (!IsSolved())
            {
                for (int i = 0; i < m_VeritcalClues.Count; i++)
                {
                    Clue c = m_VeritcalClues[i];
                    c.Analyze(this);
                }

                for (int i = 0; i < m_HorizontalClues.Count; i++)
                {
                    Clue c = m_HorizontalClues[i];
                    c.Analyze(this);
                }

                iPass++;
                if (iPass > 100)
                {
                    Debug.WriteLine("Unsolvable in the optimize stage?");
                    DumpPuzzle();
                    DebugError();
                    return;
                }
            }
            Debug.WriteLine("Passes: " + iPass);

            // Sort the list based on most used
            m_Clues.Sort();

            // Remove any zero use count clues
            for (int i = m_Clues.Count - 1; i > 0; i--)
            {
                Clue C = (Clue)m_Clues[i];
                if (C.m_iUseCount > 0)
                    break;

                m_Clues.RemoveAt(i);
            }

            // Add/Remove clues for difficulty
            Reset();
            if (m_iDifficulty == 0)
            {
                // Add some clues
                int iCluesToAdd = m_Rand.Next(4) + 1;
                int iNewClueCount = m_Clues.Count + iCluesToAdd;
                while (m_Clues.Count < iNewClueCount)
                {
                    Clue c = new Clue(this, m_Rand);
                    if (ValidateClue(c))
                    {
                        m_Clues.Add(c);
                    }
                }
            }
            else if (m_iDifficulty == 2)
            {
                // Remove some clues
                int iCluesToRemove = m_Rand.Next(m_iSize / 3) + 2;
                int iUseCount = 1;
                while (iCluesToRemove > 0)
                {
                    int iClueCount = m_Clues.Count;
                    for (int i = 0; i < m_Clues.Count; i++)
                    {
                        Clue C = (Clue)m_Clues[i];
                        if (C.m_iUseCount <= iUseCount)
                        {
                            iCluesToRemove--;
                            m_Clues.Remove(C);
                            break;
                        }
                    }
                    if (iClueCount == m_Clues.Count)
                        iUseCount++;
                }
            }

            // Rebuild the clues list
            BuildClueLists();

            // Reset the puzzle again
            Reset();
        }
コード例 #9
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
 private bool IsDuplicateClue(Clue testClue)
 {
     for (int i = 0; i < m_Clues.Count; i++)
     {
         Clue C = (Clue)m_Clues[i];
         if (testClue.m_Type == C.m_Type)
         {
             if (C.m_Type == eClueType.Vertical)
             {
                 if (C.m_VerticalType == testClue.m_VerticalType)
                 {
                     if (C.m_iCol == testClue.m_iCol)
                     {
                         switch (C.m_VerticalType)
                         {
                             case eVerticalType.Two:
                                 if (C.m_iRow == testClue.m_iRow && C.m_iRow2 == testClue.m_iRow2)
                                     return true;
                                 break;
                             case eVerticalType.Three:
                                 if (C.m_iRow == testClue.m_iRow && C.m_iRow2 == testClue.m_iRow2 && C.m_iRow3 == testClue.m_iRow3)
                                     return true;
                                 break;
                             case eVerticalType.TwoNot:
                                 if (C.m_iRow == testClue.m_iRow && C.m_iRow2 == testClue.m_iRow2 && C.m_iNotCell == testClue.m_iNotCell)
                                     return true;
                                 break;
                             case eVerticalType.EitherOr:
                             case eVerticalType.ThreeTopNot:
                             case eVerticalType.ThreeMidNot:
                             case eVerticalType.ThreeBotNot:
                                 if (C.m_iRow == testClue.m_iRow && C.m_iRow2 == testClue.m_iRow2 && C.m_iRow3 == testClue.m_iRow3 && C.m_iNotCell == testClue.m_iNotCell)
                                     return true;
                                 break;
                         }
                     }
                 }
             }
             else if (C.m_Type == eClueType.Horizontal)
             {
                 if (C.m_HorizontalType == testClue.m_HorizontalType)
                 {
                     switch (C.m_HorizontalType)
                     {
                         case eHorizontalType.NextTo:
                         case eHorizontalType.LeftOf:
                         case eHorizontalType.NotLeftOf:
                             if (C.m_iRow == testClue.m_iRow && C.m_iCol == testClue.m_iCol && C.m_iRow2 == testClue.m_iRow2 && C.m_iCol2 == testClue.m_iCol2)
                                 return true;
                             break;
                         case eHorizontalType.NotNextTo:
                             if (C.m_iRow == testClue.m_iRow && C.m_iCol == testClue.m_iCol && C.m_iRow2 == testClue.m_iRow2 && C.m_iHorizontal1 == testClue.m_iHorizontal1)
                                 return true;
                             break;
                         case eHorizontalType.Span:
                             if (C.m_iRow == testClue.m_iRow && C.m_iCol == testClue.m_iCol && C.m_iRow2 == testClue.m_iRow2 && C.m_iCol2 == testClue.m_iCol2 && C.m_iRow3 == testClue.m_iRow3 && C.m_iCol3 == testClue.m_iCol3)
                                 return true;
                             break;
                         case eHorizontalType.SpanNotLeft:
                         case eHorizontalType.SpanNotMid:
                         case eHorizontalType.SpanNotRight:
                             if (C.m_iRow == testClue.m_iRow && C.m_iCol == testClue.m_iCol && C.m_iRow2 == testClue.m_iRow2 && C.m_iCol2 == testClue.m_iCol2 && C.m_iRow3 == testClue.m_iRow3 && C.m_iCol3 == testClue.m_iCol3 && C.m_iHorizontal1 == testClue.m_iHorizontal1)
                                 return true;
                             break;
                     }
                 }
             }
             else // Given
             {
                 if (C.m_iCol == testClue.m_iCol && C.m_iRow == testClue.m_iRow)
                     return true;
             }
         }
     }
     return false;
 }
コード例 #10
0
ファイル: HelpPanel.cs プロジェクト: acid1789/Happiness
        void DrawClueDescription_Horizontal(SpriteBatch spriteBatch, Clue clue)
        {
            int iX = m_Rect.Left;
            int iY = (m_Rect.Top + (m_Rect.Height >> 1)) - (m_iClueIconSize >> 1);
            int[] iIcons = new int[3];
            int[] iRows = clue.GetRows();
            clue.GetIcons(GameScene.Puzzle, iIcons);
            string szDesc;

            switch (clue.m_HorizontalType)
            {
                case eHorizontalType.NextTo:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is next to";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eHorizontalType.NotNextTo:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is not next to";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eHorizontalType.LeftOf:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is left of";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eHorizontalType.NotLeftOf:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is not left of";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eHorizontalType.Span:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "has";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "next to it on one side, and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "next to it on the other";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
                case eHorizontalType.SpanNotLeft:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "has";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "next to it on one side, and not";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "next to it on the other";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
                case eHorizontalType.SpanNotMid:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "have one column between them without";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eHorizontalType.SpanNotRight:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "has";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "on one side, and not";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "on the other";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
            }
        }
コード例 #11
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        public void SetFinalIcon(Clue theClue, int iRow, int iCol, int iIcon)
        {
            int iFinal = m_Rows[iRow].m_Cells[iCol].m_iFinalIcon;
            if (iFinal >= 0 && iFinal != iIcon)
            {
                Debug.WriteLine(string.Format("SetFinalIcon({0}, {1}, {2}) changing final icon from: {3}", iRow, iCol, iIcon, iFinal));

                DebugError();
            }

            if (!m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon])
            {
                Debug.WriteLine(string.Format("SetFinalIcon({0}, {1}, {2}) setting final icon to an already eliminated icon", iRow, iCol, iIcon));
                DebugError();
            }

            if (iFinal != iIcon)
            {
                if (theClue != null)
                    theClue.m_iUseCount += 5;

                // Set the final icon
                m_Rows[iRow].m_Cells[iCol].m_iFinalIcon = iIcon;

                // Eliminate all the other icons in this cell
                for (int i = 0; i < m_iSize; i++)
                {
                    if (i != iIcon)
                        EliminateIcon(theClue, iRow, iCol, i);
                }

                // Eliminate the newly set icon from every other column on this row
                for (int i = 0; i < m_iSize; i++)
                {
                    if (i != iCol)
                        EliminateIcon(theClue, iRow, i, iIcon);
                }
            }
        }
コード例 #12
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        public Hint GenerateHint(Clue[] VisibleClues)
        {
            Hint hRet = null;

            // Pick a clue that we could use for a hint
            for (int i = 0; i < VisibleClues.Length; i++)
            {
                SetMarker();
                if (VisibleClues[i] != null)
                {
                    int iUseCount = VisibleClues[i].m_iUseCount;
                    VisibleClues[i].Analyze(this);
                    RestoreMarker();

                    if (VisibleClues[i].m_iUseCount > iUseCount)
                    {
                        // This clue can do something, use it for the hint
                        hRet = new Hint();
                        if (!hRet.Init(this, VisibleClues[i]))
                        {
                            continue;
                        }
                        break;
                    }
                }
            }

            return hRet;
        }
コード例 #13
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        public void EliminateIcon(Clue theClue, int iRow, int iCol, int iIcon)
        {
            int iFinal = m_Rows[iRow].m_Cells[iCol].m_iFinalIcon;
            if (iFinal == iIcon)
            {
                Debug.WriteLine(string.Format("EliminateIcon({0}, {1}, {2}) eliminating the final icon", iRow, iCol, iIcon));
                DebugError();
            }

            if (iIcon < 0)
            {
                Debug.WriteLine(string.Format("EliminateIcon({0}, {1}, {2}) eliminating a negative icon", iRow, iCol, iIcon));
                DebugError();
            }

            if (m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon])
            {
                // If the icon hasnt been eliminated already and there is a clue driving this, mark the clue as used
                if (theClue != null)
                    theClue.m_iUseCount++;

                // Eliminate the icon
                m_Rows[iRow].m_Cells[iCol].m_bValues[iIcon] = false;

                if (m_Rows[iRow].m_Cells[iCol].m_iFinalIcon < 0)
                {
                    // Check to see if there is only one icon left in this cell
                    int iRemaining = m_Rows[iRow].m_Cells[iCol].GetRemainingIcon();
                    if (iRemaining >= 0)
                    {
                        // Only one icon remaining and the icon hasnt been 'set' yet
                        SetFinalIcon(theClue, iRow, iCol, iRemaining);
                    }
                }

                // Check to see if there is only one of this icon left on this row
                int iCount = 0;
                int iColumn = 0;
                for (int i = 0; i < m_iSize; i++)
                {
                    if (m_Rows[iRow].m_Cells[i].m_bValues[iIcon])
                    {
                        iCount++;
                        iColumn = i;
                    }
                }
                if (iCount == 1 && m_Rows[iRow].m_Cells[iColumn].m_iFinalIcon < 0)
                {
                    // There is only one of this icon left and it hasnt been 'set' in its column yet
                    SetFinalIcon(theClue, iRow, iColumn, iIcon);
                }
            }
        }
コード例 #14
0
        void DrawClue(SpriteBatch sb, int x, int y, Clue c, bool bHintClue)
        {
            Rectangle[] rects = new Rectangle[3];
            rects[0] = new Rectangle(x, y, m_IconSize, m_IconSize);
            rects[1] = new Rectangle(x, y + m_IconSize, m_IconSize, m_IconSize);
            rects[2] = new Rectangle(x, y + (m_IconSize * 2), m_IconSize, m_IconSize);
            Rectangle bounds = new Rectangle(x, y, m_IconSize, m_IconSize * 3);

            int[] iIcons = new int[3];
            int[] iRows = c.GetRows();
            int iNumIcons = c.GetIcons(GameScene.Puzzle, iIcons);

            // Draw the frame
            sb.Draw(Assets.TransGray, bounds, Color.White);
            sb.Draw(Assets.GoldBarVertical, new Rectangle(x - 3, y - 3, 3, bounds.Height + 6), Color.White);
            sb.Draw(Assets.GoldBarHorizontal, new Rectangle(x - 3, y - 3, bounds.Width + 6, 3), Color.White);
            sb.Draw(Assets.GoldBarVertical, new Rectangle(bounds.Right, y - 3, 3, bounds.Height + 6), Color.White);
            sb.Draw(Assets.GoldBarHorizontal, new Rectangle(x - 3, bounds.Bottom, bounds.Width + 6, 3), Color.White);

            // Draw the icons

            for (int j = 0; j < iNumIcons; j++)
            {
                sb.Draw(GameScene.GetIcon(iRows[j], iIcons[j]), rects[j], Color.White);
                if (bHintClue)
                    Assets.HintSprite.Draw(sb, rects[j], Color.White);
            }

            // Draw the operational overlay
            Rectangle[] overlayRects = new Rectangle[2];
            overlayRects[0] = new Rectangle(x, y + (m_IconSize / 2), m_IconSize, m_IconSize);
            overlayRects[1] = new Rectangle(x, y + (m_IconSize / 2) + m_IconSize, m_IconSize, m_IconSize);
            switch (c.m_VerticalType)
            {
                case eVerticalType.Two:
                case eVerticalType.Three:
                    break;
                case eVerticalType.EitherOr:
                    sb.Draw(Assets.EitherOrOverlay, overlayRects[1], Color.White);
                    break;
                case eVerticalType.TwoNot:
                    sb.Draw(Assets.NotOverlay, overlayRects[0], Color.White);
                    break;
                case eVerticalType.ThreeTopNot:
                    sb.Draw(Assets.NotOverlay, rects[0], Color.White);
                    break;
                case eVerticalType.ThreeMidNot:
                    sb.Draw(Assets.NotOverlay, rects[1], Color.White);
                    break;
                case eVerticalType.ThreeBotNot:
                    sb.Draw(Assets.NotOverlay, rects[2], Color.White);
                    break;
            }
        }
コード例 #15
0
ファイル: Hint.cs プロジェクト: acid1789/Happiness
 public bool ShouldDraw(Clue C)
 {
     return (C == theClue);
 }
コード例 #16
0
        void DrawClue(SpriteBatch sb, int x, int y, Clue c, bool bHintClue)
        {
            Rectangle[] rects = new Rectangle[3];
            rects[0] = new Rectangle(x, y, m_IconSize, m_IconSize);
            rects[1] = new Rectangle(x + m_IconSize, y, m_IconSize, m_IconSize);
            rects[2] = new Rectangle(x + (m_IconSize * 2), y, m_IconSize, m_IconSize);
            Rectangle bounds = new Rectangle(x, y, m_IconSize * 3, m_IconSize);

            int[] iIcons = new int[3];
            int[] iRows = c.GetRows();
            int iNumIcons = c.GetIcons(GameScene.Puzzle, iIcons);

            // Draw the frame
            //sb.Draw(m_Game.TransGrey, bounds, Color.White);
            sb.Draw(Assets.GoldBarHorizontal, new Rectangle(x - 3, y - 3, bounds.Width + 6, 3), Color.White);
            sb.Draw(Assets.GoldBarHorizontal, new Rectangle(x - 3, bounds.Bottom, bounds.Width + 6, 3), Color.White);
            sb.Draw(Assets.GoldBarVertical, new Rectangle(x - 3, y - 3, 3, bounds.Height + 6), Color.White);
            sb.Draw(Assets.GoldBarVertical, new Rectangle(bounds.Right, y - 3, 3, bounds.Height + 6), Color.White);

            // Draw the icons
            if (c.m_HorizontalType == eHorizontalType.LeftOf || c.m_HorizontalType == eHorizontalType.NotLeftOf)
            {
                sb.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), rects[0], Color.White);
                sb.Draw(Assets.LeftOfIcon,                      rects[1], Color.White);
                sb.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), rects[2], Color.White);

                if (bHintClue)
                {
                    Assets.HintSprite.Draw(sb, rects[0], Color.White);
                    Assets.HintSprite.Draw(sb, rects[2], Color.White);
                }
            }
            else
            {
                for (int j = 0; j < iNumIcons; j++)
                {
                    sb.Draw(GameScene.GetIcon(iRows[j], iIcons[j]), rects[j], Color.White);
                    if (bHintClue)
                        Assets.HintSprite.Draw(sb, rects[j], Color.White);
                }
            }

            // Draw the operational overlay
            switch (c.m_HorizontalType)
            {
                case eHorizontalType.NextTo:
                case eHorizontalType.LeftOf:
                    break;
                case eHorizontalType.NotLeftOf:
                case eHorizontalType.NotNextTo:
                    sb.Draw(Assets.NotOverlay, rects[1], Color.White);
                    break;
                case eHorizontalType.Span:
                    sb.Draw(Assets.SpanOverlay, bounds, Color.White);
                    break;
                case eHorizontalType.SpanNotLeft:
                    sb.Draw(Assets.SpanOverlay, bounds, Color.White);
                    sb.Draw(Assets.NotOverlay, rects[0], Color.White);
                    break;
                case eHorizontalType.SpanNotMid:
                    sb.Draw(Assets.SpanOverlay, bounds, Color.White);
                    sb.Draw(Assets.NotOverlay, rects[1], Color.White);
                    break;
                case eHorizontalType.SpanNotRight:
                    sb.Draw(Assets.SpanOverlay, bounds, Color.White);
                    sb.Draw(Assets.NotOverlay, rects[2], Color.White);
                    break;
            }
        }
コード例 #17
0
ファイル: Puzzle.cs プロジェクト: acid1789/Happiness
        private void GenerateClues()
        {
            m_Clues = new ArrayList();
            while (!IsSolved())
            {
                Clue c = new Clue(this, m_Rand);
                if (ValidateClue(c))
                {
                    //Debug.Write("Adding Clue: ");
                    //Debug.WriteLine(m_Clues.Count);
                    m_Clues.Insert(0, c);

                    AnalyzeAllClues();
                }
            }

            Reset();

            Debug.WriteLine("Clue Count after initial generation: " + m_Clues.Count);

            // Optimize the clues
            OptimizeClues();

            Debug.WriteLine("Clue Count after optimization: " + m_Clues.Count);

            // Scramble All the clues
            ScrambleClues();

            // Reset the puzzle for actual play
            Reset();
        }
コード例 #18
0
ファイル: HelpPanel.cs プロジェクト: acid1789/Happiness
        void DrawClueDescription_Vertical(SpriteBatch spriteBatch, Clue clue)
        {
            int iX = m_Rect.Left;
            int iY = (m_Rect.Top + (m_Rect.Height >> 1)) - (m_iClueIconSize >> 1);
            int[] iIcons = new int[3];
            int[] iRows = clue.GetRows();
            clue.GetIcons(GameScene.Puzzle, iIcons);
            string szDesc;

            switch (clue.m_VerticalType)
            {
                case eVerticalType.Two:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is in the same column as";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eVerticalType.Three:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is in the same column as";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eVerticalType.EitherOr:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is either in the column with";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "or the column with";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eVerticalType.TwoNot:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;
                    szDesc = "is not in the same column as";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    break;
                case eVerticalType.ThreeTopNot:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "are in the same column but";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "is not";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
                case eVerticalType.ThreeMidNot:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "are in the same column but";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "is not";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
                case eVerticalType.ThreeBotNot:
                    spriteBatch.Draw(GameScene.GetIcon(iRows[0], iIcons[0]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "and";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[1], iIcons[1]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "are in the same column but";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    iX += (int)Assets.DialogFont.MeasureString(szDesc).X + 6;

                    spriteBatch.Draw(GameScene.GetIcon(iRows[2], iIcons[2]), new Rectangle(iX, iY, m_iClueIconSize, m_iClueIconSize), Color.White);
                    iX += m_iClueIconSize + 6;

                    szDesc = "is not";
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX + 2, iY + 2), Color.Black);
                    spriteBatch.DrawString(Assets.DialogFont, szDesc, new Vector2(iX, iY), Color.White);
                    break;
            }
        }