Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends, I wrote some code to move the king in chess game; can you tell me where is the problem of this code that king doesn't move? Thanks.

C#
if (pictureBox34.Image ==  chess9.Properties.Resources.siyahsah2))
{
    f();
}

C#
public void picarray()
{
    pic[0, 4] = pictureBox34;
}

C#
public void f()
{
    int x = 3;
    mode = hold;
    int y = 3;
    for (int i = 1; i < x; i++)
    {
        for (int j = 1; j < y; j++)
        {
            pic[i, j] = pic[i + 1, j + 1];
            pic[i, j] = pic[i - 1, j - 1];
        }
    pic[i, j].Image = Image.FromFile("pic/siyahsah2.jpg");
}
Posted
Updated 4-Dec-10 7:29am
v7
Comments
Toli Cuturicu 4-Dec-10 5:05am    
Don't use PictureBoxes for this purpose. I believe you have already been told this.
Oh, and use descriptive method names! Not f()!
LloydA111 4-Dec-10 11:10am    
Don't use the Image.FromFile like you are doing, as it will be checking the file EVERY time you do that.
CPallini 4-Dec-10 11:21am    
All other criticism to your code are pretty coorrect, but, what is the intended logic for King movement in your function (and what should the output, exactly? i.e. in which direction the King should go?)?
arashmobileboy 4-Dec-10 11:24am    
it goes one place to left,right,up,down,i updated my question
Dr.Walt Fair, PE 4-Dec-10 17:18pm    
Wasn't this already asked and answered??

You shouldn't be using a single PictureBox to do this. All of the board and the knight should be rendered in the Paint event of a Panel control.
 
Share this answer
 
Comments
arashmobileboy 4-Dec-10 11:02am    
can you explain me more?thanks
I don't have to explain this any further - it's already been explained to you before in the first two questions you posted about this. All you have to do is read the answers and follow and read the links that were provided on how to render this yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900