BackGammon Game

856 Views Asked by At

I'm trying to write a server client application for a backgammon game using C# Windows Forms: Server Side: I have a picturebox with a backgammon board image, and I need to draw the checkers on it. I wrote this so far.

private void drawboard()
   {
      int x = 82, y = 64;
      for (int s = 0; s < 6; s++)
      {
          darkstone[s] = new PictureBox();
          this.Controls.Add(darkstone[s]);
          darkstone[s].Location = new Point(x, y);
          darkstone[s].BackColor = Color.Black;
          x += 60;
          darkstone[s].Paint += new PaintEventHandler(stone_Paint);
      }
   }
    private void stone_Paint(object sender, PaintEventArgs e)
   {
       SolidBrush blackbrush = new SolidBrush(Color.Black);
       int x = 32, y = 20;
       for (int i = 0; i < 6; i++)
       {
           e.Graphics.FillEllipse(blackbrush, x, y, 25, 23);
           y += 22;
       }
       SolidBrush whitebrush = new SolidBrush(Color.White);
       int z = 32, w = 350;
       for (int j = 0; j < 6; j++)
       {    
           e.Graphics.FillEllipse(whitebrush, z, w, 25, 23);
           w -= 22;
       }
       blackbrush.Dispose();
       whitebrush.Dispose();
   }

And I called method drawboard() when my form loads, but no checkers are drawn. Anyway, if I define a picturebox_paint event, and call method stone_paint(), the checkers are drawn on the board. but this solution is not ideal as I need each checker to be represented as a pictureBox as in method drawboard() for later purposes such as moving checkers across the board.

What is wrong with my code?

0

There are 0 best solutions below