-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.java
More file actions
73 lines (64 loc) · 1.73 KB
/
Copy pathDisplay.java
File metadata and controls
73 lines (64 loc) · 1.73 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package Puissance4;
public class Display{
public static int[][] symetrieHorizontale(int[][] tab){
//Renverse l'organisation du tableau pour préparé son affichage
int n = tab.length;
int[][] rep = new int[n][];
for(int i =0; i < n; i ++) {
rep[i] = new int[tab[i].length];
for(int j = 0; j < tab[i].length; j ++) {
rep[i][j] = 0;
}
}
for(int i = 0; i < n; i ++) {
for(int j = 0; j < tab[i].length; j ++) {
if(n%2 == 0) {
if(i <= n /2) {rep[(n-1) - i][j] = tab[i][j];}
else {
if(i != tab.length-1){rep[i - n/2][j] = tab[i][j];}
else {rep[0][j] = tab[i][j];}
}
}
else {
if(i != n/2) {
if(i <= n /2) {rep[(n-1) - i] [j] = tab[i][j];}
else {rep[i - n/2-1][j] = tab[i][j];}
}
else {rep[i][j] = tab[i][j];}
}
}
}
return rep;
}
public static void afficheGrille() {
//Affiche la grille de jeu avec X pour les jetons du joueur 1 et O pour ceux du joueur 2
String rep = "";
int[][] tab = symetrieHorizontale(repre.grille);
for(int i = 0; i < tab.length; i++) {
rep+="|";
for(int j = 0; j < tab[i].length; j ++) {
if(tab[i][j] == 0) {rep+=" |";}
else if(tab[i][j] == 1) {rep+="X|";}
else if(tab[i][j] == 2) {rep+="O|";}
}
rep+="\n";
}
System.out.print(rep);
}
public static void main(String[] args) {
repre.initialiseGrille();
repre.jouer(1, 6, repre.grille);
repre.jouer(2, 4, repre.grille);
repre.jouer(2, 6, repre.grille);
repre.jouer(1, 4, repre.grille);
afficheGrille();
int[][] tab = new int[6][7];
for(int i = 0; i < tab.length; i ++) {
for(int j = 0; j < tab[i].length; j ++) {
tab[i][j] = i;
}
}
repre.afficheTab2D(tab);
repre.afficheTab2D(symetrieHorizontale(tab));
}
}