Написаны Лыбой Алексеем
(Alex Lyba 2:5014/5.5@FidoNet)Ниже представлены исходные тексты некоторых апплетов на языке Oberon-2, откомпилированные при помощи компилятора JOB, написанного Свердловым С. З.
Автор будет признателен всем, кто пришлет свои пожелания или замечания по поводу работы программ. Замечания по поводу их текстов не принимаются. : )
(* Filler <applet code="filler_Game" width=420 height=420> </applet> *)
(* Copyright (C) Lyba Alexey 1998 *)
MODULE filler;
IMPORT awt:=javaawt, awc:=javaawtColor, app:=javaapplet, util:=javautil, lang:=javalang, SYSTEM;
CONST N1=41; N2=40; M1=26; M2=25; TYPE ExtArray = ARRAY M1+2,N1+2 OF INTEGER; IntArray = ARRAY M2+2,N2+2 OF INTEGER; PGame*=POINTER TO Game; Game*=RECORD (app.Applet) g:awt.PGraphics; Ext,UserExt,CompExt:ExtArray; Int,UserInt,CompInt:IntArray; MouseX,MouseY:INTEGER; UserColor,OldUserColor:INTEGER; CompColor,OldCompColor:INTEGER; UsersPoints,CompsPoints:INTEGER; rand:util.PRandom; NewGame:awt.PButton; xpoints,ypoints:ARRAY 5 OF INTEGER; END;
PROCEDURE Rnd(r:util.PRandom; n:INTEGER):INTEGER; BEGIN RETURN SHORT(ENTIER(n*r.nextFloat())); END Rnd;
PROCEDURE CountUsersPoints(a:PGame); VAR i,j:INTEGER; Cur:INTEGER; BEGIN Cur:=0; FOR i:=1 TO M1-1 DO FOR j:=1 TO N1-1 DO IF a.UserExt[i][j]#0 THEN INC(Cur); END; END; END; FOR i:=1 TO M2-1 DO FOR j:=1 TO N2-1 DO IF a.UserInt[i][j]#0 THEN INC(Cur); END; END; END; a.UsersPoints:=Cur; END CountUsersPoints;
PROCEDURE CountCompsPoints(a:PGame); VAR i,j:INTEGER; Cur:INTEGER; BEGIN Cur:=0; FOR i:=1 TO M1-1 DO FOR j:=1 TO N1-1 DO IF a.CompExt[i][j]#0 THEN INC(Cur); END; END; END; FOR i:=1 TO M2-1 DO FOR j:=1 TO N2-1 DO IF a.CompInt[i][j]#0 THEN INC(Cur); END; END; END; a.CompsPoints:=Cur; END CountCompsPoints;
PROCEDURE Str( c : ARRAY OF CHAR ) : J.PString; VAR s:J.PString; len:INTEGER; BEGIN SYSTEM.NEW( s, c ); len := s.length(); IF (len>0) & (s.charAt(len-1)=0X) THEN RETURN s.substring(0,len-1); END; RETURN s; END Str;
PROCEDURE Romb(a:PGame; g:awt.PGraphics; x,y,RombColor:INTEGER); VAR RombCol,num:INTEGER; BEGIN a.xpoints[1]:=x+5; a.xpoints[2]:=x+10; a.xpoints[3]:=x+5; a.xpoints[4]:=x; a.xpoints[0]:=x+5; a.ypoints[1]:=y; a.ypoints[2]:=y+6; a.ypoints[3]:=y+12; a.ypoints[4]:=y+6; a.ypoints[0]:=y; num:=5; CASE RombColor OF | 1: a.g.setColor(awc.blue); | 2: a.g.setColor(awc.green); | 3: a.g.setColor(awc.red); | 4: a.g.setColor(awc.yellow); | 5: a.g.setColor(awc.white); | 6: a.g.setColor(awc.magenta); ELSE END; a.g.fillPolygon(a.xpoints,a.ypoints,num); a.g.setColor(awc.darkGray); a.g.drawLine(x+5,y,x+10,y+6); a.g.drawLine(x+10,y+6,x+5,y+12); a.g.drawLine(x+5,y+12,x,y+6); a.g.drawLine(x,y+6,x+5,y); END Romb;
PROCEDURE MouseButton(a:PGame; PosX:INTEGER); BEGIN a.g.fillRect(PosX,335,20,25); END MouseButton;
PROCEDURE (a:PGame) paint*(g:awt.PGraphics); VAR i,j:INTEGER; I,J,K,L:lang.PInteger; BEGIN FOR i:=1 TO M1-1 DO FOR j:=1 TO N1-1 DO Romb(a,g,10*j,12*i,a.Ext[i][j]); END; IF i#M1-1 THEN FOR j:=1 TO N2-1 DO Romb(a,g,10*j+5,i*12+6,a.Int[i][j]); END; END; END; a.g.setColor(awc.black); a.g.fillRect(90,325,240,40); a.g.setColor(awc.gray); FOR i:=1 TO 6 DO a.g.drawRect(57+i*40,332,25,30); END; IF (a.UserColor#1) & (a.CompColor#1) THEN a.g.setColor(awc.blue); MouseButton(a,100); END; IF (a.UserColor#2) & (a.CompColor#2) THEN a.g.setColor(awc.green); MouseButton(a,140); END; IF (a.UserColor#3) & (a.CompColor#3) THEN a.g.setColor(awc.red); MouseButton(a,180); END; IF (a.UserColor#4) & (a.CompColor#4) THEN a.g.setColor(awc.yellow); MouseButton(a,220); END; IF (a.UserColor#5) & (a.CompColor#5) THEN a.g.setColor(awc.white); MouseButton(a,260); END; IF (a.UserColor#6) & (a.CompColor#6) THEN a.g.setColor(awc.magenta); MouseButton(a,300); END; CountCompsPoints(a); CountUsersPoints(a); SYSTEM.NEW(I,a.CompsPoints); SYSTEM.NEW(J,a.UsersPoints); IF (((a.CompsPoints/1936)*100 MOD 1)>0.5) THEN SYSTEM.NEW(K,SHORT(ENTIER((a.CompsPoints/1936)*100))+1); ELSE SYSTEM.NEW(K,SHORT(ENTIER((a.CompsPoints/1936)*100))); END; IF (((a.UsersPoints/1936)*100 MOD 1)>0.5) THEN SYSTEM.NEW(L,SHORT(ENTIER((a.UsersPoints/1936)*100))+1); ELSE SYSTEM.NEW(L,SHORT(ENTIER((a.UsersPoints/1936)*100))); END; a.g.setColor(awc.black); a.g.fillRect(35,345,45,40); a.g.fillRect(365,345,45,40); a.g.setColor(awc.white); a.g.drawString(Str("Computer"),22,340); a.g.drawString(I.toString(),38,360); a.g.drawString(K.toString(),38,380); a.g.drawString(Str("%"),54,380); a.g.drawString(Str("Player"),363,340); a.g.drawString(J.toString(),370,360); a.g.drawString(L.toString(),370,380); a.g.drawString(Str("%"),386,380); END paint;
PROCEDURE UserMove(a:PGame); VAR i,j,k:INTEGER; BEGIN FOR k:=1 TO 20 DO FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO IF (a.UserExt[i][j]#0) & (a.CompExt[i][j]=0) THEN a.Ext[i][j]:=a.UserColor; END; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO IF (a.UserInt[i][j]#0) & (a.CompInt[i][j]=0) THEN a.Int[i][j]:=a.UserColor; END; END; END; FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO IF (a.UserExt[i][j]#0) & (a.CompExt[i][j]=0) THEN IF (a.Int[i][j-1]=a.UserColor) & (a.CompInt[i][j-1]=0) THEN a.UserInt[i][j-1]:=a.UserColor; END; IF (a.Int[i][j]=a.UserColor) & (a.CompInt[i][j]=0) THEN a.UserInt[i][j]:=a.UserColor; END; IF (a.Int[i-1][j-1]=a.UserColor) & (a.CompInt[i-1][j-1]=0) THEN a.UserInt[i-1][j-1]:=a.UserColor; END; IF (a.Int[i-1][j]=a.UserColor) & (a.CompInt[i-1][j]=0) THEN a.UserInt[i-1][j]:=a.UserColor; END; END; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO IF (a.UserInt[i][j]#0) & (a.CompInt[i][j]=0) THEN IF (a.Ext[i][j+1]=a.UserColor) & (a.CompExt[i][j+1]=0) THEN a.UserExt[i][j+1]:=a.UserColor; END; IF (a.Ext[i][j]=a.UserColor) & (a.CompExt[i][j]=0) THEN a.UserExt[i][j]:=a.UserColor; END; IF (a.Ext[i+1][j+1]=a.UserColor) & (a.CompExt[i+1][j+1]=0) THEN a.UserExt[i+1][j+1]:=a.UserColor; END; IF (a.Ext[i+1][j]=a.UserColor) & (a.CompExt[i+1][j]=0) THEN a.UserExt[i+1][j]:=a.UserColor; END; END; END; END; END; END UserMove;
PROCEDURE GetCompColor(a:PGame); TYPE PLocalGame = POINTER TO LocalGame; LocalGame = RECORD (app.Applet) Ext1,UserExt1,CompExt1:ExtArray; Int1,UserInt1,CompInt1:IntArray; END; VAR a1:PLocalGame; i,j,k,L,Col,Max,Cur:INTEGER; BEGIN NEW(a1); Max:=0; FOR L:=1 TO 6 DO FOR i:=0 TO M1+1 DO FOR j:=0 TO N1+1 DO a1.Ext1[i][j]:=a.Ext[i][j]; a1.UserExt1[i][j]:=a.UserExt[i][j]; a1.CompExt1[i][j]:=a.CompExt[i][j]; END; END;
FOR i:=0 TO M2+1 DO FOR j:=0 TO N2+1 DO a1.Int1[i][j]:=a.Int[i][j]; a1.UserInt1[i][j]:=a.UserInt[i][j]; a1.CompInt1[i][j]:=a.CompInt[i][j]; END; END; Col:=L; Cur:=0; FOR k:=1 TO 20 DO FOR i:=0 TO M1+1 DO FOR j:=0 TO N1+1 DO IF (a1.CompExt1[i][j]#0) & (a1.UserExt1[i][j]=0) THEN a1.Ext1[i][j]:=Col; END; END; END; FOR i:=0 TO M2+1 DO FOR j:=0 TO N2+1 DO IF (a1.CompInt1[i][j]#0) & (a1.UserInt1[i][j]=0) THEN a1.Int1[i][j]:=Col; END; END; END; FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO IF (a1.CompExt1[i][j]#0) & (a1.UserExt1[i][j]=0) THEN IF (a1.Int1[i][j-1]=Col) & (a1.UserInt1[i][j-1]=0) THEN a1.CompInt1[i][j-1]:=Col; INC(Cur); END; IF (a1.Int1[i][j]=Col) & (a1.UserInt1[i][j]=0) THEN a1.CompInt1[i][j]:=Col; INC(Cur); END; IF (a1.Int1[i-1][j-1]=Col) & (a1.UserInt1[i-1][j-1]=0) THEN a1.CompInt1[i-1][j-1]:=Col; INC(Cur); END; IF (a1.Int1[i-1][j]=Col) & (a1.UserInt1[i-1][j]=0) THEN a1.CompInt1[i-1][j]:=Col; INC(Cur); END; END; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO IF (a1.CompInt1[i][j]#0) & (a1.UserInt1[i][j]=0) THEN IF (a1.Ext1[i][j+1]=Col) & (a1.UserExt1[i][j+1]=0) THEN a1.CompExt1[i][j+1]:=Col; INC(Cur); END; IF (a1.Ext1[i][j]=Col) & (a1.UserExt1[i][j]=0) THEN a1.CompExt1[i][j]:=Col; INC(Cur); END; IF (a1.Ext1[i+1][j+1]=Col) & (a1.UserExt1[i+1][j+1]=0) THEN a1.CompExt1[i+1][j+1]:=Col; INC(Cur); END; IF (a1.Ext1[i+1][j]=Col) & (a1.UserExt1[i+1][j]=0) THEN a1.CompExt1[i+1][j]:=Col; INC(Cur); END; END; END; END; END; IF (Cur>Max) & (Col#a.OldCompColor) & (Col#a.UserColor) THEN Max:=Cur; a.CompColor:=Col; END; END; END GetCompColor;
PROCEDURE CompMove(a:PGame); VAR i,j,k:INTEGER; BEGIN a.OldCompColor:=a.CompColor; GetCompColor(a); FOR k:=1 TO 20 DO FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO IF (a.CompExt[i][j]#0) & (a.UserExt[i][j]=0) THEN a.Ext[i][j]:=a.CompColor; END; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO IF (a.CompInt[i][j]#0) & (a.UserInt[i][j]=0) THEN a.Int[i][j]:=a.CompColor; END; END; END; FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO IF (a.CompExt[i][j]#0) & (a.UserExt[i][j]=0) THEN IF (a.Int[i][j-1]=a.CompColor) & (a.UserInt[i][j-1]=0) THEN a.CompInt[i][j-1]:=a.CompColor; END; IF (a.Int[i][j]=a.CompColor) & (a.UserInt[i][j]=0) THEN a.CompInt[i][j]:=a.CompColor; END; IF (a.Int[i-1][j-1]=a.CompColor) & (a.UserInt[i-1][j-1]=0) THEN a.CompInt[i-1][j-1]:=a.CompColor; END; IF (a.Int[i-1][j]=a.CompColor) & (a.UserInt[i-1][j]=0) THEN a.CompInt[i-1][j]:=a.CompColor; END; END; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO IF (a.CompInt[i][j]#0) & (a.UserInt[i][j]=0) THEN IF (a.Ext[i][j+1]=a.CompColor) & (a.UserExt[i][j+1]=0) THEN a.CompExt[i][j+1]:=a.CompColor; END; IF (a.Ext[i][j]=a.CompColor) & (a.UserExt[i][j]=0) THEN a.CompExt[i][j]:=a.CompColor; END; IF (a.Ext[i+1][j+1]=a.CompColor) & (a.UserExt[i+1][j+1]=0) THEN a.CompExt[i+1][j+1]:=a.CompColor; END; IF (a.Ext[i+1][j]=a.CompColor) & (a.UserExt[i+1][j]=0) THEN a.CompExt[i+1][j]:=a.CompColor; END; END; END; END; END; END CompMove;
PROCEDURE (a:PGame) mouseDown*(evt:awt.PEvent; x,y:INTEGER):BOOLEAN; BEGIN a.MouseX:=x; a.MouseY:=y; IF ((x>=100) & (x<=120)) OR ((x>=140) & (x<=160)) OR ((x>=180) & (x<=200)) OR ((x>=220) & (x<=240)) OR ((x>=260) & (x<=280)) OR ((x>=300) & (x<=320)) & (y>=335) & (y<=360) THEN a.OldUserColor:=a.UserColor; IF (x>=100) & (x<=120) THEN a.UserColor:=1; END; IF (x>=140) & (x<=160) THEN a.UserColor:=2; END; IF (x>=180) & (x<=200) THEN a.UserColor:=3; END; IF (x>=220) & (x<=240) THEN a.UserColor:=4; END; IF (x>=260) & (x<=280) THEN a.UserColor:=5; END; IF (x>=300) & (x<=320) THEN a.UserColor:=6; END; IF (a.UserColor#a.CompColor) & (a.OldUserColor#a.UserColor) THEN UserMove(a); a.paint(a.g); CompMove(a); a.paint(a.g); END; END; RETURN TRUE; END mouseDown;
PROCEDURE NewGame(a:PGame); VAR i,j:INTEGER; BEGIN FOR i:=1 TO M1 DO FOR j:=1 TO N1 DO a.Ext[i][j]:=Rnd(a.rand,6)+1; a.UserExt[i][j]:=0; a.CompExt[i][j]:=0; END; END; FOR i:=1 TO M2 DO FOR j:=1 TO N2 DO a.Int[i][j]:=Rnd(a.rand,6)+1; a.UserInt[i][j]:=0; a.CompInt[i][j]:=0; END; END; a.CompsPoints:=0; a.UsersPoints:=0; a.UserExt[1][N1-1]:=a.Ext[1][N1-1]; a.CompExt[M1-1][1]:=a.Ext[M1-1][1]; a.UserColor:=a.UserExt[1][N1-1]; UserMove(a); a.CompColor:=a.CompExt[M1-1][1]; CompMove(a); CountUsersPoints(a); CountCompsPoints(a); a.g:=a.getGraphics(); a.paint(a.g); END NewGame;
PROCEDURE (a:PGame) init*(); VAR I:awt.PComponent; BEGIN NEW(a.rand); a.setLayout(NIL); SYSTEM.NEW(a.NewGame, Str("New Game")); a.NewGame.reshape(170,375,80,30); I:=a.add(a.NewGame); a.setBackground(awc.black); NewGame(a); END init;
PROCEDURE (a:PGame) action*(Evt:awt.PEvent; obj:lang.PObject):BOOLEAN; BEGIN IF (Evt.target IS awt.PButton) THEN IF (obj.equals(Str("New Game"))) THEN NewGame(a); END; RETURN TRUE; END; RETURN FALSE; END action;
END filler.
(* Voracity <applet code="voracity_Game" width=328 height=380> </applet> *)
(* Copyright (C) Lyba Alexey 1998 *)
MODULE voracity;
IMPORT awt:=javaawt, awc:=javaawtColor, app:=javaapplet, util:=javautil, lang:=javalang, SYSTEM;
CONST N=19; TYPE tArray = ARRAY N+2,N+2 OF INTEGER; PGame*=POINTER TO Game; Game*=RECORD (app.Applet) g:awt.PGraphics; T:tArray; XPos,YPos:INTEGER; MouseX,MouseY:INTEGER; UsersPoints:INTEGER; rand:util.PRandom; NewGame:awt.PButton; END;
PROCEDURE Rnd(r:util.PRandom; n:INTEGER):INTEGER; BEGIN RETURN SHORT(ENTIER(n*r.nextFloat())); END Rnd;
PROCEDURE Str( c : ARRAY OF CHAR ) : J.PString; VAR s:J.PString; len:INTEGER; BEGIN SYSTEM.NEW( s, c ); len := s.length(); IF (len>0) & (s.charAt(len-1)=0X) THEN RETURN s.substring(0,len-1); END; RETURN s; END Str;
PROCEDURE Item(a:PGame); VAR X,Y:INTEGER; BEGIN X:=8+15*a.XPos; Y:=8+15*a.YPos; a.g.setColor(awc.yellow); a.g.fillOval(X,Y,9,9); a.g.setColor(awc.red); a.g.drawOval(X,Y,9,9); a.g.fillOval(X+3,Y+3,3,3); END Item;
PROCEDURE NullSquare(a:PGame; X1,Y1:INTEGER); VAR X,Y:INTEGER; BEGIN X:=6+15*X1; Y:=6+15*Y1; a.g.setColor(awc.lightGray); a.g.fillRect(X,Y,14,14); END NullSquare;
PROCEDURE (a:PGame) paint*(g:awt.PGraphics); VAR i,j:INTEGER; I:lang.PInteger; BEGIN a.g.setColor(awc.gray); a.g.drawRect(20,20,285,285); FOR i:=1 TO N DO a.g.drawLine(5+i*15,20,5+i*15,305); END; FOR i:=1 TO N DO a.g.drawLine(20,5+i*15,305,5+i*15); END; FOR i:=1 TO N DO FOR j:=1 TO N DO NullSquare(a,i,j); IF (a.T[i][j]#0) THEN a.g.setColor(awc.black); SYSTEM.NEW(I,a.T[i][j]); a.g.drawString(I.toString(),10+15*i,17+15*j); END; END; END; a.g.setColor(awc.black); a.g.fillRect(275,345,40,30); a.g.fillRect(105,325,160,35); a.g.setColor(awc.yellow); a.g.drawString(Str("Score"),275,340); a.g.setColor(awc.white); a.g.drawString(Str("0"),281,357); Item(a); END paint;
PROCEDURE CanMove(a:PGame; X,Y:INTEGER):BOOLEAN; VAR i:INTEGER; BEGIN IF (a.T[X][Y]=0) THEN RETURN FALSE; ELSE FOR i:=1 TO a.T[X][Y] DO IF (a.T[a.XPos-(a.XPos-X)*i][a.YPos-(a.YPos-Y)*i]=0) THEN RETURN FALSE; END; END; END; RETURN TRUE; END CanMove;
PROCEDURE CheckToEnd(a:PGame); VAR X,Y:INTEGER; BEGIN X:=a.XPos; Y:=a.YPos; IF ~((CanMove(a,X-1,Y-1)) OR (CanMove(a,X,Y-1)) OR (CanMove(a,X+1,Y-1)) OR (CanMove(a,X-1,Y)) OR (CanMove(a,X+1,Y)) OR (CanMove(a,X-1,Y+1)) OR (CanMove(a,X,Y+1)) OR (CanMove(a,X+1,Y+1))) THEN a.g.setColor(awc.red); a.g.drawString(Str("GAME OVER"),155,340); a.g.setColor(awc.green); a.g.drawString(Str("YOU HAVE NO MORE MOVES"),113,357); END; END CheckToEnd;
PROCEDURE (a:PGame) mouseDown*(evt:awt.PEvent; x,y:INTEGER):BOOLEAN; VAR i,X1,Y1:INTEGER; I:lang.PInteger; BEGIN a.MouseX:=(x-5) DIV 15; a.MouseY:=(y-5) DIV 15; IF (x>=20) & (x<=305) & (y>=20) & (y<=305) & (x>=a.XPos*15-10) & (x<=a.XPos*15+35) & (y>=a.YPos*15-10) & (y<=a.YPos*15+35) & ((a.MouseX#a.XPos) OR (a.MouseY#a.YPos)) & (CanMove(a,a.MouseX,a.MouseY)) THEN X1:=a.XPos; Y1:=a.YPos; FOR i:=1 TO a.T[a.MouseX][a.MouseY] DO a.T[X1-(X1-a.MouseX)*i][Y1-(Y1-a.MouseY)*i]:=0; NullSquare(a,a.XPos,a.YPos); a.XPos:=X1-(X1-a.MouseX)*i; a.YPos:=Y1-(Y1-a.MouseY)*i; END; Item(a); a.UsersPoints:=a.UsersPoints+i-1; a.g.setColor(awc.black); a.g.fillRect(275,347,35,20); a.g.setColor(awc.white); SYSTEM.NEW(I,a.UsersPoints); a.g.drawString(I.toString(),281,357); CheckToEnd(a); END; RETURN TRUE; END mouseDown;
PROCEDURE NewGame(a:PGame); VAR i,j:INTEGER; BEGIN FOR i:=0 TO N+1 DO FOR j:=0 TO N+1 DO a.T[i][j]:=0; END; END; FOR i:=1 TO N DO FOR j:=1 TO N DO a.T[i][j]:=Rnd(a.rand,9)+1; END; END; a.XPos:=Rnd(a.rand,19)+1; a.YPos:=Rnd(a.rand,19)+1; a.T[a.XPos][a.YPos]:=0; a.UsersPoints:=0; a.paint(a.g); END NewGame;
PROCEDURE (a:PGame) init*(); VAR I:awt.PComponent; BEGIN NEW(a.rand); a.setLayout(NIL); SYSTEM.NEW(a.NewGame, Str("New Game")); a.NewGame.reshape(20,330,80,30); I:=a.add(a.NewGame); a.setBackground(awc.black); a.g:=a.getGraphics(); NewGame(a); END init;
PROCEDURE (a:PGame) action*(Evt:awt.PEvent; obj:lang.PObject):BOOLEAN; BEGIN IF (Evt.target IS awt.PButton) THEN IF (obj.equals(Str("New Game"))) THEN NewGame(a); END; RETURN TRUE; END; RETURN FALSE; END action;
END voracity.
(* Net <applet code="net_Game" width=351 height=400> </applet> *)
(* Copyright (C) Lyba Alexey 1998 *)
MODULE net; IMPORT awt:=javaawt, awc:=javaawtColor, app:=javaapplet, util:=javautil, lang:=javalang, SYSTEM; CONST On=1; Off=2;
TYPE TArray = ARRAY 13,13 OF INTEGER; PGame*=POINTER TO Game; Game*=RECORD (app.Applet) g:awt.PGraphics; t,p:TArray; MouseX,MouseY:INTEGER; Level:INTEGER; SPos:INTEGER; rand:util.PRandom; NewGame,Plus,Minus:awt.PButton; Col,Back,Blink:awt.PColor; n,m,w:INTEGER; END;
PROCEDURE Rnd(r:util.PRandom; n:INTEGER):INTEGER; BEGIN RETURN SHORT(ENTIER(n*r.nextFloat())); END Rnd;
PROCEDURE Str( c : ARRAY OF CHAR ) : J.PString; VAR s:J.PString; len:INTEGER; BEGIN SYSTEM.NEW( s, c ); len := s.length(); IF (len>0) & (s.charAt(len-1)=0X) THEN RETURN s.substring(0,len-1); END; RETURN s; END Str;
PROCEDURE CountTerm(a:PGame):INTEGER; VAR i,j:INTEGER; Counter:INTEGER; BEGIN Counter:=0; FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO IF ((a.t[i,j]=11) OR (a.t[i,j]=12) OR (a.t[i,j]=13) OR (a.t[i,j]=14)) THEN INC(Counter); END; END; END; RETURN Counter; END CountTerm;
PROCEDURE MakeNet(a:PGame); VAR i,j,k:INTEGER; Elem:INTEGER; Seted:BOOLEAN; BEGIN FOR i:=0 TO a.n+1 DO FOR j:=0 TO a.n+1 DO a.t[i,j]:=200; END; END; FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO a.t[i,j]:=0; END; END; i:=Rnd(a.rand,10)+1; CASE i OF | 1: a.t[a.SPos+1,a.SPos]:=70; | 2: a.t[a.SPos,a.SPos+1]:=80; | 3: a.t[a.SPos-1,a.SPos]:=90; | 4: a.t[a.SPos,a.SPos-2]:=100; | 5: a.t[a.SPos,a.SPos+1]:=80; a.t[a.SPos,a.SPos-2]:=100; | 6: a.t[a.SPos+1,a.SPos]:=70; a.t[a.SPos-1,a.SPos]:=90; | 7: a.t[a.SPos+1,a.SPos]:=70; a.t[a.SPos,a.SPos+1]:=80; a.t[a.SPos-1,a.SPos]:=90; | 8: a.t[a.SPos,a.SPos+1]:=80; a.t[a.SPos-1,a.SPos]:=90; a.t[a.SPos,a.SPos-2]:=100; | 9: a.t[a.SPos-1,a.SPos]:=90; a.t[a.SPos,a.SPos-2]:=100; a.t[a.SPos+1,a.SPos]:=70; | 10: a.t[a.SPos,a.SPos-2]:=100; a.t[a.SPos+1,a.SPos]:=70; a.t[a.SPos,a.SPos+1]:=80; ELSE END; a.t[a.SPos,a.SPos]:=200+i; a.t[a.SPos,a.SPos-1]:=200+i; FOR k:=1 TO 3*a.n DO FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO IF ((a.t[i,j]=70) OR (a.t[i,j]=80) OR (a.t[i,j]=90) OR (a.t[i,j]=100)) THEN CASE a.t[i,j] OF | 70: Seted:=FALSE; WHILE ~Seted DO Elem:=Rnd(a.rand,7)+1; CASE Elem OF | 1: IF (a.t[i+1,j]=0) & (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=2; a.t[i+1,j]:=70; a.t[i,j+1]:=80; END; | 2: IF (a.t[i,j-1]=0) & (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=3; a.t[i,j-1]:=100; a.t[i,j+1]:=80; END; | 3: IF (a.t[i,j-1]=0) & (a.t[i+1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=4; a.t[i,j-1]:=100; a.t[i+1,j]:=70; END; | 4: IF (a.t[i+1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=6; a.t[i+1,j]:=70; END; | 5: IF (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=8; a.t[i,j+1]:=80; END; | 6: IF (a.t[i,j-1]=0) THEN Seted:=TRUE; a.t[i,j]:=9; a.t[i,j-1]:=100; END; | 7: Seted:=TRUE; a.t[i,j]:=13; END; END; | 80: Seted:=FALSE; WHILE ~Seted DO Elem:=Rnd(a.rand,7)+1; CASE Elem OF | 1: IF (a.t[i+1,j]=0) & (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=1; a.t[i+1,j]:=70; a.t[i,j+1]:=80; END; | 2: IF (a.t[i,j+1]=0) & (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=3; a.t[i-1,j]:=90; a.t[i,j+1]:=80; END; | 3: IF (a.t[i-1,j]=0) & (a.t[i+1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=4; a.t[i-1,j]:=90; a.t[i+1,j]:=70; END; | 4: IF (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=5; a.t[i,j+1]:=80; END; | 5: IF (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=9; a.t[i-1,j]:=90; END; | 6: IF (a.t[i+1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=10; a.t[i+1,j]:=70; END; | 7: Seted:=TRUE; a.t[i,j]:=14; END; END; | 90: Seted:=FALSE; WHILE ~Seted DO Elem:=Rnd(a.rand,7)+1; CASE Elem OF | 1: IF (a.t[i,j-1]=0) & (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=1; a.t[i,j-1]:=100; a.t[i,j+1]:=80; END; | 2: IF (a.t[i-1,j]=0) & (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=2; a.t[i-1,j]:=90; a.t[i,j+1]:=80; END; | 3: IF (a.t[i,j-1]=0) & (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=4; a.t[i,j-1]:=100; a.t[i-1,j]:=90; END; | 4: IF (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=6; a.t[i-1,j]:=90; END; | 5: IF (a.t[i,j+1]=0) THEN Seted:=TRUE; a.t[i,j]:=7; a.t[i,j+1]:=80; END; | 6: IF (a.t[i,j-1]=0) THEN Seted:=TRUE; a.t[i,j]:=10; a.t[i,j-1]:=100; END; | 7: Seted:=TRUE; a.t[i,j]:=11; END; END; | 100: Seted:=FALSE; WHILE ~Seted DO Elem:=Rnd(a.rand,7)+1; CASE Elem OF | 1: IF (a.t[i+1,j]=0) & (a.t[i,j-1]=0) THEN Seted:=TRUE; a.t[i,j]:=1; a.t[i+1,j]:=70; a.t[i,j-1]:=100; END; | 2: IF (a.t[i+1,j]=0) & (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=2; a.t[i+1,j]:=70; a.t[i-1,j]:=90; END; | 3: IF (a.t[i,j-1]=0) & (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=3; a.t[i,j-1]:=100; a.t[i-1,j]:=90; END; | 4: IF (a.t[i,j-1]=0) THEN Seted:=TRUE; a.t[i,j]:=5; a.t[i,j-1]:=100; END; | 5: IF (a.t[i+1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=7; a.t[i+1,j]:=70; END; | 6: IF (a.t[i-1,j]=0) THEN Seted:=TRUE; a.t[i,j]:=8; a.t[i-1,j]:=90; END; | 7: Seted:=TRUE; a.t[i,j]:=12; END; END; END; END; END; END; END; END MakeNet;
PROCEDURE RightBegin(a:PGame); BEGIN a.g.setColor(a.Col); a.g.fillRect(186,174,5,5); a.g.setColor(a.Blink); a.g.drawLine(186,175,191,175); END RightBegin;
PROCEDURE DownBegin(a:PGame); BEGIN a.g.setColor(a.Col); a.g.fillRect(174,186,4,5); a.g.setColor(a.Blink); a.g.drawLine(175,186,175,190); END DownBegin;
PROCEDURE LeftBegin(a:PGame); BEGIN a.g.setColor(a.Col); a.g.fillRect(161,174,4,5); a.g.setColor(a.Blink); a.g.drawLine(161,175,164,175); END LeftBegin;
PROCEDURE UpBegin(a:PGame); BEGIN a.g.setColor(a.Col); a.g.fillRect(174,130,4,6); a.g.setColor(a.Blink); a.g.drawLine(175,130,175,136); END UpBegin;
PROCEDURE Server(a:PGame; S:INTEGER); BEGIN a.g.setColor(awc.lightGray); a.g.fillRect(169,136,16,49); a.g.setColor(awc.gray); a.g.drawLine(165,139,165,181); a.g.drawLine(166,138,166,182); a.g.drawLine(167,137,167,183); a.g.drawLine(168,136,168,184); a.g.drawRect(170,139,15,46); a.g.drawLine(172,159,183,159); a.g.drawLine(172,163,183,163); a.g.drawLine(175,169,180,169); a.g.drawLine(175,174,180,174); a.g.drawLine(175,179,180,179); a.g.drawLine(174,151,181,151); a.g.drawLine(180,152,180,152); a.g.drawLine(175,146,176,146); a.g.drawLine(182,146,182,146); a.g.drawRect(172,142,11,2); a.g.fillRect(175,166,6,2); a.g.fillRect(175,171,6,2); a.g.fillRect(175,176,6,2); a.g.setColor(awc.black); a.g.drawLine(173,146,173,146); IF (S=On) THEN a.g.setColor(awc.red); a.g.fillRect(172,166,2,2); a.g.setColor(awc.green); a.g.drawLine(179,146,179,146); a.g.fillRect(172,170,2,2); END; CASE a.t[a.SPos,a.SPos] OF | 201: RightBegin(a); | 202: DownBegin(a);; | 203: LeftBegin(a); | 204: UpBegin(a); | 205: UpBegin(a); DownBegin(a); | 206: RightBegin(a); LeftBegin(a); | 207: RightBegin(a); DownBegin(a); LeftBegin(a); | 208: DownBegin(a); LeftBegin(a); UpBegin(a); | 209: LeftBegin(a); UpBegin(a); RightBegin(a); | 210: UpBegin(a); RightBegin(a); DownBegin(a); ELSE END; END Server;
PROCEDURE Comp(a:PGame; x,y,Switch:INTEGER); VAR i,j:INTEGER; BEGIN a.g.setColor(awc.black); a.g.drawRect(x+6,y+4,18,15); a.g.setColor(awc.white); a.g.drawRect(x+7,y+5,16,13); a.g.drawRect(x+8,y+6,14,11); a.g.setColor(awc.gray); a.g.drawRect(x+9,y+7,12,9); a.g.setColor(awc.white); a.g.drawLine(x+10,y+20,x+21,y+20); IF (Switch=Off) THEN a.g.setColor(awc.black); a.g.fillRect(x+10,y+8,11,8); ELSE a.g.setColor(awc.cyan); a.g.fillRect(x+10,y+8,11,8); a.g.setColor(awc.black); a.g.fillRect(x+16,y+8,3,7); a.g.drawLine(x+19,y+9,x+19,y+15); a.g.drawLine(x+15,y+9,x+15,y+15); a.g.drawLine(x+13,y+9,x+14,y+9); a.g.drawLine(x+13,y+15,x+13,y+15); a.g.drawLine(x+11,y+8,x+11,y+8); a.g.drawLine(x+11,y+14,x+11,y+14); a.g.setColor(awc.red); a.g.drawLine(x+11,y+10,x+11,y+10); a.g.drawLine(x+13,y+11,x+14,y+11); a.g.drawLine(x+16,y+9,x+16,y+10); a.g.setColor(awc.blue); a.g.drawLine(x+11,y+12,x+11,y+12); a.g.drawLine(x+13,y+13,x+14,y+13); a.g.drawLine(x+16,y+12,x+16,y+13); a.g.setColor(awc.green); a.g.drawLine(x+18,y+9,x+18,y+10); a.g.setColor(awc.yellow); a.g.drawLine(x+18,y+12,x+18,y+13); END; a.g.setColor(awc.black); a.g.drawLine(x+3,y+26,x+28,y+26); a.g.drawLine(x+3,y+26,x+3,y+23); a.g.drawLine(x+4,y+22,x+4,y+21); a.g.drawLine(x+4,y+21,x+27,y+21); a.g.drawLine(x+27,y+21,x+27,y+22); a.g.drawLine(x+28,y+23,x+28,y+26); a.g.setColor(awc.white); a.g.fillRect(x+5,y+22,22,4); a.g.setColor(awc.lightGray); FOR i:=1 TO 5 DO a.g.drawLine(x+4+4*i,y+22,x+4+4*i,y+22); a.g.drawLine(x+6+4*i,y+23,x+6+4*i,y+23); a.g.drawLine(x+4+4*i,y+24,x+4+4*i,y+24); a.g.drawLine(x+6+4*i,y+25,x+6+4*i,y+25); END; a.g.setColor(awc.gray); a.g.drawLine(x+27,y+25,x+27,y+23); a.g.drawLine(x+26,y+22,x+25,y+22); a.g.drawLine(x+23,y+22,x+21,y+22); a.g.drawLine(x+16,y+22,x+14,y+22); a.g.drawLine(x+9,y+22,x+7,y+22); a.g.drawLine(x+5,y+22,x+5,y+22); a.g.drawLine(x+4,y+23,x+4,y+25); a.g.drawLine(x+5,y+24,x+5,y+24); a.g.drawLine(x+6,y+25,x+6,y+25); a.g.drawLine(x+15,y+25,x+15,y+25); a.g.drawLine(x+17,y+25,x+17,y+25); a.g.drawLine(x+19,y+25,x+19,y+25); a.g.drawLine(x+16,y+24,x+19,y+24); a.g.drawLine(x+18,y+23,x+19,y+23); a.g.drawLine(x+21,y+25,x+23,y+25); a.g.drawLine(x+22,y+24,x+22,y+24); END Comp;
PROCEDURE LeftComp(a:PGame; x,y,Switch:INTEGER); BEGIN Comp(a,x,y,Switch); a.g.setColor(a.Col); a.g.fillRect(x+25,y+14,5,5); a.g.setColor(a.Blink); a.g.drawLine(x+25,y+15,x+30,y+15); END LeftComp;
PROCEDURE UpComp(a:PGame; x,y,Switch:INTEGER); BEGIN Comp(a,x,y,Switch); a.g.setColor(a.Col); a.g.fillRect(x+14,y+26,4,5); a.g.setColor(a.Blink); a.g.drawLine(x+15,y+26,x+15,y+30); END UpComp;
PROCEDURE RightComp(a:PGame; x,y,Switch:INTEGER); BEGIN Comp(a,x,y,Switch); a.g.setColor(a.Col); a.g.fillRect(x+1,y+14,5,5); a.g.setColor(a.Blink); a.g.drawLine(x+1,y+15,x+5,y+15); END RightComp;
PROCEDURE DownComp(a:PGame; x,y,Switch:INTEGER); BEGIN Comp(a,x,y,Switch); a.g.setColor(a.Col); a.g.fillRect(x+14,y,4,4); a.g.setColor(a.Blink); a.g.drawLine(x+15,y,x+15,y+4); END DownComp;
PROCEDURE TLeft(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,30); a.g.fillRect(a.w+x*30-5,a.w+y*30-6,16,5); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30+10); a.g.drawLine(a.w+x*30-2,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); END TLeft;
PROCEDURE TUp(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,30,5); a.g.fillRect(a.w+x*30-6,a.w+y*30-5,4,16); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); a.g.drawLine(a.w+x*30-5,a.w+y*30-1,a.w+x*30-5,a.w+y*30+10); END TUp;
PROCEDURE TRight(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,30); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,15,5); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30+10); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30-8,a.w+y*30-5); END TRight;
PROCEDURE TDown(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,30,5); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,16); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30-7); END TDown;
PROCEDURE IUp(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,30); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30+10); END IUp;
PROCEDURE IDown(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,30,5); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); END IDown;
PROCEDURE LLeft(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-6,a.w+y*30-5,4,16); a.g.fillRect(a.w+x*30-5,a.w+y*30-6,16,5); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-5,a.w+y*30-4,a.w+x*30-5,a.w+y*30+10); a.g.drawLine(a.w+x*30-4,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); END LLeft;
PROCEDURE LUp(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,16,5); a.g.fillRect(a.w+x*30-6,a.w+y*30-5,4,16); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30-6,a.w+y*30-5); a.g.drawLine(a.w+x*30-5,a.w+y*30-4,a.w+x*30-5,a.w+y*30+10); END LUp;
PROCEDURE LRight(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,17); a.g.fillRect(a.w+x*30-19,a.w+y*30-6,16,5); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30-6); a.g.drawLine(a.w+x*30-19,a.w+y*30-5,a.w+x*30-6,a.w+y*30-5); END LRight;
PROCEDURE LDown(a:PGame; x,y:INTEGER); BEGIN a.g.setColor(a.Col); a.g.fillRect(a.w+x*30-5,a.w+y*30-6,16,5); a.g.fillRect(a.w+x*30-6,a.w+y*30-19,4,17); a.g.setColor(a.Blink); a.g.drawLine(a.w+x*30-4,a.w+y*30-5,a.w+x*30+10,a.w+y*30-5); a.g.drawLine(a.w+x*30-5,a.w+y*30-19,a.w+x*30-5,a.w+y*30-6); END LDown;
PROCEDURE Field(a:PGame; x,y:INTEGER); CONST k=19; l=9; BEGIN a.g.setColor(a.Back); a.g.fillRect(a.w+x*30-k,a.w+y*30-k,30,30); a.g.setColor(awc.white); a.g.drawLine(a.w+x*30-k,a.w+y*30-k,a.w+x*30-k,a.w+y*30+l); a.g.drawLine(a.w+x*30-k,a.w+y*30-k,a.w+x*30+l,a.w+y*30-k); a.g.setColor(awc.black); a.g.drawLine(a.w+x*30+l+1,a.w+y*30-k+1,a.w+x*30+l+1,a.w+y*30+l); a.g.drawLine(a.w+x*30-k+1,a.w+y*30+l+1,a.w+x*30+l,a.w+y*30+l+1); END Field;
PROCEDURE ShowElement(a:PGame; i,j,S:INTEGER); BEGIN Field(a,i,j); IF (i=a.SPos) & (j=a.SPos) THEN Field(a,a.SPos,a.SPos-1); Server(a,S); ELSIF (i=a.SPos) & (j=a.SPos-1) THEN Field(a,a.SPos,a.SPos); Server(a,S); END; CASE a.t[i,j] OF | 1: TLeft(a,i,j); | 2: TUp(a,i,j); | 3: TRight(a,i,j); | 4: TDown(a,i,j); | 5: IUp(a,i,j); | 6: IDown(a,i,j); | 7: LLeft(a,i,j); | 8: LUp(a,i,j); | 9: LRight(a,i,j); | 10: LDown(a,i,j); | 11: LeftComp(a,a.w+i*30-20,a.w+j*30-20,S); | 12: UpComp(a,a.w+i*30-20,a.w+j*30-20,S); | 13: RightComp(a,a.w+i*30-20,a.w+j*30-20,S); | 14: DownComp(a,a.w+i*30-20,a.w+j*30-20,S); ELSE END; END ShowElement;
PROCEDURE ShowNet(a:PGame; S:INTEGER); VAR i,j:INTEGER; BEGIN FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO ShowElement(a,i,j,S); END; END; END ShowNet;
PROCEDURE Empty(a:PGame):BOOLEAN; VAR i,j:INTEGER; Emp:BOOLEAN; BEGIN Emp:=FALSE; FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO IF ((a.t[i,j]=70) OR (a.t[i,j]=80) OR (a.t[i,j]=90) OR (a.t[i,j]=100)) THEN RETURN TRUE; END; END; END; RETURN Emp; END Empty;
PROCEDURE Rotate(a:PGame; x,y:INTEGER); BEGIN IF (x=a.SPos) & (y=a.SPos-1) THEN y:=a.SPos; END; IF (a.t[x,y]#0) & (a.t[x,y]#20) THEN a.t[x,y]:=a.t[x,y]+1; CASE a.t[x,y] OF | 5: a.t[x,y]:=1; | 7: a.t[x,y]:=5; | 11: a.t[x,y]:=7; | 15: a.t[x,y]:=11; | 205: a.t[a.SPos,a.SPos]:=201; | 207: a.t[a.SPos,a.SPos]:=205; | 211: a.t[a.SPos,a.SPos]:=207; ELSE END; END; END Rotate;
PROCEDURE Change(a:PGame); VAR i,j,Move,k:INTEGER; BEGIN FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO IF (a.t[i,j]#20) THEN Move:=Rnd(a.rand,4)+1; FOR k:=1 TO Move DO Rotate(a,i,j); END; END; END; END; END Change;
PROCEDURE ArrayEqu(a:PGame):BOOLEAN; VAR i,j:INTEGER; BEGIN FOR i:=1 TO a.n DO FOR j:=1 TO a.n DO IF (a.t[i,j]#a.p[i,j]) THEN RETURN FALSE; END; END; END; RETURN TRUE; END ArrayEqu;
PROCEDURE (a:PGame) paint*(g:awt.PGraphics); VAR I:lang.PInteger; BEGIN IF (ArrayEqu(a)) THEN ShowNet(a,On); ELSE ShowNet(a,Off); END; a.g.setColor(awc.yellow); a.g.drawString(Str("LEVEL"),239,366); a.g.setColor(awc.black); a.g.fillRect(245,375,20,15); a.g.setColor(awc.white); SYSTEM.NEW(I,a.Level); a.g.drawString(I.toString(),252,385); END paint;
PROCEDURE BeginGame(a:PGame); BEGIN a.w:=15*(11-a.n); CASE a.n OF | 5: a.SPos:=3; a.m:=6; | 7: a.SPos:=4; a.m:=12; | 9: a.SPos:=5; a.m:=21; | 11: a.SPos:=6; a.m:=30; ELSE END; REPEAT MakeNet(a); UNTIL (~Empty(a) & (CountTerm(a)>=a.m)); a.p:=a.t; Change(a); a.paint(a.g); END BeginGame;
PROCEDURE (a:PGame) init*(); VAR i,j:INTEGER; I:awt.PComponent; BEGIN NEW(a.rand); a.n:=11; a.Level:=4; a.setLayout(NIL); SYSTEM.NEW(a.NewGame, Str("New Game")); a.NewGame.reshape(30,357,80,30); I:=a.add(a.NewGame); SYSTEM.NEW(a.Plus, Str("+")); a.Plus.reshape(190,357,30,30); I:=a.add(a.Plus); SYSTEM.NEW(a.Minus, Str("--")); a.Minus.reshape(290,357,30,30); I:=a.add(a.Minus); a.setBackground(awc.black); SYSTEM.NEW(a.Back,LONG(120),LONG(180),LONG(30)); a.Col:=awc.black; a.Blink:=awc.lightGray; a.g:=a.getGraphics(); BeginGame(a); END init;
PROCEDURE (a:PGame) mouseDown*(evt:awt.PEvent; x,y:INTEGER):BOOLEAN; BEGIN IF (x>10+a.w) & (x<340-a.w) & (y>10+a.w) & (y<340-a.w) & ~(ArrayEqu(a)) THEN a.MouseX:=((x-a.w)+19) DIV 30; a.MouseY:=((y-a.w)+19) DIV 30; Rotate(a,a.MouseX,a.MouseY); ShowElement(a,a.MouseX,a.MouseY,Off); IF (ArrayEqu(a)) THEN ShowNet(a,On); END; END; RETURN TRUE; END mouseDown;
PROCEDURE (a:PGame) action*(Evt:awt.PEvent; obj:lang.PObject):BOOLEAN; VAR I:lang.PInteger; BEGIN IF (Evt.target IS awt.PButton) THEN IF (obj.equals(Str("New Game"))) THEN BeginGame(a); ELSIF (obj.equals(Str("+"))) THEN IF (a.n#11) THEN a.n:=a.n+2; a.Level:=a.Level+1; a.g.setColor(awc.black); a.g.fillRect(245,375,20,15); a.g.setColor(awc.white); SYSTEM.NEW(I,a.Level); a.g.drawString(I.toString(),252,385); BeginGame(a); END; ELSIF (obj.equals(Str("--"))) THEN IF (a.n#5) THEN a.g.setColor(awc.black); a.g.fillRect(a.w+9,a.w+9,30*a.n+3,30*a.n+3); a.Level:=a.Level-1; a.g.setColor(awc.black); a.g.fillRect(245,375,20,15); a.g.setColor(awc.white); SYSTEM.NEW(I,a.Level); a.g.drawString(I.toString(),252,385); a.n:=a.n-2; BeginGame(a); END; END; RETURN TRUE; END; RETURN FALSE; END action;
END net.