Example #1
0
        public void DrawGameField()
        {
            double width       = canvas.ActualWidth;
            double height      = canvas.ActualHeight;
            double rowHeight   = height / rowsCount;
            double columnwidth = width / columnsCount;

            WPFCanvas.Clear();
            WPFCanvas.DrawGrid(rowsCount, columnsCount, Brushes.LightGray);
            canvas.Background = Brushes.DarkGray;
            for (int i = 0; i < rowsCount; i++)
            {
                for (int j = 0; j < columnsCount; j++)
                {
                    if (grid[i, j].Opened)
                    {
                        switch (grid[i, j].Type)
                        {
                        case CELLTYPES.BOMB:
                            WPFCanvas.DrawRectangle(j * rowHeight, i * columnwidth, columnwidth, rowHeight, Brushes.White);
                            WPFCanvas.DrawEllipse(j * rowHeight, i * columnwidth, columnwidth, rowHeight, Brushes.Black);
                            MessageBox.Show("Game Over");
                            restart();
                            break;

                        case CELLTYPES.NUMBER:
                            WPFCanvas.DrawRectangle(j * rowHeight, i * columnwidth, columnwidth, rowHeight, Brushes.White);
                            WPFCanvas.DrawText(i * columnwidth, j * rowHeight, rowHeight, columnwidth, grid[i, j].Value.ToString(), Colors.Blue);
                            break;

                        case CELLTYPES.EMPTY:
                            WPFCanvas.DrawRectangle(j * rowHeight, i * columnwidth, columnwidth, rowHeight, Brushes.White);
                            break;
                        }
                    }
                    else
                    {
                        if (grid[i, j].Flag)
                        {
                            WPFCanvas.DrawEllipse(j * rowHeight, i * columnwidth, columnwidth, rowHeight, Brushes.Red);
                        }
                    }
                }
            }
            CheckForWin();
        }
Example #2
0
 private void clearPanel()
 {
     drawingCanvas.Clear();
 }