Best Way to Draw a Chessboard?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 31950 Views - Last Post: 07 December 2011 - 03:51 PM Rate Topic: -----

#16 Aramyth   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 51
  • Joined: 14-January 10

Re: Best Way to Draw a Chessboard?

Posted 06 December 2011 - 11:13 PM

I decided I'd draw the board out and use picture boxes for the pieces, for 'simplicity' sake, because I don't want to draw the pieces.

I tried placing a few pieces on the board for testing, but it's not working exactly right. For some reason it's only placing 2 images on the board. Note this is just practice for getting the images to display. I'm going to try it now with a 2D array to place the pieces correctly. But if anyone has any insight on the below code and why it would only display two images. I'd be thankful. My debugging skills still need work.

 
 public PictureBox[] test = new PictureBox[3];

for (int i = 0; i < 3; i++) {
                test[i] = new PictureBox();
                test[i].Image = System.Drawing.Image.FromFile("Piece" + i + ".png");
                test[i].SetBounds(i * 50, i * 50, 30, 30);
                test[i].SizeMode = PictureBoxSizeMode.StretchImage;
                this.Controls.Add(test[i]);
                i++;
            }
            this.Controls.Add(cells);

This post has been edited by Aramyth: 06 December 2011 - 11:26 PM

Was This Post Helpful? 0
  • +
  • -

#17 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Best Way to Draw a Chessboard?

Posted 06 December 2011 - 11:45 PM

Because you're incrementing your loop control variable twice per iteration. Once in the for loop declaration, and once at the end of the loop. So on the first pass, i is 0, but on the next, i is 2.

To discover this yourself, set a breakpoint right before the loop, open the "Locals" pallet (or add a watch for it), and watch its value change as you F11 through the steps.
Was This Post Helpful? 1
  • +
  • -

#18 Aramyth   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 51
  • Joined: 14-January 10

Re: Best Way to Draw a Chessboard?

Posted 07 December 2011 - 03:51 PM

I got that when I looked it at this afternoon. Sometimes programming when you're over tired isn't good. lol Thanks.

To Uzi, I've been looking at your code and playing with it learn how it works. I'm wondering, how exactly you'd access each cell if you needed to. Obviously, for holding a piece, how could you give it the cell position?

Again, I always seem to ask questions first and then go to play with it, so if I figure something out, I'll post back again soon.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2