-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepre.java
More file actions
51 lines (43 loc) · 1.1 KB
/
Copy pathrepre.java
File metadata and controls
51 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Puissance4;
public class repre{
//Exercice 1
public static int[][] grille = new int[6][7];
public static void initialiseGrille() {
grille = new int[6][7];
}
//Exercice 1
//Exercice 2
public static void jouer(int joueur, int colonne, int [][] tab) {//1<=joueur<=2
//Place un jeton dans la colonne indiqué dans un emplacement libre, en partant du haut de la colonne
for(int i = 0; i < tab.length; i ++) {
if(tab[i][colonne] == 0) {
tab[i][colonne] = joueur;
return;
}
}
}
//Exercice 2
//tests
public static void afficheTab2D(int [][] tab) {
String rep = "{";
for(int i =0; i < tab.length; i ++) {
rep += "{";
for(int j = 0; j < tab[i].length-1; j ++) {
rep += tab[i][j]+ ", ";
}
rep += tab[i][tab[i].length-1] + "},\n";
}
System.out.println(rep +"}");
}
public static void main(String[] args) {
jouer(1, 3, grille);
jouer(1, 3, grille);
jouer(1, 3, grille);
jouer(1, 3, grille);
jouer(1, 3, grille);
jouer(1, 3, grille);
jouer(2, 4, grille);
afficheTab2D(grille);
}
//tests
}