C
C#4mo ago
Mathall

Cannot center my top numbers with rest of written characters

hey all trying to make a minesweeper game, but I cannot seem to center the X number key above the characters, any help would be greatly appreciated, here;s the function
C#
public void RevealBoard()
{
//Add space + bar before X number key
Console.Write(" |");

//write X number key
for (int i = 0; i < Columns; i++)
{
Console.Write($" {i}");
}
//Add divider line and cross before full divider line
Console.Write("\n--+");

//write divider line
for (int i = 0; i < Columns; i++)
{
Console.Write($"--");
}
//start next line
Console.WriteLine();


//for each tile in the board write its value
for (int i = 0; i < Rows; i++)
{
//adds Y key before each new row
if (i<10)
{
Console.Write($" {i}|");
} else if (i<99)
{
Console.Write($"{i}|");
}

for (int j = 0; j < Columns; j++)
{
Thread.Sleep(10);
ChangeColor(BoardArr[i,j]); //write each character with own color
}
//every row complete, move to the next row
Console.WriteLine();
}
}
C#
public void RevealBoard()
{
//Add space + bar before X number key
Console.Write(" |");

//write X number key
for (int i = 0; i < Columns; i++)
{
Console.Write($" {i}");
}
//Add divider line and cross before full divider line
Console.Write("\n--+");

//write divider line
for (int i = 0; i < Columns; i++)
{
Console.Write($"--");
}
//start next line
Console.WriteLine();


//for each tile in the board write its value
for (int i = 0; i < Rows; i++)
{
//adds Y key before each new row
if (i<10)
{
Console.Write($" {i}|");
} else if (i<99)
{
Console.Write($"{i}|");
}

for (int j = 0; j < Columns; j++)
{
Thread.Sleep(10);
ChangeColor(BoardArr[i,j]); //write each character with own color
}
//every row complete, move to the next row
Console.WriteLine();
}
}
No description
9 Replies
Mathall
MathallOP4mo ago
its worth noting that below each is a whitespace, then a character (if nothing there then its just another whitespace) Ok I actually found a fix really fast, just added another whitespace, and shorted the space between the double digits after 9
C#
public void RevealBoard()
{
//Add space + bar before X number key
Console.Write(" |");

//write X number key
for (int i = 0; i < Columns; i++)
{
//adds X key above the columns
if (i<10)
{
Console.Write($" {i} ");
} else if (i<99)
{
Console.Write($" {i}");
}
}
//Add divider line and cross before full divider line
Console.Write("\n--+");

//write divider line
for (int i = 0; i < Columns; i++)
{
Console.Write($"---");
}
//start next line
Console.WriteLine();


//for each tile in the board write its value
for (int i = 0; i < Rows; i++)
{
//adds Y key before each new row
if (i<10)
{
Console.Write($" {i}|");
} else if (i<99)
{
Console.Write($"{i}|");
}

for (int j = 0; j < Columns; j++)
{
Thread.Sleep(10);
ChangeColor(BoardArr[i,j]); //write each character with own color
}
//every row complete, move to the next row
Console.WriteLine();
}
}
C#
public void RevealBoard()
{
//Add space + bar before X number key
Console.Write(" |");

//write X number key
for (int i = 0; i < Columns; i++)
{
//adds X key above the columns
if (i<10)
{
Console.Write($" {i} ");
} else if (i<99)
{
Console.Write($" {i}");
}
}
//Add divider line and cross before full divider line
Console.Write("\n--+");

//write divider line
for (int i = 0; i < Columns; i++)
{
Console.Write($"---");
}
//start next line
Console.WriteLine();


//for each tile in the board write its value
for (int i = 0; i < Rows; i++)
{
//adds Y key before each new row
if (i<10)
{
Console.Write($" {i}|");
} else if (i<99)
{
Console.Write($"{i}|");
}

for (int j = 0; j < Columns; j++)
{
Thread.Sleep(10);
ChangeColor(BoardArr[i,j]); //write each character with own color
}
//every row complete, move to the next row
Console.WriteLine();
}
}
Mathall
MathallOP4mo ago
here is the fixed version if anyone is wondering
No description
substitute
substitute4mo ago
The real solution would be to use a monospaced font
Mathall
MathallOP4mo ago
I personally dont know how to change the font in the console
substitute
substitute4mo ago
Sure, but I wouldn’t try to match a variable width font, it’ll break on another user’s system if the widths are different for their font
Mathall
MathallOP4mo ago
Oh, interesting, I thought the font was just constant, is there a way in the code itself to change the font, or would I have to add another resource
substitute
substitute4mo ago
Yes, and also consider the width of your columns You have 1 and you have 10 Make sure the width is consistent 01 and 10 (or space + 1)
Mathall
MathallOP4mo ago
Yea, right now I have it as if less than 10 {" # "} if more than 9 {" #"}
substitute
substitute4mo ago
Formatting should allow you to do fixed with automatically See string.format
Want results from more Discord servers?
Add your server