|
| 1 | +/* |
| 2 | +_____________________________________ |
| 3 | +https://github.com/kenysdev |
| 4 | +2024 - C# |
| 5 | +_____________________________________ |
| 6 | +47 CALENDARIO DE ADVIENTO |
| 7 | +------------------------------------ |
| 8 | +
|
| 9 | + * EJERCICIO: |
| 10 | + * ¡Cada año celebramos el aDEViento! 24 días, 24 regalos para |
| 11 | + * developers. Del 1 al 24 de diciembre: https://adviento.dev |
| 12 | + * |
| 13 | + * Dibuja un calendario por terminal e implementa una |
| 14 | + * funcionalidad para seleccionar días y mostrar regalos. |
| 15 | + * - El calendario mostrará los días del 1 al 24 repartidos |
| 16 | + * en 6 columnas a modo de cuadrícula. |
| 17 | + * - Cada cuadrícula correspondiente a un día tendrá un tamaño |
| 18 | + * de 4x3 caracteres, y sus bordes serán asteríscos. |
| 19 | + * - Las cuadrículas dejarán un espacio entre ellas. |
| 20 | + * - En el medio de cada cuadrícula aparecerá el día entre el |
| 21 | + * 01 y el 24. |
| 22 | + * |
| 23 | + * Ejemplo de cuadrículas: |
| 24 | + * **** **** **** |
| 25 | + * *01* *02* *03* ... |
| 26 | + * **** **** **** |
| 27 | + * |
| 28 | + * - El usuario seleccioná qué día quiere descubrir. |
| 29 | + * - Si está sin descubrir, se le dirá que ha abierto ese día |
| 30 | + * y se mostrará de nuevo el calendario con esa cuadrícula |
| 31 | + * cubierta de asteríscos (sin mostrar el día). |
| 32 | + * |
| 33 | + * Ejemplo de selección del día 1 |
| 34 | + * **** **** **** |
| 35 | + * **** *02* *03* ... |
| 36 | + * **** **** **** |
| 37 | + * |
| 38 | + * - Si se selecciona un número ya descubierto, se le notifica |
| 39 | + * al usuario. |
| 40 | +*/ |
| 41 | + |
| 42 | +string[,] mtx = new string[4, 6]; |
| 43 | +for (int i = 0; i < 4; i++) |
| 44 | +{ |
| 45 | + for (int j = 0; j < 6; j++) |
| 46 | + { |
| 47 | + mtx[i, j] = $"*{(i * 6 + j + 1):00}*"; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +string ln = string.Join(" ", Enumerable.Repeat("****", 6)); |
| 52 | + |
| 53 | +while (true) |
| 54 | +{ |
| 55 | + for (int i = 0; i < 4; i++) |
| 56 | + { |
| 57 | + Console.WriteLine(ln); |
| 58 | + int currentRow = i; |
| 59 | + |
| 60 | + for (int j = 0; j < 6; j++) |
| 61 | + { |
| 62 | + Console.Write(mtx[currentRow, j] + " "); |
| 63 | + } |
| 64 | + Console.WriteLine("\n" + ln + "\n"); |
| 65 | + } |
| 66 | + |
| 67 | + Console.Write("Día a descubrir: "); |
| 68 | + string? day = Console.ReadLine(); |
| 69 | + |
| 70 | + if (!int.TryParse(day, out int dayInt)) |
| 71 | + { |
| 72 | + Console.WriteLine("Entrada inválida. Debe ser un número."); |
| 73 | + continue; |
| 74 | + } |
| 75 | + |
| 76 | + if (dayInt < 1 || dayInt > 24) |
| 77 | + { |
| 78 | + Console.WriteLine("Día inválido, debe ser entre 1 y 24."); |
| 79 | + continue; |
| 80 | + } |
| 81 | + |
| 82 | + int r = (dayInt - 1) / 6; |
| 83 | + int c = (dayInt - 1) % 6; |
| 84 | + |
| 85 | + if (mtx[r, c] == "****") |
| 86 | + { |
| 87 | + Console.WriteLine($"El día {day} ya está descubierto."); |
| 88 | + continue; |
| 89 | + } |
| 90 | + |
| 91 | + mtx[r, c] = "****"; |
| 92 | +} |
0 commit comments