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
|
%D \module
%D [ file=games-hex,
%D version=2008.10.29,
%D title=\CONTEXT\ User Module,
%D subtitle=Hex,
%D author=Wolfgang Schuster,
%D date=\currentdate,
%D email=schuster.wolfgang@googlemail.com,
%D copyright=Wolfgang Schuster]
\writestatus{loading}{Context User Module / Games - Hex}
\unprotect
\definegame[\v!hexgame][\v!hex]
\def\sgfchar#1%
{\ifnum#1<9
\char\number\numexpr#1+64\relax
\else\ifnum#1<26
\char\number\numexpr#1+65\relax
\fi\fi}
\def\hex!commands
{newboard,drawboard,player}
\def\hex!copygamecommands
{\expanded{\copyparameters[][hex!][\hex!commands]}}
\setvalue{\e!begin\????gm\????gm\v!hex}%
{\hex!copygamecommands
\hex!boardsize
\hex!gamevalues}
\defineoverlay[overlay:hex][\overlaybutton{JS(Walk_Field{games!hex})}]
\setvalue{\e!end\????gm\????gm\v!hex}%
{\doif{\gameparameter\c!interactive}\v!yes\hex!fieldstack}
\def\hex!fieldstack
{\expanded{\definefieldstack[games!hex][\hex!list!symbols][\c!frame=\v!off]}%
\framed
[\c!frame=\v!off,
\c!background={foreground,overlay:hex},
\c!offset=\v!overlay]
{\fieldstack[games!hex]}}
\def\hex!boardsize % what are common values for hex
{\assignvalue{\gameparameter\c!nx}\hex!board!nx{11}{14}{19}%
\assignvalue{\gameparameter\c!ny}\hex!board!ny{11}{14}{19}%
\ctxlua{thirddata.games.hex.setup.nx = \number\hex!board!nx }%
\ctxlua{thirddata.games.hex.setup.ny = \number\hex!board!ny }}
\def\hex!gamevalues
{\startlua
thirddata.games.hex.setup.size = \number\dimexpr\gameparameter\c!stonesize\relax ;
thirddata.games.hex.setup.dx = \number\dimexpr\gameparameter\c!dx\relax ;
thirddata.games.hex.setup.dy = \number\dimexpr\gameparameter\c!dy\relax ;
thirddata.games.hex.setup.offset = \number\dimexpr\gameparameter\c!frameoffset\relax ;
thirddata.games.hex.setup.distance = \number\dimexpr\gameparameter\c!labeldistance\relax ;
\stoplua}
%D User commands
\def\hex!newboard
{\ctxlua{thirddata.games.hex.board_new()}}
\def\hex!drawboard
{\doifnot{\gameparameter\c!interactive}\v!yes
{\hex!setboard{0}%
\hex!getboard{0}}}
\def\hex!setboard#1%
{\ctxlua{thirddata.games.hex.board_draw("games:hex:#1")}}
\def\hex!getboard#1%
{\uniqueMPgraphic{games:hex:#1}}
\def\hex!player[#1]#2#3%
{\bgroup
\processaction
[#1]
[ \v!red=>\chardef\stonecolor\plusone,
\v!blue=>\chardef\stonecolor\plustwo]%
\ctxlua{thirddata.games.hex.field[#2][#3] = { color = \number\stonecolor }}%
\egroup
\doif{\gameparameter\c!interactive}\v!yes\hex!symbol}
\newcount\hex!count!symbols
\let\hex!list!symbols\empty
\def\hex!symbol
{\expanded{\advance\hex!count!symbols\plusone}%
\expanded{\hex!setboard{\number\hex!count!symbols}}%
\expanded{\definesymbol[hex!symbol!\number\hex!count!symbols][\noexpand\hex!getboard{\number\hex!count!symbols}]}%
\expanded{\appendtocommalist{hex!symbol!\number\hex!count!symbols}}\hex!list!symbols}
%D Lua functions
\ctxloadluafile{games-hex}{}
%D Default values
\setupgame
[\v!hex]
[\c!size=\v!small,
\c!nx=\gameparameter\c!size,
\c!ny=\gameparameter\c!size,
\c!stonesize=\bodyfontsize,
\c!dx=\gameparameter\c!stonesize,
\c!dy=\gameparameter\c!dx,
\c!frameoffset=0pt,
\c!labeldistance=0pt,
\c!labelstyle=\tx,
\c!labelcolor=,
\c!interaction=\v!no]
\protect \endinput
|