1
我有一個繪製方法應該繪製出一個盒子,但是我的問題是它只繪製盒子的寬度,而不是高度。我的繪製方法不繪製高度
這裏有一個代碼片段:
class ColoredBox : Box
{
protected ConsoleColor backColor;
public ColoredBox(Point p, int width, int height, ConsoleColor backColor)
: base(p, width, height)
{
this.backColor = backColor;
}
public virtual void Draw()
{
for (int j = 0; j < height; j++)
{
Console.SetCursorPosition(p.X, p.Y);
Console.BackgroundColor = backColor;
for (int i = 0; i <= width; i++)
Console.Write(' ');
}
}
問題似乎是Draw()
方法,我不能把它打印出來,這樣我怎麼能解決這個簡單的問題?
你不破最後'for'循環後,新的生產線。 – Aphelion 2013-02-11 10:40:16
http://i45.tinypic.com/6h2fk2.jpg我的打印結果。它沒有繪製寬度,這個算法在某種程度上是不正確的。 – user2059474 2013-02-11 10:40:39
應該是'SetCursorPosition(p.Y + j)' – Rotem 2013-02-11 10:42:14