My homework is to move a new ufo with key arrows. We already done the main program in class. I have no clue how to do it. I would be obliged if someone could help!
(I am a beginner)
I am Hungarian so some help might come handy:
mozgat - move the ufo
torol - delete
szin - color
rajzol - show the ufo on the screen
kep - the ufo's look
What I have tried:
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Ufotip ufo1 = new Ufotip(40, 12, "\\-O-/", ConsoleColor.Red);
Ufotip ufoLe = new Ufotip(20, 20, "|-O-|", ConsoleColor.Green);
Ufotip ufoE = new Ufotip(30, 20, ">-----------/",
ConsoleColor.Yellow);
Ufotip ufoFV = new Ufotip(10, 10, "<-|O|->", ConsoleColor.Blue);
Ufotip ufoV = new Ufotip(60, 10, "_/\\_", ConsoleColor.White);
Ufotip ufoEn = new Ufotip(10, 15, "/--O--\\" , ConsoleColor.Magenta);
Ufotip ufoseven = new Ufotip(5, 5, "U-U", ConsoleColor.Cyan);
while (true)
{
ufo1.rajzol();
ufoLe.rajzol();
ufoE.rajzol();
ufoFV.rajzol();
ufoV.rajzol();
ufoEn.rajzol();
Thread.Sleep(100);
ufo1.torol();
ufoLe.torol();
ufoFV.torol();
ufoV.torol();
ufoEn.torol();
ufo1.mozgat(1, 0);
ufoLe.mozgat(0, 1);
ufoFV.mozgat(0, r.Next(-1, 1 + 1));
ufoV.mozgat(r.Next(-1, 2), r.Next(-1, 2));
}
}
}
class Ufotip
{
int x, y;
string kep;
ConsoleColor szin;
public Ufotip(int x, int y, string kep, ConsoleColor szin)
{
this.x = x;
this.y = y;
this.kep = kep;
this.szin = szin;
}
public void rajzol()
{
if (x < 0) { x = 79; }
if (x > 79) { x = 0; }
if (y < 0) { y = 23; }
if (y > 23) { y = 0; }
Console.SetCursorPosition(x, y);
Console.ForegroundColor = szin;
Console.WriteLine(kep);
Console.ResetColor();
}
public void torol()
{
Console.SetCursorPosition(x, y);
for (int i = 0; i < kep.Length; i++)
{
Console.Write(" ");
}
Console.WriteLine();
}
public void mozgat(int dx, int dy)
{
x += dx;
y += dy;
}
}