void InitGame(int height, int width, int mines, int tileSize)
        {
            minePanel.Children.Clear();
             minePanel.Height = tileSize * height;
             minePanel.Width = tileSize * width;

             game = Game.RandomGame(width, height, mines);
             covers = new List<Rectangle>();
             for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++)
            {
               var tile = game.GetTile(i, j);
               TextBlock txt = null;
               if (tile.IsMine)
               {
                  txt = new TextBlock();
                  txt.Text = "X";
               }
               else if (tile.SurroundMines > 0)
               {
                  txt = new TextBlock();
                  txt.Foreground = flagColors[tile.SurroundMines - 1];
                  txt.Text = tile.SurroundMines.ToString();
               }

               if (txt != null)
               {
                  txt.Height = txt.Width = tileSize;
                  txt.TextAlignment = TextAlignment.Center;
                  Canvas.SetLeft(txt, j * tileSize);
                  Canvas.SetTop(txt, i * tileSize);
                  minePanel.Children.Add(txt);
               }

               var cover = new Rectangle();
               cover.Tag = i * width + j;
               cover.Fill = new SolidColorBrush(Colors.Blue);
               cover.Height = cover.Width = tileSize;
               cover.MouseLeftButtonDown += new MouseButtonEventHandler(cover_MouseLeftButtonDown);
               Canvas.SetLeft(cover, j * tileSize);
               Canvas.SetTop(cover, i * tileSize);
               minePanel.Children.Add(cover);
               covers.Add(cover);
            }

             //grid lines
             for (int x = 0; x <= width * tileSize; x += tileSize)
             {
            var line = new Line();
            line.Stroke = new SolidColorBrush(Colors.Black);
            line.X1 = line.X2 = x;
            line.Y1 = 0;
            line.Y2 = height * tileSize;
            minePanel.Children.Add(line);
             }

             for (int y = 0; y <= height * tileSize; y += tileSize)
             {
            var line = new Line();
            line.Stroke = new SolidColorBrush(Colors.Black);
            line.Y1 = line.Y2 = y;
            line.X1 = 0;
            line.X2 = width * tileSize;
            minePanel.Children.Add(line);
             }
        }