-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
177 lines (138 loc) · 4.63 KB
/
Program.cs
File metadata and controls
177 lines (138 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using Personajes;
public class Laberinto
{
public static int ancho = 15;
public static int largo = 17;
public static int[,] laberinto = new int[ancho, largo];
public static Random random = new Random();
static (int x, int y) puntoinicial;
static (int x, int y) puntofinal;
public static List<Azucena> Lista;
public void Agregodepersonajes(Azucena azucena)
{
azucena.PosicionAzucena = 2;
azucena.PosicionAzucenay = 2;
Lista.Add(azucena);
}
public static void Creacion( )
{
for (int i = 0; i < ancho; i++)
{
for (int j = 0; j < largo; j++)
{
laberinto[i, j] = 1;
}
}
(int dx, int dy)[] movimientos = { (0, 2), (2, 0), (-2, 0), (0, -2) };
int inicial = random.Next(1, ancho / 2) * 2;
int final = random.Next(1, largo / 2) * 2;
laberinto[inicial, final] = 0;
var Stack = new Stack<(int x, int y)>();
Stack.Push((inicial, final));
while (Stack.Count > 0)
{
var (x, y) = Stack.Pop();
List<(int dx, int dy)> movimientosprobables = new List<(int dx, int dy)>();
foreach (var (dx, dy) in movimientos)
{
int celdadireccion = x + dx;
int celdadirecciony = y + dy;
if (celdadireccion > 0 && celdadireccion < ancho && celdadirecciony > 0 && celdadirecciony < largo && laberinto[celdadireccion, celdadirecciony] == 1)
{
movimientosprobables.Add((dx, dy));
}
}
Mezclar(movimientosprobables);
foreach (var (dx, dy) in movimientosprobables)
{
int celdadireccion = x + dx;
int celdadirecciony = y + dy;
laberinto[x + dx / 2, y + dy / 2] = 0;
laberinto[celdadireccion, celdadirecciony] = 0;
Stack.Push((celdadireccion, celdadirecciony));
}
}
}
static void Diamond(int diamante, int cantidad)
{
for(int i = 0; i < cantidad; i++) {
int position;
int positiony;
do
{
position = random.Next(1, ancho - 1);
positiony = random.Next(1, largo - 2);
}
while (laberinto[position, positiony] == 1);
laberinto[position, positiony] = diamante;
}
}
static void Mezclar(List<(int, int)> lista)
{
for (int i = lista.Count - 1; i > 0; i--)
{
int j = random.Next(i + 1);
var temp = lista[i];
lista[i] = lista[j];
lista[j] = temp;
}
}
static void Ruta()
{
do
{
puntoinicial.x = random.Next(1, ancho - 1);
puntoinicial.y = random.Next(1, largo - 1);
}
while (laberinto[puntoinicial.x, puntoinicial.y] != 0);
do
{
puntofinal.x = random.Next(1, ancho - 1);
puntofinal.y = random.Next(1, largo - 1);
}
while (laberinto[puntofinal.x, puntoinicial.y] != 0 || (puntofinal.x == puntoinicial.x && puntofinal.y == puntoinicial.y));
}
static void Generacionmaze()
{
int anchoConsole = Console.WindowWidth;
int largoConsole = Console.WindowHeight;
int central = (anchoConsole - largoConsole) / 2;
for (int i = 0; i < ancho; i++)
{
Console.Write(new string(' ', central));
for (int j = 0; j < largo; j++)
{
if (laberinto[i, j] == 0)
{
Console.ForegroundColor = ConsoleColor.Green;
//Console.BackgroundColor = ConsoleColor.Green;
}
if(laberinto[i, j] == 1)
{
Console.ForegroundColor = ConsoleColor.Blue;
//Console.BackgroundColor = ConsoleColor.Blue;
}
if (laberinto[i, j] == 3)
{
Console.ForegroundColor = ConsoleColor.Magenta;
}
Console.Write(laberinto[i, j]);
}
Console.WriteLine();
}
}
public static void Main()
{
Laberinto laberinto = new Laberinto();
Console.SetWindowSize(70, 20);
Creacion();
Azucena azucena = new Azucena("A", 90, 70, 5, 2, 2);
laberinto.Agregodepersonajes(azucena);
Ruta();
Diamond(3, 6);
Generacionmaze();
}
}
// definitivo