Advertisement
Tecnelm

Untitled

Feb 27th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Base {
  4. /*
  5. * grille
  6. *
  7. */
  8.  
  9. public static void main(String[] args) {
  10. /*-----------------------------------------------------------//
  11. Gรฉnรฉration grille de jeu
  12. //-----------------------------------------------------------*/
  13. int largeur ,hauteur , id=1 ,id2 = 1 ;
  14. Scanner read = new Scanner(System.in);
  15. System.out.println("largeur:");
  16. largeur =read.nextInt();
  17. System.out.println("hauteur");
  18. hauteur = read.nextInt();
  19. int grille[][] = new int[hauteur][largeur];
  20. for (int i = 0 ; i < hauteur ; i++ ) {
  21. id = 1;
  22. for(int a =0 ; a<largeur ; a++) {
  23. if( i ==0 || i == hauteur-1 || a==0|| a == largeur-1 )
  24. grille[i][a] = 0;
  25. else {
  26. if(id2!=0) {
  27. grille[i][a] = id;
  28. id = (id+1)%2;}
  29. else
  30. {
  31. grille[i][a] = id;
  32. }
  33. }
  34. }
  35. id2 = (id2+1)%2;
  36. }
  37.  
  38. //-----------------------------------------------------------//
  39. int caseJx, caseJy , idcaseJ;
  40. boolean Jplace = false;
  41. do {
  42. System.out.println("caseJx:");
  43. caseJx = read.nextInt();
  44. System.out.println("caseJy:");
  45. caseJy = read.nextInt();
  46. }while(caseJx<=0 || caseJx>=largeur|| caseJy<=0 || caseJy>=hauteur );
  47.  
  48. idcaseJ=grille[caseJy][caseJx];
  49. if (idcaseJ ==1) {
  50. grille[caseJy][caseJx] = 3;
  51. Jplace = true ;
  52. }
  53. if (Jplace)
  54. {
  55. if(grille[caseJy][caseJx-1] !=0)
  56. grille[caseJy][caseJx-1] =4;
  57.  
  58. if(grille[caseJy][caseJx+1] !=0)
  59. grille[caseJy][caseJx+1] =4;
  60.  
  61. if(grille[caseJy+1][caseJx] !=0)
  62. grille[caseJy+1][caseJx] =4;
  63.  
  64. if(grille[caseJy-1][caseJx] !=0)
  65. grille[caseJy-1][caseJx] =4;
  66.  
  67.  
  68. }
  69.  
  70. for(int []a:grille) {
  71. for(int b :a)
  72. System.out.print(b+" ");
  73. System.out.println();
  74. }
  75.  
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement