It's time to remember that C # is an object-oriented language and add a couple of your own types to describe the shapes on the field.
First, let's set the colors of the figures by listing
enum FigureColor { White, Black }
Now define the shape. Since the figure can not change color during the game - we will make the property responsible for the color read-only.
public class ChessFigure { //буквенное обозначение public char Letter { get; set; } //цвет фигуры public FigureColor Color { get; private set; } //конструктор public ChessFigure(FigureColor color, char letter) { Color = color; Letter = letter; } }
Now the creation and output of a shape in the console can be done
ChessFigure one = new ChessFigure(FigureColor.Black, 'П'); if(one.Color == FigureColor.Black) Console.ForegroundColor = ConsoleColor.Red; if(one.Color == FigureColor.White) Console.ForegroundColor = ConsoleColor.White; Console.Write(one.Letter); Console.ResetColor();
This is only an idea that can and should be developed further. A similar technique can be used for chessboard cells.
Try to immediately separate the logic of the program from its visualization, it will help to avoid difficulties with adding new functions and changing existing ones.
charoccupied, but most likely only the first 127 characters, but if chess is, then even less so. The high bit, for example, can be taken under the color. Then numbers up to 127 will be black, and from 128 to 255 will be white. This is one of several options. - Zealintcharis a type, variables of this type can take a very wide range of values. In addition, you create your ownChar. What prevents to add to your class a field that stores the value to be output and a field that stores color? In addition: if you wanted to change the color that the console will display, you cannot do with a single line. Color should be set for each output separately. - Grundy