import java.io.*; import java.util.*; public class GameHelper { private static final String alphabet = "abcdefg"; private int tailleLigne = 7; private int tailleGrille = 49; private int[] grille = new int[tailleGrille]; private int nbPtCom = 0; public String getUserInput(String prompt) { String inputLine = null; System.out.print(prompt + " "); try{ BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); inputLine = is.readLine(); if (inputLine.length()==0 ) return null; }catch (IOException e){ System.out.println("IOEception: " + e) ; } return inputLine.toLowerCase(); } public ArrayList placePointCom(int taillePtCom){ ArrayList cellAlpha = new ArrayList(); String [] coordAlpha = new String [taillePtCom]; String temp = null; int[] coords = new int[taillePtCom]; int essais = 0; boolean succes = false; int place = 0; nbPtCom++; int incr = 1; if((nbPtCom % 2)==1){ incr = tailleLigne; } while(!succes & essais++ < 200){ place = (int)(Math.random() * tailleGrille); //System.out.println("essayé " + place); int x = 0; succes = true; while (succes && x < taillePtCom){ if (grille[place]== 0){ coords[x++] = place; place += incr; if(place >= tailleGrille); succes = false; } if(x>0 & (place % tailleLigne ==0)){ succes = false; } else { //System.out.println("utilisé " + place); succes = false; } } } int x = 0; int ligne = 0; int colonne = 0; System.out.println("\n"); while (x < taillePtCom){ grille[coords[x]] = 1; ligne = (int) (coords[x] / tailleLigne); colonne = coords[x] % tailleLigne; temp = String.valueOf(alphabet.charAt(colonne)); cellAlpha.add(temp.concat(Integer.toString(ligne))); x++; } System.out.println("\n"); return cellAlpha; } }