Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package testlabirinto;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. * Università degli studi di camerino
  12. * @author (XXXXXX)
  13. * @version (XXXXXXX)
  14. * Realizzazione del Gioco del labirinto in modo casuale con relativa soluzione se esistente
  15. */
  16. public class Main {
  17. public static void main (String args[]){
  18. Scanner in = new Scanner (System.in);
  19. double perc = 0.0 ; int ok = 0; int lato = 0; double muri = 0;
  20. while(ok == 0) {
  21. System.out.println("Impostare la percentuale di copertura: ");
  22. if (in.hasNextDouble()) {perc = in.nextDouble();
  23. if ((perc >=0) && (perc <= 100)){ok = 1;}
  24. else {System.out.println("La Percentuale deve essere max 100, min 0"); in.nextLine(); }
  25. }
  26. }
  27. ok = 0;
  28. while(ok == 0) {
  29. System.out.println("Impostare la misura del lato: ");
  30. if (in.hasNextInt()) {lato = in.nextInt();
  31. if (lato >= 2){ ok = 1;}
  32. else {System.out.println("Il lato deve essere minimo 2"); in.nextLine(); }
  33. }
  34. }
  35. muri = ((lato * lato) / perc);
  36.  
  37.  
  38. char muro = '*';
  39. int matrice[][] = new int[lato][lato];
  40. int i, j;
  41. for(i=0; i<=(lato-1); i=i+1) {
  42. matrice[i][0] = muro;
  43. }
  44. for(j=0; j<=(lato-1); j=j+1) {
  45. matrice[0][j] = muro;
  46. }
  47. for(i=0; i<=(lato-1); i=i+1) {
  48. matrice[i][lato-1] = muro;
  49. }
  50. for(j=0; j<=(lato-1); j=j+1) {
  51. matrice[lato-1][j] = muro;
  52. }
  53. for(i=1; i<=(lato-2); i=i+1) {
  54. for(j=1; j<=(lato-2); j=j+1) {
  55. matrice[i][j] = 1;
  56. }
  57. }
  58.  
  59. for(i=0; i<=(lato-1); i=i+1) {
  60. for(j=0; j<=(lato-1); j=j+1) {
  61. if (matrice[i][j] != 42) {
  62. System.out.print((matrice[i][j]+" "));
  63. } else {
  64. System.out.print("* ");
  65. }
  66. }
  67. System.out.println("");
  68. System.out.println("");
  69. }
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement