summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/hexgame/hexgame.sty
blob: 97a7d71e5d46678fe9d5b3a18bbe1c71d38cf015 (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
%%
%% This is file `hexgame.sty',
%%
%% --------------------------------------------------------------------------
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% 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.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%% 
%% File: hexgame.sty Copyright (C) 2006 Meron Brouwer (meron.brouwer@gmail.com)
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hexgame}
          [2006/08/01 v1.0 `hexgame' package]
\RequirePackage{pstcol}
\RequirePackage{pst-poly}
\RequirePackage{calc}
\RequirePackage{ifthen}
\newlength\halfhexheight			
\setlength\halfhexheight{0.866025404cm}		
\newlength\halfhexwidth				
\setlength\halfhexwidth{1cm}			
\newlength\hexgameboxwidth			
\setlength\hexgameboxwidth{0.45\textwidth} 	
\newlength\hexgameheight			
\newlength\halfhexgameheight			
\newlength\hexgamewidth				
\newlength\halfhexgamewidth			
\newlength\startpointx				
\newlength\startpointy				
\newsavebox\hexgamebox				
\definecolor{playerone}{rgb}{0,0, .8} 		
\definecolor{playertwo}{rgb}{0.8,0,0} 		
\newcounter{hexboardsize}			
\newenvironment{hexgame}[1]
	{\psset{unit=1cm,PstPicture=false}
	\setcounter{hexboardsize}{#1}					
	\setlength\hexgamewidth{(#1\halfhexwidth*2)+(#1\halfhexwidth)+(\halfhexwidth)} 
	\setlength\hexgameheight{(#1\halfhexheight*2)+(\halfhexheight)} 
	\setlength\halfhexgameheight{0.5\hexgameheight} 		
	\setlength\halfhexgamewidth{0.5\hexgamewidth} 			
	\setlength\startpointx{0.5\hexgamewidth} 			
	\setlength\startpointy{1.5\halfhexheight} 			
	\begin{lrbox}{\hexgamebox}
	\begin{pspicture}(\the\hexgamewidth,\the\hexgameheight)%
	\psframe[fillstyle=solid,fillcolor=playerone,linewidth=0.8pt](0,0)(\the\halfhexgamewidth,\the\halfhexgameheight)
	\psframe[fillstyle=solid,fillcolor=playerone,linewidth=0.8pt](\the\halfhexgamewidth,\the\halfhexgameheight)(\the\hexgamewidth,\the\hexgameheight)
	\psframe[fillstyle=solid,fillcolor=playertwo,linewidth=0.8pt](0,\the\hexgameheight)(\the\halfhexgamewidth,\the\halfhexgameheight)
	\psframe[fillstyle=solid,fillcolor=playertwo,linewidth=0.8pt](\the\halfhexgamewidth,\the\halfhexgameheight)(\the\hexgamewidth,0)
	\psdiamond(\the\halfhexgamewidth,\the\halfhexgameheight)(\the\halfhexgamewidth,\the\halfhexgameheight)
	\multirput(\the\startpointx,\the\startpointy)(1.5cm,\halfhexheight){#1}{
	\multirput(0,0)(-1.5cm,\halfhexheight){#1}{\PstHexagon[linewidth=0.5pt,unit=1cm,fillstyle=solid,fillcolor=white]}}}
	{\end{pspicture}
	\end{lrbox}
	\psscaleboxto(\the\hexgameboxwidth,0){\usebox{\hexgamebox}}}
\newlength\refpointx				
\newlength\refpointy	
\newlength\nexthexx				
\newlength\nexthexy				
\newcounter{stepcounter}			
\newcounter{modulocounter}
\newcounter{squaredboardsize}
\newcommand\colorhex[2]{\setcounter{stepcounter}{\value{hexboardsize}}
			\setcounter{modulocounter}{#1}
			\setcounter{squaredboardsize}{\value{hexboardsize}*\value{hexboardsize}}
			\ifthenelse{#1>\value{squaredboardsize}}{\PackageWarning{hexgame}{Number to big}}{
			\setlength\refpointx{\startpointx}
			\addtolength{\refpointx}{0.5mm}
			\setlength\refpointy{\startpointy}
			\whiledo{\value{stepcounter}<#1}{\addtocounter{stepcounter}{\value{hexboardsize}}
					\addtolength{\refpointx}{-1.5\halfhexwidth}
					\addtolength{\refpointy}{\halfhexheight}
					\addtocounter{modulocounter}{-\value{hexboardsize}}}
			\setlength\nexthexx{(\refpointx)+1.5\halfhexwidth*((\value{modulocounter})-1)}
			\setlength\nexthexy{(\refpointy)+\halfhexheight*((\value{modulocounter})-1)}
			\rput(\the\nexthexx,\the\nexthexy){\PstHexagon[linewidth=0.5pt,unit=1cm,fillstyle=solid,fillcolor=#2]}}}
\newcommand\labelhex[2]{\setcounter{stepcounter}{\value{hexboardsize}}
			\setcounter{modulocounter}{#1}
			\setcounter{squaredboardsize}{\value{hexboardsize}*\value{hexboardsize}}
			\ifthenelse{#1>\value{squaredboardsize}}{\PackageWarning{hexgame}{Number to big}}{
			\setlength\refpointx{\startpointx}
			\addtolength{\refpointx}{0.5mm}
			\setlength\refpointy{\startpointy}
			\whiledo{\value{stepcounter}<#1}{\addtocounter{stepcounter}{\value{hexboardsize}}
					\addtolength{\refpointx}{-1.5\halfhexwidth}
					\addtolength{\refpointy}{\halfhexheight}
					\addtocounter{modulocounter}{-\value{hexboardsize}}}
			\setlength\nexthexx{(\refpointx)+1.5\halfhexwidth*((\value{modulocounter})-1)}
			\setlength\nexthexy{(\refpointy)+\halfhexheight*((\value{modulocounter})-1)}
			\rput(\the\nexthexx,\the\nexthexy){\textbf{\large #2}}}}
%%
%% End of file `hexgame.sty'.