Aquí les dejo el código de la pelotita en C#
static void Main(string[] args)
{
String pelotita = "O";
int posicionX = 40;
int direccion = 1;
while (true) { //-- para cortar el programa usar Control + C
Console.Clear();
Console.CursorTop = 15;
Console.CursorLeft = posicionX;
if (direccion == 1) {
posicionX = posicionX + 1;
if (posicionX > 70) {
posicionX = 70;
direccion = -1;
}
} else {
//direccion es -1
posicionX = posicionX - 1;
if (posicionX < 10) {
posicionX = 10;
direccion = 1;
}
}
Console.Write(pelotita); //pelotita = pelotita + "O";
System.Threading.Thread.Sleep(150);
} // fin del While
}
static void Main(string[] args)
{
String pelotita = "O";
int posicionX = 40;
int direccion = 1;
while (true) { //-- para cortar el programa usar Control + C
Console.Clear();
Console.CursorTop = 15;
Console.CursorLeft = posicionX;
if (direccion == 1) {
posicionX = posicionX + 1;
if (posicionX > 70) {
posicionX = 70;
direccion = -1;
}
} else {
//direccion es -1
posicionX = posicionX - 1;
if (posicionX < 10) {
posicionX = 10;
direccion = 1;
}
}
Console.Write(pelotita); //pelotita = pelotita + "O";
System.Threading.Thread.Sleep(150);
} // fin del While
}
Comentarios
Publicar un comentario