Commit de0dd333 by Alex

Agregado lógica de casilla seleccionable

parent 4b786a5e
...@@ -67,11 +67,8 @@ constructor(private pedidoService: ServicioPedidoService) {} ...@@ -67,11 +67,8 @@ constructor(private pedidoService: ServicioPedidoService) {}
*/ */
confirmarSeleccion(): void { confirmarSeleccion(): void {
if (this.puntoDeRecogida && this.puntoDeEntrega) { if (this.puntoDeRecogida && this.puntoDeEntrega) {
// Genera un ID único para el pedido, por ejemplo usando la fecha y hora actual.
const uniqueId = Date.now().toString();
const nuevoPedido: Pedido = { const nuevoPedido: Pedido = {
id: uniqueId, id: '',
puntoDeRecogida: this.puntoDeRecogida, puntoDeRecogida: this.puntoDeRecogida,
puntoDeEntrega: this.puntoDeEntrega puntoDeEntrega: this.puntoDeEntrega
}; };
......
...@@ -20,24 +20,42 @@ export class MapaComponent implements OnInit { ...@@ -20,24 +20,42 @@ export class MapaComponent implements OnInit {
@Output() celdaInvalidaClickeada = new EventEmitter<void>(); @Output() celdaInvalidaClickeada = new EventEmitter<void>();
mapMatrix: string[][] = []; mapMatrix: string[][] = [];
mapStr: string = "0202000105030705000200041109060110031000000200080101100110000106010701"; // Cadena de texto que representa las casillas del mapa mapStr: string = "0202000105030705000200041109060110031000000200080101100110000106010701"; // Cadena de texto que representa las casillas del mapa
celdaInvalida: string[] = ['00', '07', '08', '09', '10', '11']; // Listado de bloques no seleccionables
rows: number = 7; rows: number = 7;
cols: number = 5; cols: number = 5;
SeleccionadoIdRecogida: string | null = null; SeleccionadoIdRecogida: string | null = null;
SeleccionadoIdEntrega: string | null = null; SeleccionadoIdEntrega: string | null = null;
// Listas de IDs que no constituyen una conexión válida según la dirección
sinConexionIzquierda: string[] = ['02', '05', '06', '10', '00'];
sinConexionDerecha: string[] = ['02', '03', '04', '08', '00'];
sinConexionArriba: string[] = ['01', '03', '06', '07', '00'];
sinConexionAbajo: string[] = ['04', '05', '09', '00'];
constructor(private MapaService: MapaService) { } constructor(private MapaService: MapaService) { }
/**
* @brief Determina si un bloque es seleccionable. /**
* * Evalúa si una casilla de calle es válida según su tipo y conexiones adyacentes.
* Evalúa si el ID del bloque dado no está en la lista de bloques no seleccionables. * @param celdaId ID de la casilla (01 para horizontal, 02 para vertical).
* * @param row Fila de la casilla en la matriz.
* @param celdaId El ID del bloque a evaluar. * @param col Columna de la casilla en la matriz.
* @return true si el bloque es seleccionable, false de lo contrario. * @return true si la casilla es válida; false de lo contrario.
*/ */
siCeldaSeleccionable(celdaId: string): boolean {
return !this.celdaInvalida.includes(celdaId); esCeldaValida(celdaId: string, row: number, col: number): boolean {
if (celdaId !== '01' && celdaId !== '02') return false;
let conexionesValidas = 0;
if (celdaId === '01') {
if (col > 0 && !this.sinConexionIzquierda.includes(this.mapMatrix[row][col - 1])) conexionesValidas++;
if (col < this.cols - 1 && !this.sinConexionDerecha.includes(this.mapMatrix[row][col + 1])) conexionesValidas++;
} else if (celdaId === '02') {
if (row > 0 && !this.sinConexionArriba.includes(this.mapMatrix[row - 1][col])) conexionesValidas++;
if (row < this.rows - 1 && !this.sinConexionAbajo.includes(this.mapMatrix[row + 1][col])) conexionesValidas++;
}
return conexionesValidas === 1;
} }
/** /**
...@@ -74,7 +92,7 @@ export class MapaComponent implements OnInit { ...@@ -74,7 +92,7 @@ export class MapaComponent implements OnInit {
* @param col La columna en la matriz del mapa donde está el bloque. * @param col La columna en la matriz del mapa donde está el bloque.
*/ */
enCeldaClickeada(celdaId: string, row: number, col: number): void { enCeldaClickeada(celdaId: string, row: number, col: number): void {
if (this.siCeldaSeleccionable(celdaId)) { if (this.esCeldaValida(celdaId,row,col)) {
// Emitir también la fila y la columna // Emitir también la fila y la columna
this.celdaSeleccionada.emit({ id: celdaId, row, col }); this.celdaSeleccionada.emit({ id: celdaId, row, col });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment