Ejercicio
Clase ScreenText
Objetivo
Cree una clase ScreenText, para mostrar un texto determinado en coordenadas de pantalla especificadas. Debe tener un constructor que recibirá X, Y y la cadena a escribir. También debe tener 3 setters y un método "Display".
Cree una clase CenteredText, basada en ScreenText, para mostrar texto centrado (horizontalmente) en una fila determinada de la pantalla. Su constructor recibirá solo Y y el texto. SetX no debe cambiar la posición horizontal.
Cree una clase FramedText, para mostrar texto centrado y dentro de un rectángulo. Recibirá la fila inicial y el texto.
Finalmente, cree un programa de prueba para todos ellos, que creará un objeto de cada tipo y los mostrará.
Código de Ejemplo
using System;
namespace TextScreen
{
class CenteredText : ScreenText
{
}
}
using System;
namespace TextScreen
{
class Program
{
static void Main(string[] args)
{
}
}
}
using System;
namespace TextScreen
{
class ScreenText
{
protected int x, y;
protected string text;
public ScreenText(int x, int y, string text)
{
this.x = x;
this.y = y;
this.text = text;
}
public void SetX(int x)
{
this.x = x;
}
public void SetY(int y)
{
this.y = y;
}
public void SetText(string text)
{
this.text = text;
}
public void Display()
{
Console.SetCursorPosition(x, y);
Console.Write(text);
}
}
}