C
C#β€’3mo ago
Nicolas Matheisen

βœ… Hey I am a beginner coder and lf some tipps to write clean code.

string[] letters = new string[8];
for (int i = 0; i < letters.Length; i++)
letters[i] = ((char)(65 + i)).ToString();
for (int i = 8; i > 0; i--)
{
for (int j = 0; j < letters.Length; j++)
{
Console.Write(letters[j] + (i) + " ");
}
Console.WriteLine();
}
string[] letters = new string[8];
for (int i = 0; i < letters.Length; i++)
letters[i] = ((char)(65 + i)).ToString();
for (int i = 8; i > 0; i--)
{
for (int j = 0; j < letters.Length; j++)
{
Console.Write(letters[j] + (i) + " ");
}
Console.WriteLine();
}
I try to build a Chess. But my question is it's clean code? or how to change it that u can read it easyer and any Idea how I can build the next step I need the game peace(german: Spielfiguren) And I only learn the basics of loops and Arrays. I am not sure if i try to build a array... ty for all hints/advices🌞😊
6 Replies
ZacharyPatten
ZacharyPattenβ€’3mo ago
that isn't really enough code/context for us to help much. Can you do what that code does in a smaller amount of code? yes, but you should probably have a model of a chess board and depending on how you make your model might change how you do this code. For example you may want to override the ToString method on a CheckersBoard so you just call myCheckerBoard.ToString() ----- also, rather than using coordinates, imo it is much more user friendly to use arrow keys to select the chess piece and move for example...
ZacharyPatten
ZacharyPattenβ€’3mo ago
No description
ZacharyPatten
ZacharyPattenβ€’3mo ago
here is an example of a console checkers game, and you use the arrow keys to move the [ ] cursor around rather than having to type "A3" or "D5" If you would like a link to that checkers example just ask πŸ™‚

Checkers

╔═══════════════════╗
8 β•‘ Β· β—™ Β· β—™ Β· β—™ Β· β—™ β•‘ β—‹ = Black
7 β•‘ β—™ Β· β—™ Β· β—™ Β· β—™ Β· β•‘ ☺ = Black King
6 β•‘ Β· β—™ Β· β—™ Β· β—™ Β· β—™ β•‘ β—™ = White
5 β•‘ Β· Β· Β· Β· Β· Β· Β· Β· β•‘ ☻ = White King
4 β•‘ Β· Β· Β· Β· Β· Β· Β· Β· β•‘
3 β•‘ β—‹ Β·[β—‹]Β· β—‹ Β· β—‹ Β· β•‘ Taken:
2 β•‘ Β· β—‹ Β· β—‹ Β· β—‹ Β· β—‹ β•‘ 0 x β—™
1 β•‘ β—‹ Β· β—‹ Β· β—‹ Β· β—‹ Β· β•‘ 0 x β—‹
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
A B C D E F G H

Black's turn

Checkers

╔═══════════════════╗
8 β•‘ Β· β—™ Β· β—™ Β· β—™ Β· β—™ β•‘ β—‹ = Black
7 β•‘ β—™ Β· β—™ Β· β—™ Β· β—™ Β· β•‘ ☺ = Black King
6 β•‘ Β· β—™ Β· β—™ Β· β—™ Β· β—™ β•‘ β—™ = White
5 β•‘ Β· Β· Β· Β· Β· Β· Β· Β· β•‘ ☻ = White King
4 β•‘ Β· Β· Β· Β· Β· Β· Β· Β· β•‘
3 β•‘ β—‹ Β·[β—‹]Β· β—‹ Β· β—‹ Β· β•‘ Taken:
2 β•‘ Β· β—‹ Β· β—‹ Β· β—‹ Β· β—‹ β•‘ 0 x β—™
1 β•‘ β—‹ Β· β—‹ Β· β—‹ Β· β—‹ Β· β•‘ 0 x β—‹
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
A B C D E F G H

Black's turn
there is the same content from the screenshot as text ---- in terms of your code, there are a bunch of ways to write it. here is another:
for (char y = '8'; y >= '1'; y--)
{
for (char x = 'A'; x <= 'H'; x++)
{
Console.Write($" {x}{y}");
}
Console.WriteLine();
}
for (char y = '8'; y >= '1'; y--)
{
for (char x = 'A'; x <= 'H'; x++)
{
Console.Write($" {x}{y}");
}
Console.WriteLine();
}
Nicolas Matheisen
Nicolas Matheisenβ€’3mo ago
awwww awesome I try to build this first holy this look 1000 times better :0 uhhhh it's possibile if u push the arrows u can change the [ ] awww ok interesting. Now I need to learn how I can use this cause I don't know how I can programm if I push right curse jump to the right but first I build this How this thing is called maybe A prototype?
ZacharyPatten
ZacharyPattenβ€’3mo ago
as mentioned if you want examples of using arrow keys in the console just ask. i have lots of examples
Nicolas Matheisen
Nicolas Matheisenβ€’3mo ago
Yeah first I build this output and then I program I think it called functions ???
Want results from more Discord servers?
Add your server
More Posts