I'm coding a game and I am struggling in deleting my stickman before I draw another one.
I could just use Console.Clear()
but it clears the whole console and I only need to delete the previous stickman.
I'm trying to use:
private static string path = @"c:..\..\characters\";
private string file;
private int xpast = 0;
private int ypast = 0;
private int LinhasSeparacao;
public Graphics()
{
}
public Graphics(string file)
{
this.file = file;
StreamReader sr = new StreamReader(path + file);
LinhasSeparacao = 0;
do
{
LinhasSeparacao++;
}
while (sr.ReadLine() != "separar");
sr.Close();
}
public void Draw(int x, int y,bool forma = true)
{
string[] persona = File.ReadAllLines(path + file);
LimparAnterior(forma,persona,x,y);
//Console.Clear();
if (forma)
{
for (int i = 0; i < LinhasSeparacao - 1; i++)
{
Console.SetCursorPosition(x, y + i);
Console.Write(persona[i]);
}
}
else
{
int j= 0;
for (int i = LinhasSeparacao; i <persona.Length-1; i++)
{
Console.SetCursorPosition(x, y + j);
Console.Write(persona[i]);
j++;
}
}
xpast = x;
ypast = y;
}
private void LimparAnterior(bool forma,string[] persona, int xlive, int ylive)
{
int i = 0;
for (i = 0 ; i < LinhasSeparacao; i++)
{
Console.SetCursorPosition(xpast > 0? xpast -1:xpast,ypast + i);
Console.Write(" ",persona[i].Length);
}
}
This is my class to draw the new character, it needs x and y coordinates. I use a file to the drawing and put all the line into a array called persona. I'm drawing after someone press the arrows to make the little guy move.
If you need more information, say something. Here is the link to github: https://github.com/digaso/Wizardoft