Le programme permet maintenant d'affichier un ecran qui fait la taille d'une grille 4*4
This commit is contained in:
@@ -6,15 +6,18 @@ CFLAGS = -Wall \
|
||||
LIBS = -lgraph
|
||||
EXE = taquin
|
||||
OFILES = main.o \
|
||||
affichage.o
|
||||
affichage.o \
|
||||
partie.o
|
||||
|
||||
### BUT PAR DEFAUT ###
|
||||
but : ${EXE}
|
||||
|
||||
### REGLES ESSENTIELLES ###
|
||||
affichage.o : affichage.h
|
||||
affichage.o : affichage.h config.h
|
||||
|
||||
main.o : affichage.h
|
||||
partie.o : partie.h config.h
|
||||
|
||||
main.o : affichage.h partie.h config.h
|
||||
|
||||
${EXE} : ${OFILES}
|
||||
$(CC) $(CFLAGS) -o ${EXE} ${OFILES} ${LIBS}
|
||||
|
||||
+25
-3
@@ -1,13 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include "affichage.h"
|
||||
#include <graph.h>
|
||||
#include "config.h"
|
||||
|
||||
|
||||
void init_affichage(void){
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(100, 100, 800, 600);
|
||||
/*La fenetre vass faire la taille de la grille*/
|
||||
CreerFenetre(100, 100, NB_COLS * TAILLE_CASE, NB_LIGNES * TAILLE_CASE);
|
||||
}
|
||||
void afficher_plateau(int grille[NB_LIGNES][NB_COLS]){
|
||||
int i,j,x,y;
|
||||
char texte[10];
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
|
||||
for (i = 0; i < NB_LIGNES; i++){
|
||||
for(j = 0; j < NB_COLS; j++){
|
||||
/*Calcul en pixel de la taille d'une case*/
|
||||
x = j * TAILLE_CASE;
|
||||
y = i * TAILLE_CASE;
|
||||
/*Ici on saute la case vide du taquin*/
|
||||
if (grille[i][j] == 0) continue;
|
||||
/*ET on ecrit le numéro dans un rectagle*/
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
DessinerRectangle(x, y, TAILLE_CASE, TAILLE_CASE);
|
||||
sprintf(texte, "%d", grille[i][j]);
|
||||
EcrireTexte(x + 40, y + 60, texte, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
void fermer_affichage(void){
|
||||
|
||||
FermerGraphique();
|
||||
FermerGraphique();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef AFFICHAGE_H
|
||||
#define AFFICHAGE_H
|
||||
#include "config.h"
|
||||
|
||||
void init_affichage(void);
|
||||
void fermer_affichage(void);
|
||||
void afficher_plateau(int grille[NB_LIGNES][NB_COLS]);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define NB_LIGNES 4
|
||||
#define NB_COLS 4
|
||||
|
||||
#define TAILLE_CASE 100
|
||||
|
||||
#endif
|
||||
@@ -1,15 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include "affichage.h"
|
||||
#include<stdio.h>
|
||||
#include <graph.h>
|
||||
#include "config.h"
|
||||
#include "partie.h"
|
||||
int main(void){
|
||||
int k;
|
||||
int grille[NB_LIGNES][NB_COLS],touche;
|
||||
|
||||
init_affichage();
|
||||
initialiser_plateau(grille);
|
||||
afficher_plateau(grille);
|
||||
|
||||
while(1){
|
||||
|
||||
if (ToucheEnAttente()){
|
||||
k = Touche();
|
||||
if (k == XK_q)break;
|
||||
touche = Touche();
|
||||
if (touche == XK_q)break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "partie.h"
|
||||
void initialiser_plateau(int grille[NB_LIGNES][NB_COLS]){
|
||||
int i, j;
|
||||
int compteur = 1;
|
||||
|
||||
for (i = 0; i < NB_LIGNES; i++){
|
||||
for(j = 0; j < NB_COLS; j++){
|
||||
grille[i][j] = compteur;
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
/*On laisse la dernière case du tableu vide pour le taquin*/
|
||||
grille[NB_LIGNES - 1 ][NB_COLS - 1] = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user