예제 #1
0
 private void changeC(object obj)
 {
     //HAHA Dave Gay
     if (myIndex_ != -1)
     {
         int    temp = myIndex_;
         Square s    = Squares[temp];
         Squares.RemoveAt(temp);
         Squares.Insert(temp, new Square());
         setNumbers();
     }
 }
예제 #2
0
        private void ShrinkSquares()
        {
            /* Remove squares from the list of squares */
            // First we remove entirely deleted lists.
            // This happens when the height was changed.

            // We loop backwards from the previous count of squares,
            // because it's larger than the new size (either height or width).
            for (int y = Squares.Count - 1; y > this.Height / SquareSideLength; y--)
            {
                // Height is in pixels, so we divide it by SquareSideLength to get the list index.
                foreach (Square squareObj in Squares[y])
                {
                    if (PaintedSquares.ContainsKey(squareObj.Location))
                    {
                        // A non existent square cannot be painted ;)
                        PaintedSquares.Remove(squareObj.Location);
                    }
                }
                // Now we can remove the entire sublist.
                Squares.RemoveAt(y);
            }
            // Now we remove any extra squares on each sublist.
            // This happens when the width was changed.
            for (int y = 0; y < Squares.Count; y++)
            {
                // Once again we loop backwards starting at Count - 1 until we hit the new width.
                for (int x = Squares[y].Count - 1; x > this.Width / SquareSideLength; x--)
                {
                    Square squareObj = Squares[y][x];
                    Squares[y].RemoveAt(x);
                    if (PaintedSquares.ContainsKey(squareObj.Location))
                    {
                        // Remove this square from the PaintedSquares dictionary as well
                        PaintedSquares.Remove(squareObj.Location);
                    }
                }
            }
            // Redraw the grid
            this.Invalidate();
        }