Compare commits
5 Commits
b08e96be47
...
50e0d7fa5f
| Author | SHA1 | Date | |
|---|---|---|---|
| 50e0d7fa5f | |||
| 5ecc182ab5 | |||
| f5cf74c048 | |||
| ee09e8c08b | |||
| 55817ce6d6 |
@@ -1,3 +0,0 @@
|
|||||||
*.o
|
|
||||||
app
|
|
||||||
.git
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
FROM gcc:13 AS build
|
|
||||||
WORKDIR /app
|
|
||||||
COPY . .
|
|
||||||
RUN gcc -ansi -pedantic tests.c -o app
|
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=build /app/app .
|
|
||||||
CMD ["./app"]
|
|
||||||
|
|
||||||
# sudo docker build -t app-c
|
|
||||||
# sudo docker run app-c
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
int tab[TAILLE_TABLEAU];
|
int tab[TAILLE_TABLEAU];
|
||||||
|
int tab_inverse[TAILLE_TABLEAU];
|
||||||
int i;
|
int i;
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
@@ -34,5 +35,32 @@ int main(void){
|
|||||||
}
|
}
|
||||||
printf("+\n");
|
printf("+\n");
|
||||||
|
|
||||||
|
/* Remplissage du tableau inverse */
|
||||||
|
for (i = 0; i != TAILLE_TABLEAU; i++) {
|
||||||
|
tab_inverse[i] = tab[TAILLE_TABLEAU-i-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Affichage du tableau */
|
||||||
|
for (i = 0; i != TAILLE_TABLEAU; i++) {
|
||||||
|
printf("+-----");
|
||||||
|
}
|
||||||
|
printf("+\n");
|
||||||
|
for (i = 0; i != TAILLE_TABLEAU; i++) {
|
||||||
|
if (tab_inverse[i] < 10 && tab_inverse[i] >= 0) {
|
||||||
|
printf("| %d ", tab_inverse[i]);
|
||||||
|
}
|
||||||
|
else if (tab_inverse[i] < -9) {
|
||||||
|
printf("| %d ", tab_inverse[i]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("| %d ", tab_inverse[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("|\n");
|
||||||
|
for (i = 0; i != TAILLE_TABLEAU; i++) {
|
||||||
|
printf("+-----");
|
||||||
|
}
|
||||||
|
printf("+\n");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -1,31 +0,0 @@
|
|||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ArrayDeque<String> textes = new ArrayDeque<>();
|
|
||||||
ArrayDeque<Integer> entiers = new ArrayDeque<>();
|
|
||||||
|
|
||||||
for (String chaine : args) {
|
|
||||||
try {
|
|
||||||
Integer entier = new Integer(Integer.parseInt(chaine));
|
|
||||||
|
|
||||||
entiers.addLast(entier.intValue());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
textes.addLast(chaine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Integer entier : entiers) {
|
|
||||||
System.out.print(entier + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("");
|
|
||||||
|
|
||||||
for (String texte : textes) {
|
|
||||||
System.out.print(texte + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,112 +0,0 @@
|
|||||||
public class ABR {
|
|
||||||
|
|
||||||
private String valeur;
|
|
||||||
private ABR filsGauche;
|
|
||||||
private ABR filsDroit;
|
|
||||||
private int compteur = 0;
|
|
||||||
|
|
||||||
public ABR() {
|
|
||||||
this.valeur = null;
|
|
||||||
this.filsDroit = null;
|
|
||||||
this.filsGauche = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ABR(String valeur) {
|
|
||||||
this.valeur = valeur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean authentifier(String id, String password) {
|
|
||||||
|
|
||||||
// Si le noeud courant est vide, aller dans le fils gauche
|
|
||||||
if (this.valeur == null) {
|
|
||||||
if (this.filsGauche != null) {
|
|
||||||
return this.filsGauche.authentifier(id, password);
|
|
||||||
}
|
|
||||||
return false; // rien dans l'arbre
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si on trouve l'id au noeud courant
|
|
||||||
if (this.valeur.equals(id)) {
|
|
||||||
if (this.filsDroit != null && this.filsDroit.valeur.equals(password)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sinon, continuer à gauche
|
|
||||||
if (this.filsGauche != null) {
|
|
||||||
return this.filsGauche.authentifier(id, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void supprimer(String id) {
|
|
||||||
if (this.filsGauche != null) {
|
|
||||||
if (this.filsGauche.valeur.equals(id)) {
|
|
||||||
if (this.filsGauche.filsGauche != null) {
|
|
||||||
this.filsGauche = this.filsGauche.filsGauche;
|
|
||||||
} else {
|
|
||||||
this.filsGauche = null;
|
|
||||||
}
|
|
||||||
System.out.println("Suppression effectuée.");
|
|
||||||
} else {
|
|
||||||
this.filsGauche.supprimer(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void ajouterUtilisateur(String id, String password) {
|
|
||||||
if (this.filsGauche != null && this.filsGauche.equals(id)) {
|
|
||||||
System.out.println("Valeur déjà présente.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filsGauche != null) {
|
|
||||||
this.filsGauche.ajouterUtilisateur(id, password);
|
|
||||||
} else {
|
|
||||||
this.filsGauche = new ABR(id);
|
|
||||||
this.filsGauche.filsDroit = new ABR(password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean estPresent(String id) {
|
|
||||||
if (this.filsGauche == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.compteur == 0) {
|
|
||||||
this.compteur++;
|
|
||||||
this.filsGauche.estPresent(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.compteur != 0 && this.valeur == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.valeur.equals(id)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return this.filsGauche.estPresent(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
String aRenvoyer = "";
|
|
||||||
|
|
||||||
if (this.filsDroit == null && this.filsGauche == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
if (this.filsGauche == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
aRenvoyer += "Identifiant : " + this.filsGauche.valeur + " / Mot de passe : " + this.filsGauche.filsDroit.valeur + "\n";
|
|
||||||
return aRenvoyer + this.filsGauche.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,43 +1,42 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class Authentification {
|
public class Authentification {
|
||||||
|
|
||||||
private ABR dictionnaire;
|
private Map<String, String> dictionnaire;
|
||||||
|
|
||||||
public Authentification() {
|
public Authentification() {
|
||||||
this.dictionnaire = new ABR();
|
this.dictionnaire = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ajouter(String username, String password) {
|
public void ajouter(String username, String password) {
|
||||||
if (this.dictionnaire.estPresent(username)) {
|
if (this.dictionnaire.get(username) != null) {
|
||||||
System.out.println("L'utilisateur '" + username + "' existe déjà.");
|
System.out.println("L'utilisateur '" + username + "' existe déjà.");
|
||||||
} else {
|
} else {
|
||||||
this.dictionnaire.ajouterUtilisateur(username, password);
|
this.dictionnaire.put(username, password);
|
||||||
System.out.println("Utilisateur ajouté.");
|
System.out.println("Utilisateur ajouté.");
|
||||||
}
|
}
|
||||||
System.out.println(this.dictionnaire);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authentifier(String username, String password) {
|
public void authentifier(String username, String password) {
|
||||||
if (!this.dictionnaire.estPresent(username)) {
|
if (this.dictionnaire.get(username) == null) {
|
||||||
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
||||||
} else if (!this.dictionnaire.authentifier(username, password)) {
|
} else if (!this.dictionnaire.get(username).equals(password)) {
|
||||||
System.out.println("Le mot de passe est incorrect.");
|
System.out.println("Le mot de passe est incorrect.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("L'utilisateur '" + username + "' est authentifié.");
|
System.out.println("L'utilisateur '" + username + "' est authentifié.");
|
||||||
}
|
}
|
||||||
System.out.println(this.dictionnaire);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void supprimer(String username) {
|
public void supprimer(String username) {
|
||||||
if (!this.dictionnaire.estPresent(username)) {
|
if (this.dictionnaire.get(username) == null) {
|
||||||
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
||||||
} else {
|
} else {
|
||||||
this.dictionnaire.supprimer(username);
|
this.dictionnaire.remove(username);
|
||||||
System.out.println("L'utilisateur '" + username + "' a été supprimé");
|
System.out.println("L'utilisateur '" + username + "' a été supprimé");
|
||||||
}
|
}
|
||||||
System.out.println(this.dictionnaire);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -64,7 +63,7 @@ public class Authentification {
|
|||||||
auth.authentifier(ligne[1], ligne[2]);
|
auth.authentifier(ligne[1], ligne[2]);
|
||||||
} else if (input.equals("del")) {
|
} else if (input.equals("del")) {
|
||||||
auth.supprimer(ligne[1]);
|
auth.supprimer(ligne[1]);
|
||||||
} else. if (input.equals("quit")) {
|
} else if (input.equals("quit")) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Commande non reconnue.");
|
System.out.println("Commande non reconnue.");
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/main"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="#555"
|
|
||||||
android:padding="10dp"
|
|
||||||
tools:context=".MainActivity">
|
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="660dp"
|
|
||||||
android:layout_gravity="top"
|
|
||||||
android:background="@color/white"
|
|
||||||
android:inputType="textMultiLine"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@color/white"
|
|
||||||
android:layout_weight="1"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="OK"
|
|
||||||
android:textSize="20dp"
|
|
||||||
android:gravity="center"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/main"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="#555"
|
|
||||||
android:padding="10dp"
|
|
||||||
tools:context=".MainActivity">
|
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/champPrincipal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="top"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:background="@color/white"
|
|
||||||
android:inputType="textMultiLine" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/champSecondaire"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@color/white"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:gravity="bottom"
|
|
||||||
android:layout_toStartOf="@+id/bouton"
|
|
||||||
android:layout_below="@+id/champPrincipal"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/bouton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:layout_below="@+id/champPrincipal"
|
|
||||||
android:text="OK"
|
|
||||||
android:textSize="20sp" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
---------------------------------------------
|
|
||||||
Dockerfile Java
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
FROM eclipse-temurin:17-jdk
|
|
||||||
|
|
||||||
WORKDIR /Ecriture
|
|
||||||
COPY Ecriture.java .
|
|
||||||
|
|
||||||
RUN javac Ecriture.java
|
|
||||||
|
|
||||||
CMD ["java", "Ecriture"]
|
|
||||||
|
|
||||||
|
|
||||||
---------------------------------------------
|
|
||||||
Commandes
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Build & run :
|
|
||||||
--------------
|
|
||||||
|
|
||||||
sudo docker build -t appli .
|
|
||||||
sudo docker run --r appli
|
|
||||||
|
|
||||||
Statut docker :
|
|
||||||
----------------
|
|
||||||
|
|
||||||
sudo docker ps (--> Liste l'ensemble des processus dockers en cours, équivalent de ls pour les dockers lancés)
|
|
||||||
|
|
||||||
Accéder aux fichiers du conteneur :
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
sudo docker exec -it <id_du_conteneur> bash (--> Permet d'accéder aux fichiers du conteneur, on obtient l'id du conteneur avec sudo docker ps)
|
|
||||||
|
|
||||||
|
|
||||||
Créer un volume (monter un dossier de sa machine dans le docker) :
|
|
||||||
------------------------------------------------------------------
|
|
||||||
|
|
||||||
sudo docker run -v $(pwd):/appli nom-image (--> le dossier ":/appli" doit être le nom spécifié dans le Dockerfile, soit WORKDIR /appli)
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
FROM eclipse-temurin:17-jdk
|
|
||||||
|
|
||||||
WORKDIR /Ecriture
|
|
||||||
COPY Ecriture.java .
|
|
||||||
|
|
||||||
RUN javac Ecriture.java
|
|
||||||
|
|
||||||
CMD ["java", "Ecriture"]
|
|
||||||
Binary file not shown.
@@ -1,48 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class Ecriture {
|
|
||||||
|
|
||||||
|
|
||||||
public static void ecrireFichier() {
|
|
||||||
try {
|
|
||||||
|
|
||||||
BufferedWriter flux = new BufferedWriter(new FileWriter("Texte.txt", true));
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
String aEcrire = "Hello world!";
|
|
||||||
flux.write(aEcrire, 0, aEcrire.length());
|
|
||||||
flux.newLine();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
flux.close();
|
|
||||||
|
|
||||||
} catch (IOException e3) {
|
|
||||||
System.err.println("Erreur de fermeture.");
|
|
||||||
}
|
|
||||||
} catch (IOException e2) {
|
|
||||||
System.err.println("Erreur d'écriture.");
|
|
||||||
}
|
|
||||||
} catch (IOException e1) {
|
|
||||||
System.err.println("Erreur d'ouverture.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
while (true) {
|
|
||||||
Ecriture.ecrireFichier();
|
|
||||||
System.out.println("Fichier modifié.");
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e4) {
|
|
||||||
System.err.println("Erreur de timer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Hello world!
|
|
||||||
Hello world!
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
jeu : jeu_principal.o
|
|
||||||
gcc -o jeu jeu_principal.o -lgraph
|
|
||||||
|
|
||||||
jeu_principal.o : jeu_principal.c jeu_principal.h
|
|
||||||
gcc -c jeu_principal.c -lgraph
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm *.o
|
|
||||||
|
|
||||||
run : jeu
|
|
||||||
./jeu
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB |
BIN
SAE11_2025/jeu
BIN
SAE11_2025/jeu
Binary file not shown.
@@ -1,337 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <graph.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
void affiche_grille(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_de_lignes; i++) {
|
|
||||||
for (j = 0; j < nb_de_colonnes; j++) {
|
|
||||||
printf("%d ", grille[i][j]);
|
|
||||||
}
|
|
||||||
putchar('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int verifie_si_taquin_complet(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int compteur = 0;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_de_lignes; i++) {
|
|
||||||
for (j = 0; j < nb_de_colonnes; j++) {
|
|
||||||
if (grille[i][j] != compteur) {
|
|
||||||
return 0; /* Pas complet */
|
|
||||||
}
|
|
||||||
compteur++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1; /* Complet */
|
|
||||||
}
|
|
||||||
|
|
||||||
int peut_decaler_en_haut(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i != nb_de_lignes; i++) {
|
|
||||||
if (grille[nb_de_colonnes-1][i] == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int peut_decaler_en_bas(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i != nb_de_lignes; i++) {
|
|
||||||
if (grille[0][i] == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int peut_decaler_a_gauche(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i != nb_de_colonnes; i++) {
|
|
||||||
if (grille[i][nb_de_lignes-1] == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int peut_decaler_a_droite(int grille[8][8], int nb_de_lignes, int nb_de_colonnes) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i != nb_de_colonnes; i++) {
|
|
||||||
if (grille[i][0] == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void mettre_a_jour_grille(int tab_image[8][8], int nb_de_lignes, int nb_de_colonnes, int decalage, int indice_case_vide_x, int indice_case_vide_y, int direction_decalage, int largeur_image, int hauteur_image) {
|
|
||||||
int pos_img_x;
|
|
||||||
int pos_img_y;
|
|
||||||
int pos_x;
|
|
||||||
int pos_y;
|
|
||||||
|
|
||||||
switch (direction_decalage) {
|
|
||||||
case 1: /* haut */
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = indice_case_vide_y * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = indice_case_vide_x * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
||||||
|
|
||||||
RemplirRectangle(
|
|
||||||
pos_x + decalage*(indice_case_vide_y+1), pos_y + decalage*(indice_case_vide_x+1), largeur_image / nb_de_colonnes, hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x-1][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x-1][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = (indice_case_vide_y) * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = (indice_case_vide_x-1) * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
pos_x + decalage * indice_case_vide_y + 10, pos_y + decalage * (indice_case_vide_x-1) + 10,
|
|
||||||
pos_img_x, pos_img_y,
|
|
||||||
largeur_image / nb_de_colonnes,
|
|
||||||
hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2: /* bas */
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = indice_case_vide_y * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = indice_case_vide_x * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
||||||
|
|
||||||
RemplirRectangle(
|
|
||||||
pos_x + decalage*(indice_case_vide_y+1), pos_y + decalage*(indice_case_vide_x+1), largeur_image / nb_de_colonnes, hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x+1][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x+1][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = (indice_case_vide_y) * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = (indice_case_vide_x+1) * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
pos_x + decalage * indice_case_vide_y + 10, pos_y + decalage * (indice_case_vide_x+1) + 10,
|
|
||||||
pos_img_x, pos_img_y,
|
|
||||||
largeur_image / nb_de_colonnes,
|
|
||||||
hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3: /* gauche */
|
|
||||||
|
|
||||||
printf("Coord case vide : %d | %d", indice_case_vide_x, indice_case_vide_y);
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = indice_case_vide_y * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = indice_case_vide_x * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
||||||
|
|
||||||
RemplirRectangle(
|
|
||||||
pos_x + decalage*(indice_case_vide_y+1), pos_y + decalage*(indice_case_vide_x+1), largeur_image / nb_de_colonnes, hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y-1] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y-1] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = (indice_case_vide_y-1) * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = (indice_case_vide_x) * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
pos_x + decalage * (indice_case_vide_y-1) + 10, pos_y + decalage * (indice_case_vide_x) + 10,
|
|
||||||
pos_img_x, pos_img_y,
|
|
||||||
largeur_image / nb_de_colonnes,
|
|
||||||
hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4: /* droite */
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = indice_case_vide_y * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = indice_case_vide_x * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
||||||
|
|
||||||
RemplirRectangle(
|
|
||||||
pos_x + decalage*(indice_case_vide_y+1), pos_y + decalage*(indice_case_vide_x+1), largeur_image / nb_de_colonnes, hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
pos_img_x = (tab_image[indice_case_vide_x][indice_case_vide_y+1] % nb_de_colonnes) * largeur_image / nb_de_colonnes;
|
|
||||||
pos_img_y = tab_image[indice_case_vide_x][indice_case_vide_y+1] / nb_de_colonnes * hauteur_image / nb_de_lignes;
|
|
||||||
pos_x = (indice_case_vide_y+1) * (largeur_image / nb_de_colonnes);
|
|
||||||
pos_y = (indice_case_vide_x) * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
pos_x + decalage * (indice_case_vide_y+1) + 10, pos_y + decalage * (indice_case_vide_x) + 10,
|
|
||||||
pos_img_x, pos_img_y,
|
|
||||||
largeur_image / nb_de_colonnes,
|
|
||||||
hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
int nb_de_lignes = 5;
|
|
||||||
int nb_de_colonnes = 5;
|
|
||||||
int decalage = 10;
|
|
||||||
int largeur_image = 1710;
|
|
||||||
int hauteur_image = 900;
|
|
||||||
int tab_image[8][8];
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int compteur = 0;
|
|
||||||
int indice_case_vide_x = 0;
|
|
||||||
int indice_case_vide_y = 0;
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
for (i = 0; i != nb_de_lignes; i++) {
|
|
||||||
for (j = 0; j != nb_de_colonnes; j++) {
|
|
||||||
tab_image[i][j] = compteur;
|
|
||||||
compteur++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int rand_1_1 = (rand() % nb_de_lignes);
|
|
||||||
int rand_1_2 = (rand() % nb_de_colonnes);
|
|
||||||
|
|
||||||
int rand_2_1 = (rand() % nb_de_lignes);
|
|
||||||
int rand_2_2 = (rand() % nb_de_colonnes);
|
|
||||||
|
|
||||||
compteur = 0;
|
|
||||||
|
|
||||||
while (compteur < 100) {
|
|
||||||
while (rand_1_1 + rand_1_2 == 0) {
|
|
||||||
rand_1_1 = (rand() % nb_de_lignes);
|
|
||||||
rand_1_2 = (rand() % nb_de_colonnes);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (rand_2_1 + rand_2_2 == 0) {
|
|
||||||
rand_2_1 = (rand() % nb_de_lignes);
|
|
||||||
rand_2_2 = (rand() % nb_de_colonnes);
|
|
||||||
}
|
|
||||||
|
|
||||||
int temp = tab_image[rand_1_1][rand_1_2];
|
|
||||||
tab_image[rand_1_1][rand_1_2] = tab_image[rand_2_1][rand_2_2];
|
|
||||||
tab_image[rand_2_1][rand_2_2] = temp;
|
|
||||||
|
|
||||||
rand_1_1 = (rand() % nb_de_lignes);
|
|
||||||
rand_1_2 = (rand() % nb_de_colonnes);
|
|
||||||
|
|
||||||
rand_2_1 = (rand() % nb_de_lignes);
|
|
||||||
rand_2_2 = (rand() % nb_de_colonnes);
|
|
||||||
|
|
||||||
compteur++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
affiche_grille(tab_image, nb_de_lignes, nb_de_colonnes);
|
|
||||||
|
|
||||||
|
|
||||||
InitialiserGraphique();
|
|
||||||
CreerFenetre(10, 10, largeur_image + decalage * (nb_de_lignes+1), hauteur_image + decalage * (nb_de_colonnes+1));
|
|
||||||
|
|
||||||
for (i = 0; i < nb_de_lignes; i++) {
|
|
||||||
for (j = 0; j < nb_de_colonnes; j++) {
|
|
||||||
if (j == 0 && i == 0){
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
int pos_img_x = (tab_image[i][j] % nb_de_colonnes) * (largeur_image / nb_de_colonnes);
|
|
||||||
int pos_img_y = (tab_image[i][j] / nb_de_colonnes) * (hauteur_image / nb_de_lignes);
|
|
||||||
int pos_x = j * (largeur_image / nb_de_colonnes);
|
|
||||||
int pos_y = i * (hauteur_image / nb_de_lignes);
|
|
||||||
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
pos_x + decalage * j + 10, pos_y + decalage * i + 10,
|
|
||||||
pos_img_x, pos_img_y,
|
|
||||||
largeur_image / nb_de_colonnes,
|
|
||||||
hauteur_image / nb_de_lignes
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!verifie_si_taquin_complet(tab_image, nb_de_lignes, nb_de_colonnes)) {
|
|
||||||
if (ToucheEnAttente()) {
|
|
||||||
int touche = Touche();
|
|
||||||
|
|
||||||
if (touche == XK_Up && peut_decaler_en_haut(tab_image, nb_de_lignes, nb_de_colonnes)) {
|
|
||||||
int temp = tab_image[indice_case_vide_x+1][indice_case_vide_y];
|
|
||||||
tab_image[indice_case_vide_x+1][indice_case_vide_y] = 0;
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y] = temp;
|
|
||||||
|
|
||||||
indice_case_vide_x++;
|
|
||||||
|
|
||||||
mettre_a_jour_grille(tab_image, nb_de_lignes, nb_de_colonnes, decalage, indice_case_vide_x, indice_case_vide_y, 1, largeur_image, hauteur_image);
|
|
||||||
} else if (touche == XK_Down && peut_decaler_en_bas(tab_image, nb_de_lignes, nb_de_colonnes)) {
|
|
||||||
int temp = tab_image[indice_case_vide_x-1][indice_case_vide_y];
|
|
||||||
tab_image[indice_case_vide_x-1][indice_case_vide_y] = 0;
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y] = temp;
|
|
||||||
|
|
||||||
indice_case_vide_x--;
|
|
||||||
|
|
||||||
mettre_a_jour_grille(tab_image, nb_de_lignes, nb_de_colonnes, decalage, indice_case_vide_x, indice_case_vide_y, 2, largeur_image, hauteur_image);
|
|
||||||
} else if (touche == XK_Left && peut_decaler_a_gauche(tab_image, nb_de_lignes, nb_de_colonnes)) {
|
|
||||||
int temp = tab_image[indice_case_vide_x][indice_case_vide_y+1];
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y+1] = 0;
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y] = temp;
|
|
||||||
|
|
||||||
indice_case_vide_y++;
|
|
||||||
|
|
||||||
mettre_a_jour_grille(tab_image, nb_de_lignes, nb_de_colonnes, decalage, indice_case_vide_x, indice_case_vide_y, 3, largeur_image, hauteur_image);
|
|
||||||
} else if (touche == XK_Right && peut_decaler_a_droite(tab_image, nb_de_lignes, nb_de_colonnes)) {
|
|
||||||
int temp = tab_image[indice_case_vide_x][indice_case_vide_y-1];
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y-1] = 0;
|
|
||||||
tab_image[indice_case_vide_x][indice_case_vide_y] = temp;
|
|
||||||
|
|
||||||
indice_case_vide_y--;
|
|
||||||
|
|
||||||
mettre_a_jour_grille(tab_image, nb_de_lignes, nb_de_colonnes, decalage, indice_case_vide_x, indice_case_vide_y, 4, largeur_image, hauteur_image);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
affiche_grille(tab_image, nb_de_lignes, nb_de_colonnes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
||||||
RemplirRectangle(0, 0, hauteur_image, largeur_image);
|
|
||||||
|
|
||||||
ChargerImage("./img/p4.img",
|
|
||||||
20, 20,
|
|
||||||
0, 0,
|
|
||||||
largeur_image, hauteur_image
|
|
||||||
);
|
|
||||||
|
|
||||||
Touche();
|
|
||||||
FermerGraphique();
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#ifndef JEU_PRINCIPAL_H
|
|
||||||
#define JEU_PRINCIPAL_H
|
|
||||||
|
|
||||||
void affiche_grille(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Affichage de la grille dans la console */
|
|
||||||
|
|
||||||
int verifie_si_taquin_complet(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Vérifie la condition de victoire */
|
|
||||||
|
|
||||||
int peut_decaler_en_haut(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Vérifie si on peut décaler l'image en dessous de la case vide vers le haut */
|
|
||||||
|
|
||||||
int peut_decaler_en_bas(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Vérifie si on peut décaler l'image au dessus de la case vide vers le bas */
|
|
||||||
|
|
||||||
int peut_decaler_a_gauche(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Vérifie si on peut décaler l'image à droite de la case vide vers la gauche */
|
|
||||||
|
|
||||||
int peut_decaler_a_droite(int grille[8][8], int nb_de_lignes, int nb_de_colonnes);
|
|
||||||
/* Vérifie si on peut décaler l'image à gauche de la case vide vers la droite */
|
|
||||||
|
|
||||||
void mettre_a_jour_grille(int tab_image[8][8], int nb_de_lignes, int nb_de_colonnes, int decalage, int indice_case_vide_x, int indice_case_vide_y, int direction_decalage, int largeur_image, int hauteur_image);
|
|
||||||
/* Met à jour l'affichage des 2 cases concernées dans le cas d'un déplacement */
|
|
||||||
|
|
||||||
int main(void);
|
|
||||||
/* LANCEMENT DU JEU */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user