/* Goban Client - DMS - Mar 98 - by Sylvain HUET */ var bitmapfile="Dms/Games/Goban/goban.bmp";; defcom Cregister=register;; defcom Cspeak0=speak0 S;; defcom Cplay=play I I;; defcom Cspeak=speak I S;; defcom Cmove=move I I I;; defcom Cquit=quit I;; defcom Creset=reset I;; typeof bitmap=ObjBitmap;; typeof win=ObjWin;; typeof banner=ObjText;; typeof text=ObjText;; typeof cmd=ObjText;; typeof list=ObjList;; typeof title=S;; typeof games=[[S r1] r1];; struct Game=[numGame:I,posGame:S,typeGame:I,opponentIdGame:I,reverseGame:I, winGame:ObjWin,bannerGame:ObjText,textGame:ObjText, editGame:ObjText,boardGame:ObjBitmap,indexGame:I, whiteGame:ObjText,blackGame:ObjText] mkGame;; var nbgames=16;; typeof boards=tab Game;; fun _boardmessage (g,mess)= let g.textGame -> text in { _ADDtext text mess ; let ( _GETlineCount text ) -> size in { while ( size > 60 ) do { _DELline text 0 ; set size = size - 1 } ; _SCROLLtext text 0 size }; mess };; fun _resets(x,g,r)= if r then (_DMSsend this Creset [g.numGame]; _boardmessage g (_loc this "GOB_SEND" nil)) else nil;; fun _reset(a,g)= _DLGrflmessage _DLGMessageBox _channel g.winGame (_loc this "GOB_RESET" nil) (_loc this "GOB_RESETDOYOU" nil) 2 @_resets g ;; fun drawboard(g,b,p)= _FILLbitmap b 0; let 0-> i in while i<361 do (let nth_char p i -> s in let if s==32 then 0 else if s=='b then 1 else 2 -> x in _CPbitmap16 b (mod i 19)*16 (18-i/19)*16 bitmap x*16 0 16 16 nil; set i=i+1); 0;; fun drawcase(g,b,p,i)= let nth_char p i -> s in let if s==32 then 0 else if s=='b then 1 else 2 -> x in _CPbitmap16 b (mod i 19)*16 (18-i/19)*16 bitmap x*16 0 16 16 nil;; fun posbyxy(g,x,y)= let [(x-10)/16 (y-40)/16] -> [i j] in if i<0 || i>=19 || j<0 || j>=19 then nil else i+(18-j)*19;; fun _clickG(a,g,x,y,b)= let posbyxy g x y -> j in if j==nil then nil else let nth_char g.posGame j-> a in let if g.typeGame then ['w 'b] else ['b 'w] -> [col adv] in let if b==1 then if a==col then 32 else col else if a==32 then adv else if a==adv then col else 32 -> new in (_DMSsend this Cmove [g.numGame j new]; _boardmessage g (_loc this "GOB_MOVE" nil));; fun _cursorG(a,g,x,y,b)= let posbyxy g x y -> j in if j==nil then _SETwinCursor g.winGame StdCursor else _SETwinCursor g.winGame HandCursor;; fun _textG(x,g)= if (_GETlineCount g.editGame) >= 2 then let _GETline g.editGame 0 -> ligne in (_DMSsend this Cspeak [g.numGame ligne]; _DELline g.editGame 0) else nil;; fun _destroyG(a,g)= set boards.(g.numGame)=nil; _DMSsend this Cquit [g.numGame]; _DSbitmap g.boardGame;; fun _paintG(a,g)= _BLTbitmap g.winGame g.boardGame 10 40;; defcom SmainCom=main S;; defcom S_load=_load S;; fun _contacto(a,g)= if g.opponentIdGame==nil then nil else _DMSevent this "select" itoa g.opponentIdGame nil;; defcom Cwhite=white I S;; defcom Cblack=black I S;; fun _textwG(a,g)= _DMSsend this Cwhite [g.numGame _GETtext g.whiteGame];; fun _textbG(a,g)= _DMSsend this Cblack [g.numGame _GETtext g.blackGame];; fun _incw(a,g)= _SETtext g.whiteGame itoa 1+atoi _GETtext g.whiteGame;; fun _incb(a,g)= _SETtext g.blackGame itoa 1+atoi _GETtext g.blackGame;; fun __openGame(n,pos,type,wh,bl)= let mkGame [n pos type nil if type==1 then 1 else 0 nil nil nil nil nil nil nil nil] -> g in let nth_list games n -> l in let strcatn (_loc this "GOB_GAME" nil)::" "::(itoa n+1)::" : "::(hd l)::" / "::(hd tl l)::nil -> banner in let _CRwindow _channel win nil nil 534 384 WN_MENU+WN_MINBOX banner -> win in (_CBwinDestroy win @_destroyG g; _CBwinPaint win @_paintG g; set g.bannerGame=_CRtext _channel win 10 10 304 20 ET_DOWN banner; set g.winGame=win; set g.textGame=_CRtext _channel win 324 10 200 310 ET_VSCROLL|ET_AVSCROLL|ET_DOWN ""; set g.editGame=_CReditText _channel win 324 324 200 20 ET_AHSCROLL|ET_AVSCROLL|ET_DOWN ""; _CBtext g.editGame @_textG g; if type==0 || type==1 then (_CBbutton (_CRbutton _channel win 384 354 40 20 0 (_loc this "GOB_RESET" nil)) @_reset g; _CBbutton (_CRbutton _channel win 424 354 100 20 0 (_loc this "GOB_CONTACT" nil)) @_contacto g; _CBwinClick win @_clickG g; _CBcursorMove win @_cursorG g) else nil; set g.boardGame=_CRbitmap _channel 304 304; drawboard g g.boardGame pos; if type==0 || type==1 then (_CBbutton (_CRbutton _channel win 10 354 40 20 0 (_loc this "GOB_WHITE" nil)) @_incw g; set g.whiteGame=_CReditLine _channel win 50 354 100 20 ET_DOWN wh; _CBtext g.whiteGame @_textwG g; _CBbutton (_CRbutton _channel win 164 354 40 20 0 (_loc this "GOB_BLACK" nil)) @_incb g; set g.blackGame=_CReditLine _channel win 204 354 100 20 ET_DOWN bl; _CBtext g.blackGame @_textbG g) else (_CRtext _channel win 10 354 40 20 ET_BORDER (_loc this "GOB_WHITE" nil); set g.whiteGame=_CRtext _channel win 50 354 100 20 ET_DOWN wh; _CRtext _channel win 164 354 40 20 ET_BORDER (_loc this "GOB_BLACK" nil); set g.blackGame=_CRtext _channel win 204 354 100 20 ET_DOWN bl); _paintG nil g; set boards.n=g ); 0;; fun __white(i,s)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else _SETtext b.whiteGame s;; fun __black(i,s)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else _SETtext b.blackGame s;; fun __hear(i,s)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else _boardmessage b s;; fun __update(i)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else let nth_list games i -> l in let strcatn (_loc this "GOB_GAME" nil)::" "::(itoa i+1)::" : "::(hd l)::" / "::(hd tl l)::nil -> txt in (_SETwindowName b.winGame txt; _SETtext b.bannerGame txt);; fun __pos(i,p)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else (set b.posGame=p; drawboard b b.boardGame p; _paintG nil b);; fun __move(i,j,k)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else (set_nth_char b.posGame j k; drawcase b b.boardGame b.posGame j; _paintG nil b);; fun __opponentId(i,id)= if i<0 || i>=nbgames then nil else let boards.i -> b in if b==nil then nil else set b.opponentIdGame=id;; fun _select(a,b)= let b->[win game i] in (_DSwindow win; _DMSsend this Cplay [game i]);; fun choicewindow(i,l)= let _CRwindow _channel win 200 120 320 130 WN_MENU+WN_MINBOX (_loc this "GOB_SEL" nil) -> win in (_CRtext _channel win 10 10 300 20 ET_DOWN strcatn (_loc this "GOB_GAME" nil)::" "::(itoa i+1)::" : "::(hd l)::" / "::(hd tl l)::nil; if strcmp hd l "..." then nil else _CBbutton (_CRbutton _channel win 20 40 280 20 0 (_loc this "GOB_PWHITES" nil)) @_select [win i 0]; if strcmp hd tl l "..." then nil else _CBbutton (_CRbutton _channel win 20 70 280 20 0 (_loc this "GOB_PBLACKS" nil)) @_select [win i 1]; _CBbutton (_CRbutton _channel win 20 100 280 20 0 (_loc this "GOB_JUST" nil)) @_select [win i 2] ); 0;; fun _contact(a,b,n,txt)= choicewindow n nth_list games n;; fun _message (mess)= _ADDtext text mess ; let ( _GETlineCount text ) -> size in { while ( size > 60 ) do { _DELline text 0 ; set size = size - 1 } ; _SCROLLtext text 0 size }; mess ;; fun _textE(x,y)= if (_GETlineCount cmd) >= 2 then let _GETline cmd 0 -> ligne in (_DMSsend this Cspeak0 [ligne]; _DELline cmd 0) else nil;; fun _destroyE(a,b)= _DMSdelete this;; fun _end(b)= _DMSdelete this;; fun _resize(x,s)= let x->[wn x y w h] in _SIZEwindow win w h x y; 0;; fun _resizeE(a,b,w,h)= if (h<70)||(w<20) then nil else (_SIZEtext banner w-10 20 5 5; _SIZElist list w-10 (h-65)*100/250 5 30; _SIZEtext text w-10 (h-65)*150/250 5 30+(h-65)*105/250; _SIZEtext cmd w-10 20 5 h-25);; fun createwin(w,h)= set banner=_CRtext _channel win 5 5 w-10 20 ET_BORDER+ET_AHSCROLL strcat title strcat " " (_loc this "GOB_SEL2" nil); set list=_CRlist _channel win 5 30 w-10 (h-65)*100/250 LB_DOWN+LB_VSCROLL; _CBlistDclick list @_contact 0; set text=_CRtext _channel win 5 (h-65)*135/250 w-10 (h-65)*150/250 ET_VSCROLL|ET_AVSCROLL|ET_DOWN ""; set cmd=_CReditText _channel win 5 h-25 w-10 20 ET_AHSCROLL|ET_AVSCROLL|ET_DOWN (_loc this "GOB_HELLO" nil); _CBtext cmd @_textE 0;; fun IniDMI(param)= set title=_DMSgetName this; set boards=mktab nbgames nil; set bitmap=_LDbitmap _channel _checkpack bitmapfile; let _DMSgetZone this (_loc this "GOB_BOARDS" nil) @_end @_resize @_end ->[wn x y w h] in if wn==nil then (set win=_CRwindow _channel DMSwin nil nil 280 315 WN_MENU+WN_MINBOX+WN_SIZEBOX title; _CBwinDestroy win @_destroyE 0; createwin 280 315) else (set win=_CRwindow _channel wn x y w h WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER title; createwin w h); _CBwinSize win @_resizeE 0; _DMSsend this Cregister []; 0;; fun displgame(l,i)= if l==nil then 0 else let l->[a n] in (_ADDlist list 100 strcatn (itoa i)::"-"::(hd a)::"/"::(hd tl a)::nil; displgame n i+1);; fun __games(s)= _RSTlist list; set games=strextr s; displgame games 1;; fun __hear0(s)= _message s;;