diff options
author | Karl Berry <karl@freefriends.org> | 2013-02-16 22:45:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-02-16 22:45:09 +0000 |
commit | 94b0b17e38865c5d7482feb748a06282961272ce (patch) | |
tree | fc048882faeb024c1a9288488cbcb3b74c39dd8d /Master/texmf-dist/tex/latex | |
parent | 29ac634381f6a33480ef3663d3208d6c3f38d6b9 (diff) |
battleship (16feb13)
git-svn-id: svn://tug.org/texlive/trunk@29138 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/battleship/battleship.sty | 135 |
1 files changed, 122 insertions, 13 deletions
diff --git a/Master/texmf-dist/tex/latex/battleship/battleship.sty b/Master/texmf-dist/tex/latex/battleship/battleship.sty index 2d279912e8a..2195ddb8e84 100644 --- a/Master/texmf-dist/tex/latex/battleship/battleship.sty +++ b/Master/texmf-dist/tex/latex/battleship/battleship.sty @@ -23,13 +23,15 @@ % http://en.wikipedia.org/wiki/Battleship_%28puzzle%29 % http://de.wikipedia.org/wiki/Bimaru % -\ProvidesPackage{battleship}[2013/02/08 battleship.sty v1.0 - Josef Kleber (C) 2013]% +\ProvidesPackage{battleship}[2013/02/16 battleship.sty v1.1 - Josef Kleber (C) 2013]% % \RequirePackage{xkeyval}% \RequirePackage{ifthen}% \RequirePackage{ragged2e}% -\RequirePackage{tikz}% \RequirePackage{etoolbox}% +\RequirePackage{tikz}% +\usetikzlibrary{decorations.pathmorphing} +\tikzstyle{island} = [fill=yellow!30,draw, decorate, decoration={random steps,segment length=2.7pt,amplitude=1.7pt}] % % options \newcommand*\BS@width{6cm}% @@ -44,8 +46,11 @@ % \newcounter{BS@rows}% \newcounter{BS@columns}% -\newcounter{BS@shipH}% -\newcounter{BS@shipV}% +\newcounter{BS@counti}% +\newcounter{BS@countii}% +\newcounter{BS@countiii}% +\newcounter{BS@countiv}% +\newcounter{BS@whiledo}% % \setcounter{BS@rows}{\BS@rows}% \setcounter{BS@columns}{\BS@columns}% @@ -195,6 +200,8 @@ \newcommand*\ShipB{\tikz[scale=\BS@scale]\draw[scale=.36,fill=\BS@shipcolor](2,1)--(2,2)--(0,2)--(0,1) arc (180:360:1);}% \newcommand*\ShipL{\tikz[scale=\BS@scale]\draw[scale=.36,fill=\BS@shipcolor](1,2)--(2,2)--(2,0)--(1,0) arc (270:90:1);}% \newcommand*\ShipR{\tikz[scale=\BS@scale]\draw[scale=.36,fill=\BS@shipcolor](1,2)--(0,2)--(0,0)--(1,0) arc (270:450:1);}% +\newcommand*\Island{\tikz[scale=\BS@scale]\draw[scale=.36,island] (0,0) rectangle (2,2);}% +\newcommand*\Water{\tikz[scale=\BS@scale]\draw[scale=.36,fill,blue!40] (1,1) circle (0.2);}% % versions for \shipbox without second scale \newcommand*\@Ship{\tikz\draw[scale=.144,fill=\BS@shipcolor] (0,0) circle (1);}% \newcommand*\@ShipC{\tikz\draw[scale=.144,fill=\BS@shipcolor] (0,0)--(0,2)--(2,2)--(2,0)--cycle;}% @@ -210,14 +217,43 @@ % \newcommand*\BS@printpartsH[1]% {% - \stepcounter{BS@shipH}% - \BS@shipparts{\arabic{BS@shipH}}{\arabic{BS@shipV}}{#1}% + \stepcounter{BS@counti}% + \BS@shipparts{\arabic{BS@counti}}{\arabic{BS@countii}}{#1}% }% % \newcommand*\BS@printpartsV[1]% {% - \stepcounter{BS@shipV}% - \BS@shipparts{\arabic{BS@shipH}}{\arabic{BS@shipV}}{#1}% + \stepcounter{BS@countii}% + \BS@shipparts{\arabic{BS@counti}}{\arabic{BS@countii}}{#1}% +}% +% +\newcommand*\BS@ingrid[2]% +{% + \setcounter{BS@countiii}{#1}% column + \setcounter{BS@countiv}{#2}% row + \ifnum\value{BS@countiii}<1% + \PackageError{battleship}% + {ship segment outside of the grid}% + {You tried to set a ship segment at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (\BS@columns,\BS@rows)}% + \fi% + \ifnum\value{BS@countiv}<1% + \PackageError{battleship}% + {ship segment outside of the grid}% + {You tried to set a ship segment at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (\BS@columns,\BS@rows)}% + \fi% + % BS@columns = \BS@columns + 1 + \stepcounter{BS@countiii}% + \stepcounter{BS@countiv}% + \ifnum\value{BS@countiii}>\value{BS@columns}% + \PackageError{battleship}% + {ship segment outside of the grid}% + {You tried to set a ship segment at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (\BS@columns,\BS@rows)}% + \fi% + \ifnum\value{BS@countiv}>\value{BS@rows}% + \PackageError{battleship}% + {ship segment outside of the grid}% + {You tried to set a ship segment at (#1,#2),\MessageBreak which is outside the grid (1,1) .. (\BS@columns,\BS@rows)}% + \fi% }% % \newcommand*\BS@printship[1]% @@ -241,29 +277,102 @@ % \newcommand*\shipH[1]% {% - \setcounter{BS@shipV}{\value{BS@rows}}% - \setcounter{BS@shipH}{0}% + \setcounter{BS@countii}{\value{BS@rows}}% + \setcounter{BS@counti}{0}% \forcsvlist\BS@printpartsH{#1}% }% % \newcommand*\shipV[1]% {% - \setcounter{BS@shipV}{0}% - \setcounter{BS@shipH}{0}% + \setcounter{BS@countii}{0}% + \setcounter{BS@counti}{0}% \forcsvlist\BS@printpartsV{#1}% }% % -\newcommand*\ship[3]% +\newcommand*\placesegment[3]% {% + \BS@ingrid{#1}{#2}% \node at (#1\BS@Pfive,#2\BS@Pfive){#3};% }% % +\let\ship\placesegment% +% +\newcommand*\placeisland[2]% +{% + \BS@ingrid{#1}{#2}% + \node at (#1\BS@Pfive,#2\BS@Pfive){\Island};% +}% +% +\newcommand*\placewater[2]% +{% + \BS@ingrid{#1}{#2}% + \node at (#1\BS@Pfive,#2\BS@Pfive){\Water};% +}% +% \newcommand*\shipbox[2][]% {% \setkeys{shipbox}{#1}% \gdef\BS@shipbox{#2}% }% % +\newcommand*\placeship[4]% +{% + \setcounter{BS@counti}{#4}% length + \ifnum\value{BS@counti}<1% + \PackageError{battleship}% + {ship length < 1}% + {The length of your ship should be at least 1}% + \fi% + \ifnum\value{BS@counti}>10% + \PackageError{battleship}% + {ship length > 10}% + {The supported max length of ships is 10!}% + \fi% + \ifnum\value{BS@counti}=1% + \placesegment{#2}{#3}{\Ship}% + \else% + \setcounter{BS@whiledo}{\value{BS@counti}}% + \addtocounter{BS@whiledo}{-2}% length of middle ship + \ifthenelse{\equal{#1}{V}}% + {% + \placesegment{#2}{#3}{\ShipB}% + \setcounter{BS@countii}{#3}% + \whiledo{\value{BS@whiledo}>0}% + {% + \addtocounter{BS@whiledo}{-1}% + \stepcounter{BS@countii}% + \placesegment{#2}{\theBS@countii}{\ShipC}% + }% + \stepcounter{BS@countii}% + \placesegment{#2}{\theBS@countii}{\ShipT}% + }% + {% + \ifthenelse{\equal{#1}{H}}% + {% + \placesegment{#2}{#3}{\ShipL}% + \setcounter{BS@counti}{#2}% + \whiledo{\value{BS@whiledo}>0}% + {% + \addtocounter{BS@whiledo}{-1}% + \stepcounter{BS@counti}% + \placesegment{\theBS@counti}{#3}{\ShipC}% + }% + \stepcounter{BS@counti}% + \placesegment{\theBS@counti}{#3}{\ShipR}% + }% + {\PackageError{battleship}% + {invalid direction (H/V)}% + {You can place your ship only\MessageBreak% + horizontally (H) or vertically (V)!}}% + }% + \fi% +}% +% +\newcommand*\battleshipsetup[1]% +{% + \setkeys{battleship.sty}{#1}% +}% +% \newenvironment{battleship}[1][]% {% \setkeys{battleship}{#1}% |