Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package testlabirinto;
- import java.util.Scanner;
- /**
- * Università degli studi di camerino
- * @author (XXXXXX)
- * @version (XXXXXXX)
- * Realizzazione del Gioco del labirinto in modo casuale con relativa soluzione se esistente
- */
- public class Main {
- public static void main (String args[]){
- Scanner in = new Scanner (System.in);
- double perc = 0.0 ; int ok = 0; int lato = 0; double muri = 0;
- while(ok == 0) {
- System.out.println("Impostare la percentuale di copertura: ");
- if (in.hasNextDouble()) {perc = in.nextDouble();
- if ((perc >=0) && (perc <= 100)){ok = 1;}
- else {System.out.println("La Percentuale deve essere max 100, min 0"); in.nextLine(); }
- }
- }
- ok = 0;
- while(ok == 0) {
- System.out.println("Impostare la misura del lato: ");
- if (in.hasNextInt()) {lato = in.nextInt();
- if (lato >= 2){ ok = 1;}
- else {System.out.println("Il lato deve essere minimo 2"); in.nextLine(); }
- }
- }
- muri = ((lato * lato) / perc);
- char muro = '*';
- int matrice[][] = new int[lato][lato];
- int i, j;
- for(i=0; i<=(lato-1); i=i+1) {
- matrice[i][0] = muro;
- }
- for(j=0; j<=(lato-1); j=j+1) {
- matrice[0][j] = muro;
- }
- for(i=0; i<=(lato-1); i=i+1) {
- matrice[i][lato-1] = muro;
- }
- for(j=0; j<=(lato-1); j=j+1) {
- matrice[lato-1][j] = muro;
- }
- for(i=1; i<=(lato-2); i=i+1) {
- for(j=1; j<=(lato-2); j=j+1) {
- matrice[i][j] = 1;
- }
- }
- for(i=0; i<=(lato-1); i=i+1) {
- for(j=0; j<=(lato-1); j=j+1) {
- if (matrice[i][j] != 42) {
- System.out.print((matrice[i][j]+" "));
- } else {
- System.out.print("* ");
- }
- }
- System.out.println("");
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement