-1

This is my first time asking a question so please be patient.

I am just starting to create a chess game on C#. I've been researching and as of today I have no clue how to begin!

I can print on console the array but I need to create graphics.

The question is how do I create an array that holds both, an integer and an image. An int because I am assigning numbers to the chess pieces, like for instance the white pawns are 1 and the black pawns are 2.

But also related to any piece on the board beside the number is an image and right here is where i am lost.

2

1 Answer 1

0

You need to create a wrapper that contains your information for the field. A class is the way to go here.

In your cass this would be something along those lines:

public class ChessPiece
{
    //hold figure value
    public int Number { get; set; }
    //display image on baord
    public string ImagePath { get; set; }
}

If I remeber correctly, a chess baord is 8 by 8 fields, which means you would need a 2-dimensional array with the length of 8.

ChessPiece[,] Board = new ChessPiece[8,8];

Remember, that arrays are 0-index based. So while they hold 8 objects. The first object starts at the index 0 and the last is at 7.

This would answer you question on how to store image information in an array. However, console applications are not suited to display graphics. You might need to read up further on WPF / Windows Forms, after you have dealt with the very basic principles of programming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.