Commit 19819ec43f97693d77d9375ec28775dbdbd8ad01
1 parent
46763cc4
deuxième dépôt
Showing
1 changed file
with
106 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,106 @@ | @@ -0,0 +1,106 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#define N 5 | ||
3 | + | ||
4 | +#define reset "\033[0m" | ||
5 | +#define reverse "\033[7m" | ||
6 | + | ||
7 | +#define rouge "\033[;31m" | ||
8 | +#define vert "\033[;32m" | ||
9 | +#define bleu "\033[;34m" | ||
10 | + | ||
11 | +#define green 0 | ||
12 | +#define blue 1 | ||
13 | +#define red 2 | ||
14 | +#define empty -1 | ||
15 | + | ||
16 | +typedef struct d{ | ||
17 | + int tab[N][N]; | ||
18 | + int indi; //indice de ligne du neutron | ||
19 | + int indc; //indice de colonne du neutron | ||
20 | +}damier; | ||
21 | + | ||
22 | + | ||
23 | +//fonction qui initialise un damier | ||
24 | +damier init(){ | ||
25 | + damier d; | ||
26 | + int i,j; | ||
27 | + | ||
28 | + for(i=0;i<N;i++){ | ||
29 | + for(j=0;j<N;j++){ | ||
30 | + d.tab[i][j]=-1; | ||
31 | + } | ||
32 | + } | ||
33 | + | ||
34 | + for(j=0;j<N;j++){ | ||
35 | + d.tab[0][j]=2; | ||
36 | + } | ||
37 | + | ||
38 | + for(j=0;j<N;j++){ | ||
39 | + d.tab[4][j]=1; | ||
40 | + } | ||
41 | + | ||
42 | + | ||
43 | + d.tab[2][2]=0; | ||
44 | + | ||
45 | + d.indi=3; | ||
46 | + d.indc=3; | ||
47 | + | ||
48 | + return d; | ||
49 | +} | ||
50 | + | ||
51 | +void affichage(damier d){ | ||
52 | + int i,j; | ||
53 | + for (i=0;i<N;i++){ | ||
54 | + for (j=0;j<N;j++){ | ||
55 | + if (d.tab[i][j]==green){ | ||
56 | + printf("%s%s %s ",vert,reverse,reset); | ||
57 | + } | ||
58 | + else if (d.tab[i][j]==blue){ | ||
59 | + printf("%s%s %s ",bleu,reverse,reset); | ||
60 | + } | ||
61 | + else if (d.tab[i][j]==red){ | ||
62 | + printf("%s%s %s ",rouge,reverse,reset); | ||
63 | + } | ||
64 | + else{ | ||
65 | + printf(" "); | ||
66 | + } | ||
67 | + } | ||
68 | + printf("\n"); | ||
69 | + } | ||
70 | +} | ||
71 | + | ||
72 | +/* dir : Donnée (donne la direction voulu par le joueur) | ||
73 | + i,j : Données,indice de ligne et de colonne du pion qu'on veut déplacer | ||
74 | + d: D/R | ||
75 | +*/ | ||
76 | + | ||
77 | +void dep(int i,int j,int dir,damier *d){ | ||
78 | + int temp; | ||
79 | + i=N-i; | ||
80 | + j=j-1; | ||
81 | + if (dir==1){ | ||
82 | + while ((i>=0) && ((d->tab[i-1][j])!=empty)){ | ||
83 | + temp=d->tab[i][j]; | ||
84 | + (d->tab[i][j])=(d->tab[i-1][j]); | ||
85 | + (d->tab[i-1][j])=temp; | ||
86 | + i=i-1; | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | +} | ||
91 | + | ||
92 | + | ||
93 | +int main(){ | ||
94 | + | ||
95 | + damier d; | ||
96 | + d=init(); | ||
97 | + affichage(d); | ||
98 | + printf("\n\n"); | ||
99 | + dep(1,1,1,&d); | ||
100 | + affichage(d); | ||
101 | + return 0; | ||
102 | +} | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + |