Beispiel #1
0
 /// <summary>
 /// removes all items from the palette
 /// </summary>
 /// <param name="aPuzzleItem"></param>
 public void RemoveAll()
 {
     PuzzleItems.Clear();
     aListOfSelectedItems.Clear();
     PuzzleItems.Clear();
     Invalidate();
 }
Beispiel #2
0
 public void InsertAfter(PuzzleItem item, int slot)
 {
     if (DeleteAtEnd)
     {
         if (PuzzleItems.Count >= gridSize)
         {
             if (OverloadDumpSite != null)
             {
                 OverloadDumpSite.InsertBefore(PuzzleItems[gridSize - 1], 0);
             }
             PuzzleItems.Remove(PuzzleItems[gridSize - 1]);
         }
         if (PuzzleItems.Count >= gridSize)
         {
             try
             {
                 PuzzleItems.RemoveAt(gridSize);
                 foreach (PuzzleItem anItem in aListOfSelectedItems)
                 {
                     if (!PuzzleItems.Contains(anItem))
                     {
                         aListOfSelectedItems.Remove(anItem);
                     }
                 }
             }
             catch { /*happens when window is resized (sometimes)*/ }
         }
     }
     PuzzleItems.Insert(slot + 1, item);
     Invalidate();
 }
Beispiel #3
0
 public void RemoveItemNumber(int index)
 {
     if (PuzzleItems.Count > 0)
     {
         PuzzleItems.RemoveAt(index);
     }
     if (aListOfSelectedItems.Count > 0)
     {
         aListOfSelectedItems.Remove(PuzzleItems[index]);//dont think this is nessesary
     }
     Invalidate();
 }
        public void Solve_GivenValidDifferentPuzzleAsInputWithMultipleCell_ShouldHaveValidSolveRun()
        {
            var sut = new PuzzleItems.Puzzle(@$ "2,_,_,3,_,_,_,_,_| 
                                                8,_,4,_,6,2,_,_,3|
                                                _,1,3,8,_,_,2,_,_|
                                                _,_,_,_,2,_,3,9,_|
                                                5,_,7,_,_,_,6,2,1|
                                                _,3,2,_,_,6,_,_,_|
                                                _,2,_,_,_,9,1,4,_|
                                                6,_,1,2,5,_,8,_,9|
                                                _,_,_,_,_,1,_,_,2");

            sut.Solve();
            Assert.IsTrue(sut.IsValid());
        }
        public void Solve_GivenValidPuzzleAsInputWithMultipleCell_ShouldHaveValidSolveRun()
        {
            var sut = new PuzzleItems.Puzzle(@$ "_,2,_,_,_,4,3,_,_| 
                                                9,_,_,_,2,_,_,_,8|
                                                _,_,_,6,_,9,_,5,_|
                                                _,_,_,_,_,_,_,_,1|
                                                _,7,2,5,_,3,6,8,_|
                                                6,_,_,_,7,_,4,3,5|
                                                _,8,_,2,_,5,_,_,_|
                                                1,_,_,_,9,_,_,_,3|
                                                _,_,9,8,_,_,_,6,_");

            sut.Solve();
            Assert.IsTrue(sut.IsValid());
        }
        public void Solve_GivenValidPuzzleAsInputWithTwoMissingCell_ShouldHaveValidSolveRun()
        {
            var sut = new PuzzleItems.Puzzle(@$ "_,2,7,1,5,4,3,9,6| 
                                                9,6,5,3,2,7,1,4,8|
                                                3,4,1,6,8,9,7,5,2|
                                                5,9,3,4,6,8,2,7,1|
                                                4,7,2,5,1,3,6,8,9|
                                                6,1,8,9,7,2,4,3,5|
                                                7,8,6,2,3,5,9,1,4|
                                                1,5,4,7,9,6,8,2,3|
                                                2,3,9,8,4,1,5,6,_");

            sut.Solve();
            Assert.IsTrue(sut.IsValid());
        }
        public void InsertGuesses_GivenPuzzleWithBlanks_ShouldHaveIsInitialValueFalseForBlankCells()
        {
            var sut = new PuzzleItems.Puzzle(@$ "1,2,3,4,5,6,7,8,9| 
                                                1,2,3,4,5,6,7,8,_|
                                                1,2,3,4,5,6,7,8,9|
                                                1,2,3,4,5,6,7,8,9|
                                                1,2,3,4,5,6,7,8,9|
                                                1,2,3,4,5,6,7,8,9|
                                                1,2,3,4,5,6,7,8,9|
                                                1,2,3,_,5,6,_,8,9|
                                                1,2,3,4,_,6,7,8,9");

            Assert.IsFalse(sut.Columns[3].Cells[7].IsInitialCell);
            Assert.IsFalse(sut.Columns[6].Cells[7].IsInitialCell);
            Assert.IsFalse(sut.Columns[4].Cells[8].IsInitialCell);
            Assert.IsFalse(sut.Columns[8].Cells[1].IsInitialCell);
        }
        public void Constructor_GivenInputString_ShouldPopulateColumnCellsCorrectly()
        {
            var puzzle = new PuzzleItems.Puzzle(@$ "1,2,3,4,5,6,7,8,9| 
                                                   1,2,3,4,5,6,7,8,5|
                                                   1,2,3,4,5,6,7,8,9|
                                                   1,2,3,4,5,6,7,8,9|
                                                   1,2,3,4,5,6,7,8,9|
                                                   1,2,3,4,5,6,7,8,9|
                                                   1,2,3,4,5,6,7,8,9|
                                                   1,2,3,7,5,6,4,8,9|
                                                   1,2,3,4,9,6,7,8,9");

            Assert.AreEqual(7, puzzle.Columns[3].Cells[7].Value);
            Assert.AreEqual(4, puzzle.Columns[6].Cells[7].Value);
            Assert.AreEqual(9, puzzle.Columns[4].Cells[8].Value);
            Assert.AreEqual(5, puzzle.Columns[8].Cells[1].Value);
        }
Beispiel #9
0
 public void InsertBefore(PuzzleItem item, int slot)
 {
     if (slot >= 32)
     {
         if (OverloadDumpSite != null)
         {
             OverloadDumpSite.InsertBefore(item, 0);
         }
     }
     else
     {
         if (DeleteAtEnd)
         {
             if (PuzzleItems.Count >= gridSize)
             {
                 if (OverloadDumpSite != null)
                 {
                     OverloadDumpSite.InsertBefore(PuzzleItems[gridSize - 1], 0);
                 }
                 PuzzleItems.Remove(PuzzleItems[gridSize - 1]);
             }
             if (PuzzleItems.Count >= gridSize)
             {
                 try
                 {
                     PuzzleItems.RemoveAt(gridSize);
                     foreach (PuzzleItem anItem in aListOfSelectedItems)
                     {
                         if (!PuzzleItems.Contains(anItem))
                         {
                             aListOfSelectedItems.Remove(anItem);
                         }
                     }
                 }
                 catch { /*happens when window is resized (sometimes... and things break) */ }
             }
         }
         PuzzleItems.Insert(slot, item);//todo: fix crash when Item dragged too deep onto the palette
     }
     Invalidate();
 }
Beispiel #10
0
 public virtual void update(Graphics e)
 {
     if (levelofdrawing == 0)
     {
         //bool anItemIsSelected=false;
         if (e == null)
         {
             e = this.CreateGraphics();
         }
         PuzzleItem aPuzzlemakerItem;
         //if (BackgroundImage != null)
         //    e.DrawImage(BackgroundImage, 0, 0);
         for (int i = 0; i < PuzzleItems.Count; i++)
         {
             aPuzzlemakerItem = PuzzleItems[i];
             e.DrawImage(aPuzzlemakerItem.PreviewImage, (i % gridWidth) * (ItemsImageSize + PaddingBetweenItems) + InitialOffsetPoint.X, (i / gridWidth) * (ItemsImageSize + PaddingBetweenItems) + InitialOffsetPoint.Y, 64f, 64f);
         }
         //Draw selected items
         Pen aPen = new Pen(selectedItemBoxColor);
         aPen.Width = 3;
         for (int i = 0; i < aListOfSelectedItems.Count; i++)
         {
             if (aListOfSelectedItems[i] != null)
             {
                 int location = PuzzleItems.IndexOf((PuzzleItem)aListOfSelectedItems[i]);
                 if ((location % gridWidth) >= 0 && (ItemsImageSize + PaddingBetweenItems) + InitialOffsetPoint.X >= 0)//todo: these were just >0 changed to fix bug, we'll see
                 {
                     e.DrawRectangle(aPen, (location % gridWidth) * (ItemsImageSize + PaddingBetweenItems) + InitialOffsetPoint.X, (location / gridWidth) * (ItemsImageSize + PaddingBetweenItems) + InitialOffsetPoint.Y, 64, 64);
                 }
             }
         }
         if (dragging_insert_slot >= -1)
         {
             update_insertOverlay(e);
         }
     }
 }
Beispiel #11
0
 /// <summary>
 /// removes the designated item from the palette if it exists
 /// </summary>
 /// <param name="aPuzzleItem"></param>
 public void RemoveItem(PuzzleItem aPuzzleItem)
 {
     PuzzleItems.Remove(aPuzzleItem);
     aListOfSelectedItems.Remove(aPuzzleItem);//dont think this is nessesary
     Invalidate();
 }