using System;
using System.Globalization;
using System.Speech.Recognition; // No olvidar. Micro.
using System.Speech.Synthesis; // No olvidar. Altavoz.
using System.Threading;
namespace Calculo_cilindro_voz_Consola_04
{
internal class Program
{
// Para sustituir punto por coma.
static CultureInfo currentCulture = CultureInfo.InstalledUICulture;
static NumberFormatInfo numberFormat = (NumberFormatInfo)currentCulture.NumberFormat.Clone();
static void Main(string[] args)
{
#region Configuración ventana.
// Título de la ventana.
Console.Title = "Cálculo litros de un depósito";
// Tamaño de la ventana, x, y.
// Tamaño de la ventana, x, y.
const int anchoX = 80;
const int altoY = 30;
Console.SetWindowSize(anchoX, altoY);
// Color de fondo.
Console.BackgroundColor = ConsoleColor.Black;
// Color de las letras.
Console.ForegroundColor = ConsoleColor.Gray;
// Limpiar pantalla y dejarlo todo en color de fondo.
Console.Clear();
// Visible el cursor.
Console.CursorVisible = false;
#endregion
#region Variables.
// Variables.
const double Pi = 3.14;
float PI = Convert.ToSingle(Pi);
string stringRadio, stringAltura, stringNivelAgua;
float radio, altura, volumen, litros, nivelAgua, resultadoPorcentaje,
resultadoLitros, volumenLitros, mitadBarra, cantidadTubosLitros,
totalLitros, cantidadTubos;
#endregion
numberFormat.NumberDecimalSeparator = ".";
do
{
try
{
// Inicializar una nueva instancia de SpeechSynthesizer.
using (SpeechSynthesizer altavoz
= new SpeechSynthesizer
()) {
#region Introducción de datos en la pantalla.
// Configure la salida de audio.
altavoz.SetOutputToDefaultAudioDevice();
// Velocidad de la voz.
altavoz.Rate = -2; // Valores entre -10 a 10.
// Volumen de la voz.
altavoz.Volume = 100; // Valores entre 0 y 100.
// Limpiar pantalla.
Console.Clear();
// Dibujado cuadro.
CuadroNuevo();
// Introducción de datos.
Console.SetCursorPosition(3, 3);
Console.Write("Introduce el radio en m.: ");
altavoz.Speak("Introduce el radio en metros.");
stringRadio = Console.ReadLine();
radio = CambiarComaXPunto(stringRadio);
Console.SetCursorPosition(3, 5);
Console.Write("Introduce la altura del tubo en m.: ");
altavoz.Speak("Introduce la altura del tubo en metros.");
stringAltura = Console.ReadLine();
altura = CambiarComaXPunto(stringAltura);
Console.SetCursorPosition(3, 7);
Console.Write("Introduce altura del agua. Máximo es de {0} m.: ", altura);
altavoz.Speak("Introduce altura del agua. Máximo es de " + altura + "metros.");
stringNivelAgua = Console.ReadLine();
nivelAgua = CambiarComaXPunto(stringNivelAgua);
Console.SetCursorPosition(3, 9);
Console.Write("Introduce cantidad de tubos: ");
altavoz.Speak("Introduce cantidad de tubos.");
cantidadTubos = int.Parse(Console.ReadLine());
CuadroNuevo();
#endregion
#region Cálculos.
// Cálculo volumen.
volumen = PI * (radio * radio) * altura;
// Cálculo litros.
litros = volumen * 1000;
// Cálculo porcentaje en % del litro de agua.
resultadoPorcentaje = nivelAgua * (100 / altura);
// Cálculo litros de agua.
volumenLitros = PI * (radio * radio) * nivelAgua;
resultadoLitros = volumenLitros * 1000;
// Cálculo litros por cantidad de tubos
cantidadTubosLitros = cantidadTubos * resultadoLitros;
// Cálculo cantidad de litros con total de tubos.
totalLitros = litros * cantidadTubos;
#endregion
#region Dibujado barra de progreso.
// Posición.
Console.SetCursorPosition(3, 4);
// Dibujo de la barra.
Console.WriteLine();
Console.SetCursorPosition(3, 5);
Console.WriteLine("0 % 50 % 100 %");
Console.SetCursorPosition(3, 6);
Console.WriteLine("┌────────────────────────┬───────────────────────┐");
// Mitad de la barra para que no sea muy grande en la pantalla.
mitadBarra = resultadoPorcentaje / 2;
if (resultadoPorcentaje <= 15)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (resultadoPorcentaje <= 40)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else if (resultadoPorcentaje <= 100)
{
Console.ForegroundColor = ConsoleColor.Green;
}
if (mitadBarra > 50)
{
mitadBarra = 50;
}
Console.SetCursorPosition(3, 7);
// Rellenar la barra.
for (int i = 1; i <= mitadBarra; i++)
{
Console.Write("█");
}
Console.ForegroundColor = ConsoleColor.Gray;
// Si llega mayor a 100 se pone el # en rojo.
if (resultadoPorcentaje > 100)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("#");
Console.ForegroundColor = ConsoleColor.Gray;
}
#endregion
#region Mostrar textos en pantalla.
// Cursor invisible.
Console.CursorVisible = false;
// Muestra porcentaje del depósito.
Console.ForegroundColor = ConsoleColor.Gray;
Console.SetCursorPosition(3, 9);
Console.Write("Porcentaje: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(resultadoPorcentaje.ToString("N2") + " %.");
altavoz.Speak("Cantidad de agua que hay en el depósito es de " +
//resultadoPorcentaje.ToString("N2") + "%.");
resultadoPorcentaje + "%.");
// Muestra cantidad de agua que hay actualmente y el total.
Console.ForegroundColor = ConsoleColor.Gray;
Console.SetCursorPosition(3, 11);
Console.Write("Litros de agua: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(resultadoLitros.ToString("N2"));
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" / " + litros.ToString("N2") + " L. total de un tubo.");
altavoz.Speak("Cantidad de litros de agua en un tubo de " +
resultadoLitros.ToString("N2") + "de " +
litros.ToString("N2") + " litros total de un tubo.");
// Cantidad de tubos sin contar la base conectada, solo tubos independiente.
Console.ForegroundColor = ConsoleColor.Gray;
Console.SetCursorPosition(3, 13);
Console.Write("Cantidad de Litros total por " + cantidadTubos + " tubos: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(cantidadTubosLitros.ToString("N2"));
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" / " + totalLitros.ToString("N2") + " L.");
altavoz.Speak("Cantidad de litros en total por " + cantidadTubos.ToString("N2") +
" tubos: " + cantidadTubosLitros.ToString("N2") +
" de " + totalLitros.ToString("N2") + " litros.");
#endregion
}
}
catch (FormatException)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Red;
Console.Clear();
Console.SetCursorPosition(8, 5);
Console.Write(@"La cadena de entrada no tiene el
formato correcto.
Solo debes introducir números y comas.");
Console.CursorVisible = false;
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
}
// Pulse cualquier tecla para continuar.
Console.ReadKey();
} while (true);
}
private static void DibujarMarco(int v1, int v2, int v3, int v4)
{
gotoXY(v1, v2, "╔");
for (int i = v1 + 1; i < v3; i++)
{
gotoXY(i, v2, "═");
}
gotoXY(v3, v2, "╗");
for (int i = v2 + 1; i < v4; i++)
{
gotoXY(v3, i, "║");
}
gotoXY(v3, v4, "╝");
for (int i = v3 - 1; i > v1; i--)
{
gotoXY(i, v4, "═");
}
gotoXY(v1, v4, "╚");
for (int i = v4 - 1; i > v2; i--)
{
gotoXY(v1, i, "║");
}
}
private static void gotoXY(int x, int y, string cadena)
{
Console.SetCursorPosition(x, y);
Console.WriteLine(cadena);
Thread.Sleep(10);
}
private static void CuadroNuevo()
{
// Limpiar pantalla.
Console.Clear();
// Cursor visible.
Console.CursorVisible = false;
// Dibujo de cuadro o marco.
DibujarMarco(1, 1, 65, 25);
// Cursor visible.
Console.CursorVisible = true;
}
private static float CambiarComaXPunto(string sNro)
{
float n = 0.0f;
String nAux = sNro.Replace(',', '.');
float.TryParse(nAux, NumberStyles.Any, numberFormat, out n);
return n;
}
}
}