This commit is contained in:
EmmanuelTiamzon
2025-09-30 09:43:41 +02:00
parent f7de13bc2a
commit 7019a3b7ea
176 changed files with 9458 additions and 149 deletions

View File

@@ -1,27 +1,43 @@
public class Configuration {
private char[9] grille;
private char[] grille;
/*
On veut que chaque case soit un x ou un o et que si elle est vide alors n
la première case est 1 la deuxième 2, etc...
*/
public Configuration() {
this.grille = {'n','n','n','n','n','n','n','n','n'};
this.grille = new char[]{'n','n','n','n','n','n','n','n','n'};
}
public static int estLibre(int posGrille) {
if(this.grille[posGrille-1] == 'n') {
return true;
}
public boolean estLibre(int posGrille) {
if (posGrille < 1 || posGrille > 9) {
throw new IllegalArgumentException("La position doit être entre 1 et 9.");
}
return this.grille[posGrille - 1] == 'n';
}
public void jouer(int position, char joueur) {
if(joueur == 'x') {
this.grille[position-1] = 'x';
} else if(joueur == 'o') {
this.grille[position-1] = 'o';
}
}
if (position < 1 || position > 9) {
throw new IllegalArgumentException("La position doit être entre 1 et 9.");
}
if (joueur != 'x' && joueur != 'o') {
throw new IllegalArgumentException("Le joueur doit être 'x' ou 'o'.");
}
if (!estLibre(position)) {
throw new IllegalArgumentException("Cette case est déjà occupée.");
}
this.grille[position - 1] = joueur;
}
public void afficherGrille() {
for (int i = 0; i < 9; i++) {
System.out.print(this.grille[i] + " ");
if ((i + 1) % 3 == 0) {
System.out.println();
}
}
}
}

View File

@@ -0,0 +1,38 @@
public class Main {
public static void main(String[] args) {
Configuration jeu = new Configuration();
// Affichage de la grille initiale
jeu.afficherGrille();
System.out.println();
// Test de estLibre
System.out.println("Case 1 libre ? " + jeu.estLibre(1)); // true
// Test de jouer
jeu.jouer(1, 'x');
jeu.afficherGrille();
System.out.println("Case 1 libre ? " + jeu.estLibre(1)); // false
// Test de jouer sur une case occupée
try {
jeu.jouer(1, 'o'); // Doit lever une exception
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Test de jouer avec une position invalide
try {
jeu.jouer(10, 'x'); // Doit lever une exception
} catch (Exception e) {
System.out.println(e.getMessage());
}
// Test de jouer avec un mauvais symbole
try {
jeu.jouer(2, 'z'); // Doit lever une exception
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

View File

@@ -3,10 +3,11 @@ import java.awt.*;
public class Declinaisons extends JComponent {
public Declinaisons(String form, String fond) {
if(inst % 2 == 0) {
secondPinceau.setColor("")
}
private Color couleurTri;
public Declinaisons(Color couleurTri) {
super();
this.couleurTri = couleurTri;
}
@Override

View File

@@ -8,6 +8,16 @@ public class Fenetre extends JFrame {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setLocation(500,250);
JPanel[] panneaux = {new JPanel(), new JPanel(), new JPanel(), new JPanel()};
Color[] couleursTriangles = {Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.BLUE};
Color[] couleursFonds = {Color.CYAN, Color.PINK, Color.MAGENTA, Color.YELLOW};
for (int i = 0; i != 4; i++) {
panneaux[i].setBackground(couleursFonds[i]);
panneaux[i].setLayout(new BorderLayout());
panneaux[i].add(new Declinaisons(couleursTriangles[i]), BorderLayout.CENTER);
fenetre.add(panneaux[i]);
}
}
}

View File

@@ -0,0 +1,21 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Acharnement extends WindowAdapter{
private int compteur;
public Acharnement() {
this.compteur = 0;
}
@Override
public void windowClosing(WindowEvent evenement) {
if (this.compteur == 2) {
System.exit(0);
}
else {
this.compteur++;
}
}
}

View File

@@ -0,0 +1,14 @@
import java.awt.*;
import javax.swing.*;
public class AcharnementMain {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(300, 200);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
fenetre.addWindowListener(new Acharnement());
fenetre.setVisible(true);
}
}

View File

@@ -1,11 +0,0 @@
import java.util.Arrays;
public class Duplication {
public static void main(String[] args) {
double[] tableau = new double[10];
Arrays.fill(tableau, 5.8);
System.out.println(Arrays.toString(tableau));
}
}

View File

@@ -1,12 +0,0 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
super("");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setLocation(500,250);
}
}