import java.util.Random;
import java.util.Scanner;
///KARARA Mohamed
public class PlateauJeu {
private int x=5,y=5;
private int max_jeu=25;
private int cpt;
private char plateau_jeu[][] = new char[x][y];
private char color[]={'R','B','G','Y','P','W'};
private Random r;
public PlateauJeu(){
r=new Random();
}
private void initiale_jeu(){
cpt=0;
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
plateau_jeu[i][j]=color[r.nextInt(6)];
}
}
}
private void affiche_plateau(){
for(int j=0;j<x;j++){
if(j==0){for(int i=0;i<y;i++){
System.out.print("+---");
}
}
System.out.println("");
for(int i=0;i<y;i++){
System.out.print("| "+ plateau_jeu[i][j] +" ");
}
System.out.println("");
for(int i=0;i<y;i++){
System.out.print("+---");
}
}
}
private int lire_choix(){
int choix=0;
System.out.println("\n\t\t===============Menu=============");
System.out.println("\t\t\t1> Red");
System.out.println("\t\t\t2> Bleu");
System.out.println("\t\t\t3> Green");
System.out.println("\t\t\t4> Yellow");
System.out.println("\t\t\t5> paink");
System.out.println("\t\t\t6> white");
System.out.print("\t\t\tVotre choix :");
Scanner sc=new Scanner(System.in);
choix = sc.nextInt();
System.out.println("");
return choix-1;
}
private void change_plateau(int x,int y,char nouvColor,char ancicolor){
if(x==-1)return ;
if(y==-1)return ;
if(x==this.x)return ;
if(y==this.y)return ;
///////////
if(ancicolor!=plateau_jeu[x][y])return ;
//////////
plateau_jeu[x][y]=nouvColor;
change_plateau(x-1, y, nouvColor, ancicolor);
change_plateau(x+1, y, nouvColor, ancicolor);
change_plateau(x, y-1, nouvColor, ancicolor);
change_plateau(x, y+1, nouvColor, ancicolor);
}
private boolean gagnant(){
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
if(plateau_jeu[0][0]!=plateau_jeu[i][j])return false;
}
}
return true;
}
public void jeu(){
initiale_jeu();
while(cpt!=max_jeu&&!gagnant()){
affiche_plateau();
System.out.println("\nmax jeu :"+cpt+"/"+max_jeu);
change_plateau(0, 0, color[lire_choix()], plateau_jeu[0][0]);
cpt++;
}
if(gagnant())System.out.println("vous avez gagne :)");
else System.out.println("jeu termine");
}
}