Example #1
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]);
                }
            }
        }
Example #2
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
             }
         }
     }
 }
Example #3
0
 public SetupMenu(LifeRuleset rulesetToModify, GameState currentGame)
 {
     InitializeComponent();
     helper = new SetupMenuHelper(rulesetToModify);
     helper.RecolorBoxes(LivingList, GrowingList, DyingList);
     backupEnteredTextString = "";
     currentLength           = currentGame.Length();
     EnteredLength.Text      = currentLength.ToString();
 }
        // Opens a LoadFile window, sets Rules to its results
        void LoadClick(object sender, RoutedEventArgs e)
        {
            PauseGameWhileMenuOpen();
            LoadFileWindow window = new LoadFileWindow(Rules);

            window.ShowDialog();
            Rules    = window.ReturnResult();
            MainGame = new GameState(MainGame.Length(), (int)LifeBoard.ActualWidth, (int)LifeBoard.ActualHeight, Rules);
            UnpauseGame();
        }
Example #5
0
        // Finds the rectangle matching the xPos and yPos given, sets its color to differentiate it from other cells
        public static void DrawHighlightedCell(Canvas surface, int xPos, int yPos, GameState givenGame)
        {
            if (xPos >= 0 && yPos >= 0 && xPos < surface.ActualWidth && yPos < surface.ActualWidth)
            {
                var canvasLength      = surface.ActualWidth;
                var cellPixelLength   = canvasLength / givenGame.Length();
                int xIndex            = (int)(xPos / cellPixelLength);
                int yIndex            = (int)(yPos / cellPixelLength);
                int surfaceChildIndex = (yIndex * givenGame.Length()) + xIndex;


                if (surfaceChildIndex < surface.Children.Count && surface.Children[surfaceChildIndex] is Rectangle)
                {
                    (surface.Children[surfaceChildIndex] as Rectangle).Fill = Brushes.LightBlue;
                }
                else
                {
                    throw new NotSupportedException("Children in " + surface.Name + " is not a Rectangle item"); // item in children is not a rectangle, throw exception
                }
            }
        }