Un laberinto en tu mente... codificación y gráfica

Crea laberintos sin caminos con Java

¿Cómo crear laberintos sin caminos con Java?

Aquí estamos poniendo en práctica las lecciones anteriores:

Crea una matriz de dos o tres estados, es decir, con 2 o 3 valores aleatorios. Crea la clase gráfica que dibuja una línea horizontal, vertical o diagonal según el estado en el elemento i-jésimo de la matriz…

he aquí el código:

Main:

package maze;
import javax.swing.*;
public class Maze {
public static void main(String[] args) {

JFrame t= new JFrame("Maze/Dk t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Tela p = new Tela();

t.add(p);
t.setSize(800, 1000);
t.setVisible(true);
}
}

package labirinto;
import javax.swing.*;
public class Labirinto {
public static void main(String[] args) {

JFrame t= new JFrame("Labirinto/Dk t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Tela p = new Tela();
p.Riempire();
t.add(p);
t.setSize(800, 1000);
t.setVisible(true);
}
}

Objeto archivo TELA:

package maze;
import java.awt.*;
import javax.swing.*;
public class Tela extends JPanel{
public int M[][]=new int [100][100];

public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.black);
// g.drawRect(10,10,700,700);
g.setColor(Color.black);
M=inizializzaMatriceRandom(M,4);
int x=0,y=0;
int px=10;
for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{
x=x+px;

     if(M[i][j]==0)
     {
        g.drawLine(x, y, x, y+10);
        //g.fillRect(10+20*j,10+20*i, 2, 20);
     }
    if(M[i][j]==1)
     {
         g.drawLine(x, y, x+10, y);
        //g.fillRect(10+20*j,30+20*i, 20, 2);
     }
    if(M[i][j]==2)
     {
         g.drawLine(x, y, x+10, y+10);
        // g.drawArc(x, y, 15, 15, 90, -90);
        //g.fillRect(10+20*j,30+20*i, 20, 2);
     }
    if(M[i][j]==3)
     {
         g.drawLine(x, y+10, x+10, y);
        // g.drawArc(x, y, 15, 15, 90, 90);
        //g.fillRect(10+20*j,30+20*i, 20, 2);
     }



    }
    x=0;
   y=y+px; 
 }

}

public int[][] inizializzaMatriceRandom(int m[][],int numerostati)
{ for(int i=0;i<m.length;i++){
for(int j=0;j<m.length;j++){
m[i][j]=(int)(Math.random()*numerostati);
System.out.print(" " + m[i][j]);
}
System.out.println();
}
return m;

    }

}

he aquí la versión javascript del código

https://js.do/mpalladino/labirinto