summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/battleship/logicpuzzle.sty
blob: 0d4084289342fa23e9384ce539e29a4b60579c54 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
%%
%% Copyright (C) 2013 by:
%% Josef Kleber
%% <josef.kleber@gmx.de>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.3 or later is part of all distributions of LaTeX version
%% 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "author-maintained".
%%
%% The Current Maintainer of this work is Josef Kleber.
%%
%% This work consists of all files listed in manifest.txt.
%%
\ProvidesPackage{logicpuzzle}[2013/02/23 logicpuzzle.sty v1.0 - Josef Kleber (C) 2013]%
%
\RequirePackage{xkeyval}%
\RequirePackage{ifthen}%
\RequirePackage{ragged2e}%
\RequirePackage{etoolbox}%
\RequirePackage{marginnote}%
\RequirePackage{tikz}%
\usetikzlibrary{decorations.pathmorphing}%
%
\newcounter{LP@counti}%
\newcounter{LP@countii}%
\newcounter{LP@countiii}%
\newcounter{LP@countiv}%
\newcounter{LP@whiledo}%
\newcounter{LP@puzzlecounter}%
\setcounter{LP@puzzlecounter}{1}%
%
\newcommand*\LP@counterstyle{none}%
\newcommand*\LP@titleformat{}%
%
\newcommand*\LP@Pfive{.5}%
%
\newcommand*\LP@ingrid[5]%
{%
  \setcounter{LP@counti}{#1}% column
  \setcounter{LP@countii}{#2}% row
  \setcounter{LP@countiii}{#3}% max column
  \setcounter{LP@countiv}{#4}% max row
  %#5 style
  %
  \ifnum\value{LP@counti}<1%
    \PackageError{#5}%
                 {element outside of the grid}%
                 {You tried to set an element at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@countii}<1%
    \PackageError{#5}%
                 {element outside of the grid}%
                 {You tried to set an element at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@counti}>\value{LP@countiii}%
    \PackageError{#5}%
                 {element outside of the grid}%
                 {You tried to set an element at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@countii}>\value{LP@countiv}%
    \PackageError{#5}%
                 {element outside of the grid}%
                 {You tried to set an element at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
}%
%
\newcommand*\titleformat[1]%
{%
  \renewcommand*\LP@titleformat{#1}%
}%
\titleformat{\centering\Large\color{blue}}%
%
\newcommand*\puzzlecounter{\theLP@puzzlecounter}%
%
\newcommand*\setpuzzlecounter[1]%
{%
  \setcounter{LP@puzzlecounter}{#1}%
}%
\newcommand*{\definecounterstyle}[2]%
{%
  \expandafter\gdef\csname LP@cs@#1\endcsname{#2}%
}%
%
\definecounterstyle{none}{}%
\definecounterstyle{left}{\begingroup\reversemarginpar\marginnote{\tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,draw,rounded corners=3pt,thick]{\Huge\puzzlecounter};}[-23pt]\endgroup}%
\definecounterstyle{right}{\marginnote{\tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,draw,rounded corners=3pt,thick]{\Huge\puzzlecounter};}[-23pt]}%
%
% #1 grid x min
% #2 grid y min
% #3 grid x max
% #4 grid y max
% #5 step
\newcommand*\LP@drawgrid[5]%
{%
  \setcounter{LP@counti}{#3}% max column
  \setcounter{LP@countii}{#4}% max row
  \stepcounter{LP@counti}%
  \stepcounter{LP@countii}%
  \draw[step=#5] (#1,#2) grid (\value{LP@counti},\value{LP@countii});%
}%
%
% #1 grid x min
% #2 grid y min
% #3 grid x max
% #4 grid y max
% #5 bgcolor
\newcommand*\LP@drawbackground[5]%
{%
  \ifthenelse{\equal{#5}{}}%
  {}% no bgcolor
  {%
    \setcounter{LP@counti}{#3}% max column
    \setcounter{LP@countii}{#4}% max row
    \stepcounter{LP@counti}%
    \stepcounter{LP@countii}%
    \draw[fill=#5] (#1,#2) rectangle (\value{LP@counti},\value{LP@countii});%
  }%
}%
%
% #1 counterstyle
\newcommand*\LP@drawcounter[1]%
{%
  \csname LP@cs@#1\endcsname%
}%
%
% #1 column
% #2 row
% #3 content
\newcommand*\LP@setcellcontent[3]%
{%
  \node at (#1\LP@Pfive,#2\LP@Pfive){#3};%
}%
%
% #1 csv list
% #2 column
% #3 row
% #4 fontsize
\newcommand*\LP@setcolumncontents[4]%
{%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \forcsvlist\LP@setcolumncontents@i{#4#1}%
}%
%
\newcommand*\LP@setcolumncontents@i[1]%
{%
  \LP@setcellcontent{\arabic{LP@counti}}{\arabic{LP@countii}}{#1}%
  \stepcounter{LP@counti}%
}%
%
% #1 csv list
% #2 column
% #3 row
% #4 fontsize
\newcommand*\LP@setrowcontents[4]%
{%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \forcsvlist\LP@setrowcontents@i{#4#1}%
}%
%
\newcommand*\LP@setrowcontents@i[1]%
{%
  \LP@setcellcontent{\arabic{LP@counti}}{\arabic{LP@countii}}{#1}%
  \stepcounter{LP@countii}%
}%
%
\endinput%