summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCLabyrintheJeu.tex
blob: da8b011cc696c2b1b947da63fcaa895bac910094 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%%%
% Labyrinthe
%%%
\setKVdefault[Labyrinthe]{Lignes=6,Colonnes=3,Longueur=4,Hauteur=2,Passages=false,EcartH=1,EcartV=1,CouleurF=gray!50,Texte=\color{black},SensImpose=false,Slop}

\tikzset{FDirect/.style={-stealth}}
\tikzset{FIndirect/.style={stealth-}}
\tikzset{FBidirect/.style={stealth-stealth}}

\newlength{\LabyLongCM}

\newcommand\Labyrinthe[3][]{%
  \useKVdefault[Labyrinthe]%
  \setKV[Labyrinthe]{#1}%
  \setsepchar[*]{,*/}%
  \readlist*\ListeLaby{#2}%
  \xdef\LabySlop{\ifboolKV[Labyrinthe]{Slop}{sloped}{}}%
  \ifboolKV[Labyrinthe]{Passages}{%
    \readlist*\ListeLabySol{#3}%
  }{}%
  \xdef\LabyLong{\useKV[Labyrinthe]{Longueur}}%
%  \setlength{\LabyLongCM}{\fpeval{\LabyLong*28.3465}pt}%
  \xdef\LabyHaut{\useKV[Labyrinthe]{Hauteur}}%
  \ifboolKV[Labyrinthe]{SensImpose}{%
    \xdef\TotalLaby{\fpeval{4*(\useKV[Labyrinthe]{Colonnes}-1)+1}}%
  }{%
    \xdef\TotalLaby{\fpeval{3*\useKV[Labyrinthe]{Colonnes}-2}}%
  }%
  \xdef\CouleurF{\useKV[Labyrinthe]{CouleurF}}%
  \xdef\MotifTexte{\noexpand\useKV[Labyrinthe]{Texte}}%
  \xintifboolexpr{\ListeLabylen==\fpeval{\useKV[Labyrinthe]{Lignes}*\useKV[Labyrinthe]{Colonnes}}}{%
    \begin{tikzpicture}[remember picture]%
%      % on dessine les cadres
      \foreach \compteurv in {1,...,\useKV[Labyrinthe]{Lignes}}{%
        \foreach \compteurh in {1,...,\useKV[Labyrinthe]{Colonnes}}{%
          \xdef\ColorFill{\ListeLaby[\fpeval{\useKV[Labyrinthe]{Colonnes}*(\compteurv-1)+\compteurh},2]}%
          \node[fill=\ColorFill,draw,minimum height=\LabyHaut*1cm,minimum width=\LabyLong*1cm,name=A-\compteurh-\compteurv] at
          (\fpeval{\LabyLong+\useKV[Labyrinthe]{EcartH}}*\compteurh,-\fpeval{\LabyHaut+\useKV[Labyrinthe]{EcartV}}*\compteurv) {%
%            \begin{minipage}{\LabyLongCM}
              \ListeLaby[\fpeval{\useKV[Labyrinthe]{Colonnes}*(\compteurv-1)+\compteurh},1]%
%            \end{minipage}
          };%
        }%
      }%
      % fin des cadres
      % on dessine les fl\`eches
      \ifboolKV[Labyrinthe]{SensImpose}{%
        %verticales
        \foreach \compteurv in {1,...,\fpeval{\useKV[Labyrinthe]{Lignes}-1}}{%
          \foreach \compteurh in {1,...,\useKV[Labyrinthe]{Colonnes}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)},1]}%
              \xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)},2]>0}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)},2]==1}{\xdef\NomStyle{FDirect}}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)},2]==2}{\xdef\NomStyle{FIndirect}}{\xdef\NomStyle{FBidirect}}}%
                \draw[\CouleurF,line width=3pt,\NomStyle] (A-\compteurh-\compteurv) -- node[fill=white,midway,inner sep=2pt]{\MotifTexte\NomNode}(A-\compteurh-\fpeval{\compteurv+1});}{}%
            }{%
              \draw[\CouleurF,line width=3pt,FBidirect] (A-\compteurh-\compteurv) -- (A-\compteurh-\fpeval{\compteurv+1});%
            }%
          }%
        }%
%        % horizontales
        \foreach \compteurv in {1,...,\useKV[Labyrinthe]{Lignes}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\compteurh},1]}%
              \xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\compteurh},2]>0}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\compteurh},2]==1}{\xdef\NomStyle{FDirect}}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\compteurh},2]==2}{\xdef\NomStyle{FIndirect}}{\xdef\NomStyle{FBidirect}}}%
              \draw[\CouleurF,line width=3pt,\NomStyle](A-\compteurh-\compteurv) -- node[fill=white,midway,\LabySlop,inner sep=2pt]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\compteurv);}{}
            }{%
              \draw[\CouleurF,line width=3pt,FBidirect](A-\compteurh-\compteurv) -- (A-\fpeval{\compteurh+1}-\compteurv);%
            }%
          }%
        }%
%        % diagonales "inverses"
        \foreach \compteurv in {2,...,\fpeval{\useKV[Labyrinthe]{Lignes}}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-2)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+2},1]}%
              \xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-2)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+2},2]>0}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-2)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+2},2]==1}{\xdef\NomStyle{FDirect}}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-2)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+2},2]==2}{\xdef\NomStyle{FIndirect}}{\xdef\NomStyle{FBidirect}}}%
                \draw[\CouleurF,line width=3pt,\NomStyle] (A-\compteurh-\compteurv) -- node[fill=white,near start,\LabySlop,inner sep=2pt]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\fpeval{\compteurv-1});
              }{}
            }{%
              \draw[\CouleurF,line width=3pt,FBidirect] (A-\compteurh-\compteurv) -- (A-\fpeval{\compteurh+1}-\fpeval{\compteurv-1});
            }%
          }%
        }%
%%        % diagonales directes
        \foreach \compteurv in {1,...,\fpeval{\useKV[Labyrinthe]{Lignes}-1}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+1},1]}%
              \xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+1},2]>0}{%
                \xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+1},2]==1}{\xdef\NomStyle{FDirect}}{\xintifboolexpr{\ListeLabySol[\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+3*(\compteurh-1)+1},2]==2}{\xdef\NomStyle{FIndirect}}{\xdef\NomStyle{FBidirect}}}
                \draw[\CouleurF,line width=3pt,\NomStyle] (A-\compteurh-\compteurv) -- node[fill=white,near start,\LabySlop,inner sep=2pt]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\fpeval{\compteurv+1});
              }{}%
            }{%
              \draw[\CouleurF,line width=3pt,FBidirect] (A-\compteurh-\compteurv) -- node[fill=white,near start,\LabySlop]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\fpeval{\compteurv+1});
            }%          
          }%
        }%
      }{%
        \foreach \compteurv in {1,...,\fpeval{\useKV[Labyrinthe]{Lignes}-1}}{%
          \foreach \compteurh in {1,...,\useKV[Labyrinthe]{Colonnes}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[1,\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+2*(\compteurh-1)}]}%
              \draw[\CouleurF,line width=3pt,stealth-stealth] (A-\compteurh-\compteurv) -- node[fill=white,midway]{\MotifTexte\NomNode}(A-\compteurh-\fpeval{\compteurv+1});%
            }{%
              \draw[\CouleurF,line width=3pt,stealth-stealth] (A-\compteurh-\compteurv) -- (A-\compteurh-\fpeval{\compteurv+1});%
            }%
          }%
        }%
        \foreach \compteurv in {1,...,\useKV[Labyrinthe]{Lignes}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[1,\fpeval{\TotalLaby*(\compteurv-1)+\compteurh}]}%
              \draw[\CouleurF,line width=3pt,stealth-stealth]
              (A-\compteurh-\compteurv) -- node[fill=white,midway]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\compteurv);
            }{%
              \draw[\CouleurF,line width=3pt,stealth-stealth]
              (A-\compteurh-\compteurv) -- (A-\fpeval{\compteurh+1}-\compteurv);
            }%
          }
        }
        \foreach \compteurv in {2,...,\fpeval{\useKV[Labyrinthe]{Lignes}}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \draw[\CouleurF,line width=3pt,stealth-stealth] (A-\compteurh-\compteurv) -- (A-\fpeval{\compteurh+1}-\fpeval{\compteurv-1});
          }
        }
        \foreach \compteurv in {1,...,\fpeval{\useKV[Labyrinthe]{Lignes}-1}}{%
          \foreach \compteurh in {1,...,\fpeval{\useKV[Labyrinthe]{Colonnes}-1}}{%
            \ifboolKV[Labyrinthe]{Passages}{%
              \xdef\NomNode{\noexpand\ListeLabySol[1,\fpeval{\TotalLaby*(\compteurv-1)+\useKV[Labyrinthe]{Colonnes}+2*(\compteurh-1)+1}]}%
              \draw[\CouleurF,line width=3pt,stealth-stealth] (A-\compteurh-\compteurv) -- node[fill=white,midway]{\MotifTexte\NomNode}(A-\fpeval{\compteurh+1}-\fpeval{\compteurv+1});
            }{%
              \draw[\CouleurF,line width=3pt,stealth-stealth] (A-\compteurh-\compteurv) -- (A-\fpeval{\compteurh+1}-\fpeval{\compteurv+1});
            }%          
          }%
        }%
%      % fin des fl\`eches
    }
  \end{tikzpicture}
   }{
  \textbf{! Le nombre d'informations n'est pas compatible avec les
    d\'efinitions de {\ttfamily Colonnes} et {\ttfamily Lignes} !}}%
}