home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume4
/
rubik.shr
/
cube.pas
Wrap
Pascal/Delphi Source File
|
1988-05-20
|
26KB
|
879 lines
[INHERIT ('SYS$LIBRARY:STARLET.PEN')]
(* Rubik's cube simulator for VAX/VMS and ReGIS graphics *)
(* by Bud Crittendon *)
PROGRAM CUBE(INPUT,OUTPUT,OUTFILE);
Const
CubeSize = 35;
CubeSep = CubeSize + 6;
CubeCornerX = 200;
CubeCornerY = 200;
TiltAngle = 0.5235987;
ColorRed = 1;
ColorBlue = 2;
ColorYellow = 3;
TYPE
Iword = [WORD] 0..65535;
ShortString = PACKED ARRAY [1..12] OF CHAR;
Rotate = (NONE,LEFT,RIGHT,UP,DOWN,FRONT,BACK);
Where = (TILTFRONT,TILTTOP,TILTRIGHT,TILTLEFT,TILTDOWN,TILTBACK);
Colors = (YELLOW,WHITE,BLUE,GREEN,RED,ORANGE);
CUBITS = PACKED ARRAY [1..9] OF COLORS;
CUBES = PACKED ARRAY [LEFT..BACK] OF CUBITS;
VAR
X,
Y,
L,
C1,
C2,
CUBESEPX,
CUBESEPY,
CUBEADJX,
CUBEADJY,
SCORE,
MIXES,
MOVES,
CUBEADJUST,
DIR,
I:INTEGER;
QUIT,
DONE:BOOLEAN;
CUBEARRAY:CUBES;
CCOLOR,
COLOR:COLORS;
CTYPE,
CUBEPLACE:WHERE;
TURN:ROTATE;
KEY:CHAR;
IOCHAN:IWORD;
OUTFILE:TEXT;
(******************************************************************************)
[INITIALIZE]
PROCEDURE InitializeCubeParams;
BEGIN
WRITELN(CHR(27),'P1p');
WRITELN('S(M0(AD)M1(AR)M2(AB)M3(AY))');
WRITELN('l(a2)"A"55aa55aa55aa55aa55aa;');
WRITELN(CHR(27),'\');
FOR I := 1 TO 9 DO BEGIN
CUBEARRAY[RIGHT][I] := YELLOW;
CUBEARRAY[LEFT][I] := WHITE;
CUBEARRAY[UP][I] := BLUE;
CUBEARRAY[DOWN][I] := GREEN;
CUBEARRAY[FRONT][I] := RED;
CUBEARRAY[BACK][I] := ORANGE;
END;
DONE := FALSE;
QUIT := FALSE;
MOVES := 0;
MIXES := 0;
SCORE := 0;
CubeAdjX := round(CubeSize * cos(TiltAngle));
CubeAdjY := round(CubeSize * sin(TiltAngle));
CubeSepX := round(CubeSep * cos(TiltAngle));
CubeSepY := round(CubeSep * sin(TiltAngle));
END;
(******************************************************************************)
PROCEDURE Initialize(VAR CUBEARRAY:CUBES;VAR MIXES,MOVES,SCORE:INTEGER);
BEGIN
FOR I := 1 TO 9 DO BEGIN
CUBEARRAY[RIGHT][I] := YELLOW;
CUBEARRAY[LEFT][I] := WHITE;
CUBEARRAY[UP][I] := BLUE;
CUBEARRAY[DOWN][I] := GREEN;
CUBEARRAY[FRONT][I] := RED;
CUBEARRAY[BACK][I] := ORANGE;
END;
MOVES := 0;
MIXES := 0;
SCORE := 0;
END;
(******************************************************************************)
PROCEDURE REGIS;
BEGIN
WRITELN(CHR(27),'Pp');
END;
(******************************************************************************)
PROCEDURE ASCII;
BEGIN
WRITELN(CHR(27),'[;H');
WRITELN(CHR(27),'\');
END;
(******************************************************************************)
PROCEDURE POSITION(ROW,COL:INTEGER);
BEGIN
WRITELN('P[',COL:1,',',ROW:1,']');
END;
(******************************************************************************)
PROCEDURE RANDOMNUMBER(VAR RANDOM:INTEGER;MINVALUE,MAXVALUE:INTEGER);
TYPE
STRING = PACKED ARRAY [1..11] OF CHAR;
VAR
CURTIME : STRING;
SEED : INTEGER;
BEGIN
CURTIME := '00:00:00.00';
TIME(CURTIME);
RANDOM := 0;
SEED := 0;
SEED := SEED + 1 * (ORD(CURTIME[10])-48);
SEED := SEED + 10 * (ORD(CURTIME[11])-48);
RANDOM := ROUND((SEED/99) * (MAXVALUE - MINVALUE)) + MINVALUE;
END;
(******************************************************************************)
PROCEDURE Coords ( VAR CubeNumber: integer; VAR CubeType: Where);
VAR bx,by,ccx,ccy:integer;
BEGIN
bx := (CubeNumber-1) MOD 3;
by := (CubeNumber-1) DIV 3;
CASE CubeType OF
TILTFRONT,
TILTRIGHT,
TILTTOP: BEGIN
ccx := CubeCornerX;
ccy := CubeCornerY;
END;
TILTBACK: BEGIN
ccx := CubeCornerX + CubeSepX*7;
ccy := CubeCornerY - CubeSepy*7;
END;
TILTLEFT: BEGIN
ccx := CubeCornerX - CubeSepX*7;
ccy := CubeCornerY;
END;
TILTDOWN: BEGIN
ccx := CubeCornerX;
ccy := CubeCornerY + CubeSepY*10;
END;
OTHERWISE;
END;
CASE CubeType OF
TILTFRONT,TILTBACK:
BEGIN
x := ccx + bx * CubeSep ;
y := ccy + by * CubeSep ;
END;
TILTRIGHT,TILTLEFT:
BEGIN
x := ccx + (CubeSep * 3) + (bx * CubeSepX);
y := ccy + (CubeSep * by) - (bx * CubeSepY);
END;
TILTTOP,TILTDOWN:
BEGIN
x := ccx + (CubeSepX *3) + (bx*CubeSep) - (by*CubeSepX);
y := ccy - (CubeSepY *3) + (by*CubeSepY);
END;
END;
END;
(******************************************************************************)
PROCEDURE SetColor(VAR Color: Colors);
BEGIN
CASE Color OF
RED : BEGIN
c1 := ColorRed;
c2 := ColorRed;
END;
YELLOW:
BEGIN
c1 := ColorYellow;
c2 := ColorYellow;
END;
BLUE:
BEGIN
c1 := ColorBlue;
c2 := ColorBlue;
END;
ORANGE:
BEGIN
c1 := ColorRed;
c2 := ColorYellow;
END;
WHITE:
BEGIN
c1 := ColorBlue;
c2 := ColorYellow;
END;
GREEN:
BEGIN
c1 := ColorBlue;
c2 := ColorRed;
END;
END;
END;
(******************************************************************************)
PROCEDURE SetFill(VAR CubeType: Where);
VAR solid : boolean;
BEGIN
solid := (c1 = c2);
Write('w(r,i',c1:1,',s');
IF solid
THEN
BEGIN
CASE CubeType OF
TILTBACK,TILTLEFT,TILTFRONT,TILTRIGHT: Writeln('1)');
TILTDOWN,TILTTOP: Writeln('1(x))');
END;
END
ELSE
BEGIN
CASE CubeType OF
TILTBACK,TILTLEFT,TILTFRONT,TILTRIGHT: Writeln('"A")s(i',c2:1,')');
TILTDOWN,TILTTOP: Writeln('"A"(x))s(i',c2:1,')');
END;
END;
END;
(******************************************************************************)
PROCEDURE Square (CubeNumber: integer;
CubeType: Where; Color: Colors);
BEGIN
Coords(CubeNumber,CubeType); (* Compute X,Y *)
Writeln('p[',x,',',y,']t(a2)'); (* Place cursor at x,y *)
SetColor(Color); (* Select c1 and c2 *)
CASE CubeType OF
TILTFRONT,TILTBACK:
BEGIN
SetFill(CubeType);
Writeln('v[,+',cubesize,'][+',cubesize,']');
END;
TILTRIGHT,TILTLEFT:
BEGIN
SetFill(CubeType);
Writeln('v[,+',cubesize,'][+',CubeAdjX,
',-',CubeAdjY,']');
Writeln('v[,-',cubesize,'][-',CubeAdjX,
',+',CubeAdjY,']')
END;
TILTTOP,TILTDOWN:
BEGIN
SetFill(CubeType);
Writeln('v[-',CubeAdjX,',+',CubeAdjY,
'][+',Cubesize,']');
Writeln('v[+',CubeAdjX,',-',CubeadjY,']');
END;
END;
Writeln('w(s0)s(i0)t(a0)');
END;
(******************************************************************************)
PROCEDURE OPENKEY;
VAR
STAT : IWORD;
DEVNAME: SHORTSTRING;
BEGIN
DEVNAME := 'TT:';
STAT := $ASSIGN(DEVNAME,IOCHAN);
END;
(******************************************************************************)
PROCEDURE SHUTKEY;
VAR
STAT : IWORD;
BEGIN
STAT := $DASSGN(IOCHAN);
END;
(******************************************************************************)
FUNCTION GETKEY:CHAR;
VAR
FUNC,STAT : IWORD;
CH : CHAR;
BEGIN
FUNC := IO$_READVBLK + IO$M_NOECHO + IO$M_NOFILTR;
STAT := $QIOW (,IOCHAN,FUNC,,,,CH,1);
GETKEY := CH;
END;
(******************************************************************************)
PROCEDURE SIDES(TURN:ROTATE);
BEGIN
CASE TURN OF
FRONT : FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTFRONT,CUBEARRAY[FRONT][I]);
SQUARE(I+3,TILTFRONT,CUBEARRAY[FRONT][I+3]);
SQUARE(I+6,TILTFRONT,CUBEARRAY[FRONT][I+6]);
SQUARE((I+6),TILTTOP,CUBEARRAY[UP][I+6]);
SQUARE(((I*3)-2),TILTRIGHT,CUBEARRAY[RIGHT][((I*3)-2)]);
SQUARE((I+6),TILTDOWN,CUBEARRAY[DOWN][I]);
SQUARE(((I*3)-2),TILTLEFT,CUBEARRAY[LEFT][(I*3)]);
END;
RIGHT : FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTRIGHT,CUBEARRAY[RIGHT][I]);
SQUARE(I+3,TILTRIGHT,CUBEARRAY[RIGHT][I+3]);
SQUARE(I+6,TILTRIGHT,CUBEARRAY[RIGHT][I+6]);
SQUARE((I*3),TILTTOP,CUBEARRAY[UP][I*3]);
SQUARE((I*3),TILTFRONT,CUBEARRAY[FRONT][(I*3)]);
SQUARE((I*3),TILTDOWN,CUBEARRAY[DOWN][((4-I)*3)]);
SQUARE((I*3),TILTBACK,CUBEARRAY[BACK][((I*3)-2)]);
END;
UP : FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTTOP,CUBEARRAY[UP][I]);
SQUARE(I+3,TILTTOP,CUBEARRAY[UP][I+3]);
SQUARE(I+6,TILTTOP,CUBEARRAY[UP][I+6]);
SQUARE(I,TILTFRONT,CUBEARRAY[FRONT][I]);
SQUARE(I,TILTRIGHT,CUBEARRAY[RIGHT][I]);
SQUARE(I,TILTLEFT,CUBEARRAY[LEFT][(4-I)]);
SQUARE(I,TILTBACK,CUBEARRAY[BACK][(4-I)]);
END;
BACK : FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTBACK,CUBEARRAY[BACK][(4-I)]);
SQUARE(I+3,TILTBACK,CUBEARRAY[BACK][(4-I)+3]);
SQUARE(I+6,TILTBACK,CUBEARRAY[BACK][(4-I)+6]);
SQUARE(I,TILTTOP,CUBEARRAY[UP][I]);
SQUARE((I*3),TILTRIGHT,CUBEARRAY[RIGHT][(I*3)]);
SQUARE((I*3),TILTLEFT,CUBEARRAY[LEFT][((I*3)-2)]);
SQUARE(I,TILTDOWN,CUBEARRAY[DOWN][(I+6)]);
END;
LEFT : FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTLEFT,CUBEARRAY[LEFT][(4-I)]);
SQUARE(I+3,TILTLEFT,CUBEARRAY[LEFT][(4-I)+3]);
SQUARE(I+6,TILTLEFT,CUBEARRAY[LEFT][(4-I)+6]);
SQUARE(((I*3)-2),TILTTOP,CUBEARRAY[UP][((I*3)-2)]);
SQUARE(((I*3)-2),TILTFRONT,CUBEARRAY[FRONT][((I*3)-2)]);
SQUARE(((I*3)-2),TILTBACK,CUBEARRAY[BACK][(I*3)]);
SQUARE(((I*3)-2),TILTDOWN,CUBEARRAY[DOWN][(((4-I)*3)-2)]);
END;
DOWN : FOR I := 1 TO 3 DO BEGIN
SQUARE(I+6,TILTDOWN,CUBEARRAY[DOWN][I]);
SQUARE(I+3,TILTDOWN,CUBEARRAY[DOWN][I+3]);
SQUARE(I,TILTDOWN,CUBEARRAY[DOWN][(I+6)]);
SQUARE((I+6),TILTFRONT,CUBEARRAY[FRONT][(I+6)]);
SQUARE((I+6),TILTRIGHT,CUBEARRAY[RIGHT][(I+6)]);
SQUARE((I+6),TILTBACK,CUBEARRAY[BACK][((4-I)+6)]);
SQUARE((I+6),TILTLEFT,CUBEARRAY[LEFT][((4-I)+6)]);
END;
END;
END;
(******************************************************************************)
PROCEDURE TURNSIDE(TURN:ROTATE;DIR:INTEGER);
VAR
NUMBER:INTEGER;
TEMP:COLORS;
BEGIN
FOR NUMBER := 1 TO DIR DO BEGIN
TEMP := CUBEARRAY[TURN][1];
CUBEARRAY[TURN][1] := CUBEARRAY[TURN][7];
CUBEARRAY[TURN][7] := CUBEARRAY[TURN][9];
CUBEARRAY[TURN][9] := CUBEARRAY[TURN][3];
CUBEARRAY[TURN][3] := TEMP;
TEMP := CUBEARRAY[TURN][2];
CUBEARRAY[TURN][2] := CUBEARRAY[TURN][4];
CUBEARRAY[TURN][4] := CUBEARRAY[TURN][8];
CUBEARRAY[TURN][8] := CUBEARRAY[TURN][6];
CUBEARRAY[TURN][6] := TEMP;
END;
END;
(******************************************************************************)
PROCEDURE CHANGEARRAY(VAR CUBEARRAY:CUBES;TURN:ROTATE;DIR:INTEGER);
VAR
TEMPARRAY : PACKED ARRAY [1..3] OF COLORS;
TEMP:COLORS;
J,
X,
Y:INTEGER;
BEGIN
TURNSIDE(TURN,DIR);
FOR X := 1 TO DIR DO BEGIN
IF (TURN = UP) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[FRONT][J];
CUBEARRAY[FRONT][J] := CUBEARRAY[RIGHT][J];
CUBEARRAY[RIGHT][J] := CUBEARRAY[BACK][J];
CUBEARRAY[BACK][J] := CUBEARRAY[LEFT][J];
CUBEARRAY[LEFT][J] := TEMP;
END;
IF (TURN = DOWN) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[FRONT][J+6];
CUBEARRAY[FRONT][J+6] := CUBEARRAY[LEFT][J+6];
CUBEARRAY[LEFT][J+6] := CUBEARRAY[BACK][J+6];
CUBEARRAY[BACK][J+6] := CUBEARRAY[RIGHT][J+6];
CUBEARRAY[RIGHT][J+6] := TEMP;
END;
IF (TURN = RIGHT) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[FRONT][(4-J)*3];
CUBEARRAY[FRONT][(4-J)*3] := CUBEARRAY[DOWN][(4-J)*3];
CUBEARRAY[DOWN][(4-J)*3] := CUBEARRAY[BACK][(J*3)-2];
CUBEARRAY[BACK][(J*3)-2] := CUBEARRAY[UP][(4-J)*3];
CUBEARRAY[UP][(4-J)*3] := TEMP;
END;
IF (TURN = LEFT) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[FRONT][(J*3)-2];
CUBEARRAY[FRONT][(J*3)-2] := CUBEARRAY[UP][(J*3)-2];
CUBEARRAY[UP][(J*3)-2] := CUBEARRAY[BACK][(4-J)*3];
CUBEARRAY[BACK][(4-J)*3] := CUBEARRAY[DOWN][(J*3)-2];
CUBEARRAY[DOWN][(J*3)-2] := TEMP;
END;
IF (TURN = FRONT) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[UP][J+6];
CUBEARRAY[UP][J+6] := CUBEARRAY[LEFT][(4-J)*3];
CUBEARRAY[LEFT][(4-J)*3] := CUBEARRAY[DOWN][(4-J)];
CUBEARRAY[DOWN][(4-J)] := CUBEARRAY[RIGHT][(J*3)-2];
CUBEARRAY[RIGHT][(J*3)-2] := TEMP
END;
IF (TURN = BACK) THEN
FOR J := 1 TO 3 DO BEGIN
TEMP := CUBEARRAY[UP][4-J];
CUBEARRAY[UP][4-J] := CUBEARRAY[RIGHT][(4-J)*3];
CUBEARRAY[RIGHT][(4-J)*3] := CUBEARRAY[DOWN][J+6];
CUBEARRAY[DOWN][J+6] := CUBEARRAY[LEFT][(J*3)-2];
CUBEARRAY[LEFT][(J*3)-2] := TEMP
END;
END;
END;
(******************************************************************************)
PROCEDURE DRAWCUBE;
VAR
I : INTEGER;
BEGIN
FOR I := 1 TO 3 DO BEGIN
SQUARE(I,TILTTOP,CUBEARRAY[UP][I]);
SQUARE(I+3,TILTTOP,CUBEARRAY[UP][I+3]);
SQUARE(I+6,TILTTOP,CUBEARRAY[UP][I+6]);
SQUARE(I,TILTFRONT,CUBEARRAY[FRONT][I]);
SQUARE(I+3,TILTFRONT,CUBEARRAY[FRONT][I+3]);
SQUARE(I+6,TILTFRONT,CUBEARRAY[FRONT][I+6]);
SQUARE(I,TILTRIGHT,CUBEARRAY[RIGHT][I]);
SQUARE(I+3,TILTRIGHT,CUBEARRAY[RIGHT][I+3]);
SQUARE(I+6,TILTRIGHT,CUBEARRAY[RIGHT][I+6]);
SQUARE(I,TILTBACK,CUBEARRAY[BACK][(4-I)]);
SQUARE(I+3,TILTBACK,CUBEARRAY[BACK][(4-I)+3]);
SQUARE(I+6,TILTBACK,CUBEARRAY[BACK][(4-I)+6]);
SQUARE(I,TILTLEFT,CUBEARRAY[LEFT][(4-I)]);
SQUARE(I+3,TILTLEFT,CUBEARRAY[LEFT][(4-I)+3]);
SQUARE(I+6,TILTLEFT,CUBEARRAY[LEFT][(4-I)+6]);
SQUARE(I,TILTDOWN,CUBEARRAY[DOWN][I+6]);
SQUARE(I+3,TILTDOWN,CUBEARRAY[DOWN][I+3]);
SQUARE(I+6,TILTDOWN,CUBEARRAY[DOWN][I]);
END;
END;
(******************************************************************************)
PROCEDURE TURNCUBE(VAR CUBEARRAY:CUBES;TURN:ROTATE);
VAR
TEMPARRAY : PACKED ARRAY [1..9] OF COLORS;
J:INTEGER;
BEGIN
CASE TURN OF
UP : BEGIN
TURNSIDE(RIGHT,1);
TURNSIDE(LEFT,3);
FOR J := 1 TO 9 DO BEGIN
TEMPARRAY[J] := CUBEARRAY[UP][J];
CUBEARRAY[UP][J] := CUBEARRAY[FRONT][J];
CUBEARRAY[FRONT][J] := CUBEARRAY[DOWN][J];
CUBEARRAY[DOWN][J] := CUBEARRAY[BACK][10-J];
CUBEARRAY[BACK][10-J] := TEMPARRAY[J];
END;
END;
DOWN : BEGIN
TURNSIDE(RIGHT,3);
TURNSIDE(LEFT,1);
FOR J := 1 TO 9 DO BEGIN
TEMPARRAY[J] := CUBEARRAY[UP][J];
CUBEARRAY[UP][J] := CUBEARRAY[BACK][10-J];
CUBEARRAY[BACK][10-J] := CUBEARRAY[DOWN][J];
CUBEARRAY[DOWN][J] := CUBEARRAY[FRONT][J];
CUBEARRAY[FRONT][J] := TEMPARRAY[J];
END;
END;
RIGHT : BEGIN
TURNSIDE(UP,3);
TURNSIDE(DOWN,1);
FOR J := 1 TO 9 DO BEGIN
TEMPARRAY[J] := CUBEARRAY[FRONT][J];
CUBEARRAY[FRONT][J] := CUBEARRAY[LEFT][J];
CUBEARRAY[LEFT][J] := CUBEARRAY[BACK][J];
CUBEARRAY[BACK][J] := CUBEARRAY[RIGHT][J];
CUBEARRAY[RIGHT][J] := TEMPARRAY[J];
END;
END;
LEFT : BEGIN
TURNSIDE(UP,1);
TURNSIDE(DOWN,3);
FOR J := 1 TO 9 DO BEGIN
TEMPARRAY[J] := CUBEARRAY[FRONT][J];
CUBEARRAY[FRONT][J] := CUBEARRAY[RIGHT][J];
CUBEARRAY[RIGHT][J] := CUBEARRAY[BACK][J];
CUBEARRAY[BACK][J] := CUBEARRAY[LEFT][J];
CUBEARRAY[LEFT][J] := TEMPARRAY[J];
END;
END;
END;
DRAWCUBE;
END;
(******************************************************************************)
PROCEDURE LOADCUBE(VAR CUBEARRAY:CUBES;VAR MOVES,MIXES:INTEGER);
BEGIN
OPEN (FILE_NAME := 'SYS$LOGIN:CUBE.DAT',
FILE_VARIABLE := OUTFILE,
HISTORY := OLD,
ACCESS_METHOD := SEQUENTIAL);
RESET(OUTFILE);
FOR I := 1 TO 9 DO BEGIN
READLN(OUTFILE,CUBEARRAY[RIGHT][I]);
READLN(OUTFILE,CUBEARRAY[LEFT][I]);
READLN(OUTFILE,CUBEARRAY[UP][I]);
READLN(OUTFILE,CUBEARRAY[DOWN][I]);
READLN(OUTFILE,CUBEARRAY[FRONT][I]);
READLN(OUTFILE,CUBEARRAY[BACK][I]);
END;
READLN(OUTFILE,MOVES,MIXES);
CLOSE(OUTFILE);
END;
(******************************************************************************)
PROCEDURE SAVECUBE;
BEGIN
OPEN (FILE_NAME := 'SYS$LOGIN:CUBE.DAT',
FILE_VARIABLE := OUTFILE,
HISTORY := NEW,
ACCESS_METHOD := SEQUENTIAL);
REWRITE(OUTFILE);
FOR I := 1 TO 9 DO BEGIN
WRITELN(OUTFILE,CUBEARRAY[RIGHT][I]);
WRITELN(OUTFILE,CUBEARRAY[LEFT][I]);
WRITELN(OUTFILE,CUBEARRAY[UP][I]);
WRITELN(OUTFILE,CUBEARRAY[DOWN][I]);
WRITELN(OUTFILE,CUBEARRAY[FRONT][I]);
WRITELN(OUTFILE,CUBEARRAY[BACK][I]);
END;
WRITELN(OUTFILE,MOVES,MIXES);
CLOSE(OUTFILE);
END;
(******************************************************************************)
PROCEDURE WRITEMOVES(MOVES:INTEGER);
BEGIN
POSITION(50,50);
WRITELN('T''Moves : ',MOVES:1,' '' ');
END;
(******************************************************************************)
PROCEDURE WRITEMIXES(MIXES:INTEGER);
BEGIN
POSITION(70,50);
WRITELN('T''Mixes : ',MIXES:1,' '' ');
END;
(******************************************************************************)
PROCEDURE DRAWSCREEN;
BEGIN
REGIS;
Writeln('s(m0(ad)m1(ar)m2(ab)m3(ay))');
WRITELN('S(C0)');
WRITELN('S(E)');
POSITION(50,600);
WRITELN('T''Side to move : '' ');
POSITION(70,620);
WRITELN('T''U = Up'' ');
POSITION(90,620);
WRITELN('T''D = Down'' ');
POSITION(110,620);
WRITELN('T''R = Right'' ');
POSITION(130,620);
WRITELN('T''L = Left'' ');
POSITION(150,620);
WRITELN('T''F = Front'' ');
POSITION(170,620);
WRITELN('T''B = Back'' ');
POSITION(200,600);
WRITELN('T''Direction : '' ');
POSITION(220,620);
WRITELN('T''+ = + 90 Degrees'' ');
POSITION(240,620);
WRITELN('T''- = - 90 Degrees'' ');
POSITION(260,620);
WRITELN('T''2 = 180 Degrees'' ');
POSITION(290,600);
WRITELN('T''Other Commands : '' ');
POSITION(310,620);
WRITELN('T''CTRL-F = Fix Cube'' ');
POSITION(330,620);
WRITELN('T''CTRL-J = Jumble Cube'' ');
POSITION(350,620);
WRITELN('T''CTRL-L = Load Game'' ');
POSITION(370,620);
WRITELN('T''CTRL-H = Save Game'' ');
POSITION(390,620);
WRITELN('T''CTRL-W = Screen Refresh'' ');
POSITION(410,620);
WRITELN('T''CTRL-Z = Quit Game'' ');
POSITION(430,620);
WRITELN('T''Arrow Keys = Rotate'' ');
WRITEMIXES(MIXES);
WRITEMOVES(MOVES);
DRAWCUBE;
END;
(******************************************************************************)
PROCEDURE CHECKCUBE(VAR DONE:BOOLEAN);
VAR
I:INTEGER;
BEGIN
DONE := TRUE;
FOR I := 1 TO 9 DO BEGIN
IF (CUBEARRAY[UP][I] <> CUBEARRAY[UP][5]) THEN DONE := FALSE;
IF (CUBEARRAY[DOWN][I] <> CUBEARRAY[DOWN][5]) THEN DONE := FALSE;
IF (CUBEARRAY[RIGHT][I] <> CUBEARRAY[RIGHT][5]) THEN DONE := FALSE;
IF (CUBEARRAY[LEFT][I] <> CUBEARRAY[LEFT][5]) THEN DONE := FALSE;
IF (CUBEARRAY[FRONT][I] <> CUBEARRAY[FRONT][5]) THEN DONE := FALSE;
IF (CUBEARRAY[BACK][I] <> CUBEARRAY[BACK][5]) THEN DONE := FALSE;
END;
END;
(******************************************************************************)
PROCEDURE ESCAPE(VAR KEY:CHAR);
VAR
KEY2,
KEY3:CHAR;
BEGIN
KEY2 := ' ';
KEY3 := ' ';
KEY2 := GETKEY;
IF (KEY2 = CHR(63)) OR (KEY2 = CHR(79)) THEN
BEGIN
KEY3 := GETKEY;
CASE KEY3 OF
CHR(108) : KEY := ',';
CHR(109) : KEY := '-';
CHR(112) : KEY := '0';
CHR(113) : KEY := '1';
CHR(114) : KEY := '2';
CHR(115) : KEY := '3';
CHR(116) : KEY := '4';
CHR(117) : KEY := '5';
CHR(118) : KEY := '6';
CHR(119) : KEY := '7';
CHR(120) : KEY := '8';
CHR(121) : KEY := '9';
END;
END;
IF (KEY2 = CHR(91)) THEN BEGIN
KEY3 := GETKEY;
CASE KEY3 OF
CHR(65) : TURNCUBE(CUBEARRAY,UP);
CHR(66) : TURNCUBE(CUBEARRAY,DOWN);
CHR(67) : TURNCUBE(CUBEARRAY,RIGHT);
CHR(68) : TURNCUBE(CUBEARRAY,LEFT);
END;
END;
END;
(******************************************************************************)
PROCEDURE MESSCUBE(VAR CUBEARRAY:CUBES);
VAR
DONE:BOOLEAN;
TEMP,
RANDOM2,
RANDOM3:INTEGER;
RANDOMTURN:ROTATE;
BEGIN
FOR I := 1 TO 40 DO BEGIN
DONE := FALSE;
REPEAT
RANDOMNUMBER(RANDOM2,1,6);
CASE RANDOM2 OF
1 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 2) THEN
RANDOMTURN := FRONT;
DONE := TRUE;
END;
2 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 1) THEN
RANDOMTURN := BACK;
DONE := TRUE;
END;
3 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 4) THEN
RANDOMTURN := LEFT;
DONE := TRUE;
END;
4 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 3) THEN
RANDOMTURN := RIGHT;
DONE := TRUE;
END;
5 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 6) THEN
RANDOMTURN := UP;
DONE := TRUE;
END;
6 : BEGIN
IF (RANDOM2 <> TEMP) AND (TEMP <> 5) THEN
RANDOMTURN := DOWN;
DONE := TRUE;
END;
END
UNTIL DONE;
RANDOMNUMBER(RANDOM3,1,2);
IF RANDOM3 = 2 THEN
RANDOM3 := 3;
CHANGEARRAY(CUBEARRAY,RANDOMTURN,RANDOM3);
TEMP := RANDOM2;
END;
END;
(******************************************************************************)
PROCEDURE TYPED(VAR TURN:ROTATE;VAR DIR:INTEGER;VAR DONE:BOOLEAN;VAR
MOVES:INTEGER);
BEGIN
TURN := NONE;
REPEAT
KEY := GETKEY;
IF (KEY = CHR(27)) THEN ESCAPE(KEY);
CASE KEY OF
CHR(6) : BEGIN
TURN := NONE;
INITIALIZE(CUBEARRAY,MIXES,MOVES,SCORE);
DRAWCUBE;
END;
CHR(10) : BEGIN
MESSCUBE(CUBEARRAY);
MESSCUBE(CUBEARRAY);
MIXES := MIXES +1;
DRAWCUBE;
WRITEMIXES(MIXES);
TURN := NONE;
END;
CHR(8) : BEGIN
SAVECUBE;
END;
CHR(12) : BEGIN
LOADCUBE(CUBEARRAY,MOVES,MIXES);
DRAWCUBE;
WRITEMOVES(MOVES);
WRITEMIXES(MIXES);
TURN := NONE;
END;
CHR(26) : DONE := TRUE;
CHR(23) : DRAWSCREEN;
'R','r','6' : TURN := RIGHT;
'L','l','4' : TURN := LEFT;
'F','f','5' : TURN := FRONT;
'B','b','9' : TURN := BACK;
'U','u','8' : TURN := UP;
'D','d','2' : TURN := DOWN
OTHERWISE
TURN := NONE;
END;
UNTIL (TURN <> NONE) OR (KEY = CHR(23)) OR (KEY = CHR(26)) OR
(KEY = CHR(8)) OR (KEY = CHR(12));
DIR := 0;
IF (KEY <> CHR(23)) AND (KEY <> CHR(26)) AND
(KEY <> CHR(8)) AND (KEY <> CHR(12)) THEN REPEAT
KEY := GETKEY;
IF (KEY = CHR(27)) THEN ESCAPE(KEY);
CASE KEY OF
'+',',' : DIR := 1;
'2' : DIR := 2;
'-' : DIR := 3
OTHERWISE
DIR := 0;
END
UNTIL (DIR <> 0);
IF (DIR <> 0) THEN MOVES := MOVES + 1;
END;
(******************************************************************************)
(* MAIN *)
BEGIN
OPENKEY;
KEY := ' ';
I := 0;
REGIS;
WRITELN('T(A0)');
DRAWSCREEN;
QUIT := FALSE;
WHILE NOT(DONE) AND NOT(QUIT) DO BEGIN
I := 0;
TYPED(TURN,DIR,QUIT,MOVES);
CHANGEARRAY(CUBEARRAY,TURN,DIR);
SIDES(TURN);
WRITEMOVES(MOVES);
(* CHECKCUBE(DONE);*)
END;
IF DONE THEN BEGIN
END;
SHUTKEY;
ASCII;
END.