Пример #1
0
 // Redraws all the items without creating new rectangle objects
 // Essentially just sets their fill and border colors to match their current state (alive/dead)
 public static void RedrawGameBoard(Canvas surface, GameState givenGame)
 {
     for (int i = 0; i < givenGame.Length(); i++)
     {
         for (int j = 0; j < givenGame.Length(); j++)
         {
             int surfaceChildIndex = (i * givenGame.Length()) + j;
             if (surface.Children[surfaceChildIndex] is Rectangle)
             {
                 RedrawCell((surface.Children[surfaceChildIndex] as Rectangle), givenGame.GameStatus()[i, j]);
             }
             else
             {
                 throw new NotSupportedException("Children in " + surface.Name + " is not a Rectangle item"); // item in children is not a rectangle, throw exception
             }
         }
     }
 }
Пример #2
0
        // Fills the canvas with new and equally sized rectangles representing the cells of the Game of Life
        public static void DrawGameBoard(Canvas surface, GameState givenGame)
        {
            var canvasLength    = surface.ActualWidth;
            var cellPixelLength = canvasLength / givenGame.Length();

            surface.Children.Clear(); // resets surface
            for (int i = 0; i < givenGame.Length(); i++)
            {
                for (int j = 0; j < givenGame.Length(); j++)
                {
                    DrawCell(surface, cellPixelLength, cellPixelLength, j * cellPixelLength, i * cellPixelLength, givenGame.GameStatus()[i, j]);
                }
            }
        }