Skip to content

Commit

Permalink
Merge pull request #5 from LuGuDu/documentadoCodigo
Browse files Browse the repository at this point in the history
Documentado código
  • Loading branch information
LuGuDu committed Oct 16, 2020
2 parents 15cbb19 + 0de2adf commit c80da04
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 243 deletions.
17 changes: 13 additions & 4 deletions practica/Cell.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package practica;

import java.util.Arrays;

/**
* Esta clase es una abstacción de cada casilla del laberinto.
* Tiene valor, vecinos, es decir, celdas con las que está conectada y un
* atributo que dice si está visitado o no.
* @author David González Bermúdez, Lucas Gutiérrez Durán, David Gutiérrez Mariblanca
* Fecha: 16/10/2020
*/
public class Cell {
private int value;
private boolean[] neighbors;
private boolean visited;

public boolean isVisited() {
public boolean getVisited() {
return visited;
}

public void setVisited(boolean visited) {
this.visited = visited;
}
Expand All @@ -30,7 +39,7 @@ public void setValue(int value) {
public boolean[] getNeighbors() {
return neighbors;
}

public void setNeighbors(boolean[] neighbors) {
if (neighbors == null) {
this.neighbors = neighbors;
Expand Down
54 changes: 36 additions & 18 deletions practica/DrawLab.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package practica;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

import java.io.*;
import javax.imageio.*;

import java.util.Scanner;

/**
* Clase encargada de dibujar un laberinto a partir de un objeto Labyrinth y generar el archivo
* correspondiente con esa imagen
* @author David González Bermúdez, Lucas Gutiérrez Durán, David Gutiérrez Mariblanca
* Fecha: 16/10/2020
*/
public class DrawLab {

static Scanner sc = new Scanner(System.in);
private Labyrinth lab;
private String name;
private static int weidth;
private static int length;

public void paint(Graphics g) {
Image img = drawLab(lab, name);
g.drawImage(img, 0, 0, (ImageObserver) this);
}

static BufferedImage drawLab(Labyrinth lab, String name) {
/**
* Método principal que va generando el dibujo de todas las celdas y al final llama al
* método que genera el archivo, devuelve el objeto BufferedImage image ya que tendrá
* que ser usado por la clase paint
* @param lab
* @param name
* @return
*/
public static BufferedImage drawLab(Labyrinth lab, String name) {
weidth=((lab.getCols() * 50) + 100);
length=((lab.getRows() * 50) + 100);
BufferedImage image = new BufferedImage(weidth, length, BufferedImage.TYPE_INT_ARGB);
Expand All @@ -36,11 +42,18 @@ static BufferedImage drawLab(Labyrinth lab, String name) {
counter++;
}
}
writeImage(image, name);
generateFile(image, name);
return image;
}

private static Image drawNeighbors(BufferedImage image, Cell cell, int row, int col) {
/**
* Método que dibuja cada uno de los lados de las celdas y lo añade a image
* @param image
* @param cell
* @param row
* @param col
*/
private static void drawNeighbors(BufferedImage image, Cell cell, int row, int col) {
Graphics g = image.getGraphics();
boolean[] list = cell.getNeighbors();
g.setColor(Color.BLACK);
Expand All @@ -57,11 +70,15 @@ private static Image drawNeighbors(BufferedImage image, Cell cell, int row, int
if (list[3] == false) {
g.drawLine((row * 50)+50, (col * 50)+50, ((row) * 50)+50, ((col + 1) * 50)+50); // West Neighbor
}

return image;
}

private static void writeImage(BufferedImage image, String name) {

/**
* Este método genera un archivo .jpg con la imagen del laberinto y un archivo .json con el laberinto
* en formato de texto.
* @param image
* @param name
*/
public static void generateFile(BufferedImage image, String name) {
File test = new File("test.png");
String path=System.getProperty("user.home")+"/desktop";

Expand All @@ -84,4 +101,5 @@ private static void writeImage(BufferedImage image, String name) {
}
}while (!seguir);
}
}

}
Loading

0 comments on commit c80da04

Please sign in to comment.