Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Base {
- /*
- * grille
- *
- */
- public static void main(String[] args) {
- /*-----------------------------------------------------------//
- Gรฉnรฉration grille de jeu
- //-----------------------------------------------------------*/
- int largeur ,hauteur , id=1 ,id2 = 1 ;
- Scanner read = new Scanner(System.in);
- System.out.println("largeur:");
- largeur =read.nextInt();
- System.out.println("hauteur");
- hauteur = read.nextInt();
- int grille[][] = new int[hauteur][largeur];
- for (int i = 0 ; i < hauteur ; i++ ) {
- id = 1;
- for(int a =0 ; a<largeur ; a++) {
- if( i ==0 || i == hauteur-1 || a==0|| a == largeur-1 )
- grille[i][a] = 0;
- else {
- if(id2!=0) {
- grille[i][a] = id;
- id = (id+1)%2;}
- else
- {
- grille[i][a] = id;
- }
- }
- }
- id2 = (id2+1)%2;
- }
- //-----------------------------------------------------------//
- int caseJx, caseJy , idcaseJ;
- boolean Jplace = false;
- do {
- System.out.println("caseJx:");
- caseJx = read.nextInt();
- System.out.println("caseJy:");
- caseJy = read.nextInt();
- }while(caseJx<=0 || caseJx>=largeur|| caseJy<=0 || caseJy>=hauteur );
- idcaseJ=grille[caseJy][caseJx];
- if (idcaseJ ==1) {
- grille[caseJy][caseJx] = 3;
- Jplace = true ;
- }
- if (Jplace)
- {
- if(grille[caseJy][caseJx-1] !=0)
- grille[caseJy][caseJx-1] =4;
- if(grille[caseJy][caseJx+1] !=0)
- grille[caseJy][caseJx+1] =4;
- if(grille[caseJy+1][caseJx] !=0)
- grille[caseJy+1][caseJx] =4;
- if(grille[caseJy-1][caseJx] !=0)
- grille[caseJy-1][caseJx] =4;
- }
- for(int []a:grille) {
- for(int b :a)
- System.out.print(b+" ");
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement