• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
20-05-2016, 09:52 PM (This post was last modified: 21-05-2016 11:20 PM by froehlic.)
Post: #1
 froehlic Junior Member Posts: 3 Joined: Nov 2015 Reputation: 0
Sample program for the Spreadsheet App

I wrote a little demo using the cell() function and positioning the active cell with the variable Cursor.

Just copy the folder SPmaster from the zip-archive to your Apps. Some explanations are in the pdf.

Code:

// Sample for programming the spreadsheet-App
// Frank FrÃ¶hlich 07.04.2016

#pragma mode( separator(.,; ) integer(h32) )

/////////////////
SymbSetup()
//
// Start a new game and clear the board.
// Sets colours and variables.

BEGIN
LOCAL Col1, Col2, Col3, Col4, Lv;

/////////////////////////////////////////
// Activate these lines for OS before 2016_04_16
//
// Col1:= 26614; // Color for Setup-Cells
// Col2:= 32624; // for Code-Cells
// Col3:= 14; // for seperation-Cells
// Col4:= 32663; // for result-Cells

// These Colorcodes are for OS 2016_04_16 and later
Col1:= RGB(255,90,25); // Color for Setup-Cells
Col2:= 16776960; // for Code-Cells
Col3:= 14; // for seperation-Cells
Col4:= 11388671; // for result-Cells

Lv:= iPart(Cell(2,11));// Level:1 easy 4 positions with 6 numbers
// 2 hard 5 positions with 8 numbers
IF Lv < 1 OR Lv > 2 THEN
Lv:= 2;
Cell(2,11):= 2;
END;

// clear the cells
FOR I:=1 TO 11 DO
FOR J:= 1 TO 8 DO
Cell(I,J):=""; // Clear cell
Cell(I,J,8):= 1; // Cell is centred

IF J<6 THEN // set the colours for different cells
Cell(I,J,7):= Col2;
END;

IF J=6 THEN
Cell(I,J,7):= Col3;
END;

IF J>6 THEN
Cell(I,J,7):= Col4;
END;
END; // FOR J
END; // FOR I

// generating the secret code
L1:={};

FOR I:= 1 TO Lv+3 DO
L1(I):= RANDINT(1,4+2*Lv);
Cell(1,I):=I;
END;

Cell(1,11):=1; // Rowmarker
Cell(1,10,7):= Col1; // colour the settings
Cell(1,11,7):= Col1;
Cell(2,10,7):= Col1;
Cell(2,11,7):= Col1;
Cursor:={2,1};

END;

////////////////
Symb()
//
// Checks the Code in the line
// given by K1

BEGIN
LOCAL i, j, Lv, OK, Pos, t, Zahl, Zeil;

// L2 is a flag for the position
// checked positive
L2:= {0,0,0,0,0};

Pos:=0; Zahl:=0;
Zeil:=Cell(1,11);
Lv:=iPart(Cell(2,11));
OK:= TRUE;

// Check for the usable numbers
FOR i:= 1 TO Lv+3 DO
IF Cell(Zeil,i) < 1 OR
Cell(Zeil, i) > 2*Lv + 4 THEN
OK:= FALSE;
Cell(Zeil, i, 6):= RGB(#FFh,0,0); // Wrong number => red
ELSE
Cell(Zeil,i,6):= RGB(0,0,0); // OK => black
END; // IF
END; // FOR

IF Zeil > 10 THEN // game over?
OK= FALSE;
END;

// now we can do the main task and check
// the code in the actual line
IF OK THEN
FOR i:=1 TO Lv+3 DO
j:=1;
t:=TRUE;

WHILE t DO
IF L2(j)=0 AND
Cell(Zeil,i)=L1(j) THEN

Zahl:=Zahl+1;
L2(j):=1; //set the flag so that you know
END; //IF correct (num or pos)

j:=j+1;

IF j > Lv + 3 THEN
t:=FALSE;
END; //IF
END; //WHILE

IF Cell(Zeil,i)=L1(i) THEN
Pos:= Pos+1;
Zahl:=Zahl-1;
END; // IF
END; // FOR i

Cell(Zeil,7):=Pos;
Cell(Zeil,8):=Zahl;

// have I won?
IF (Pos=4 AND Lv=1) OR
(Pos=5 AND Lv=2) THEN

Zeil:=Zeil+1;
Cell(Zeil,1):="*";
Cell(Zeil,2):="G";
Cell(Zeil,3):="a";
Cell(Zeil,4):="m";
Cell(Zeil,5):="e";
Cell(Zeil,6):="*";
Cell(Zeil,7):="*";
Cell(Zeil,8):="*";
ELSE
Cell(1,11):=Cell(1,11)+1; // increase rowmarker

IF Cell(1,11)= 11 THEN // only 10 guesses!
Zeil:=Zeil+1;
Cell(Zeil,1):="-";
Cell(Zeil,2):="L";
Cell(Zeil,3):="o";
Cell(Zeil,4):="s";
Cell(Zeil,5):="t";
Cell(Zeil,6):="-";
Cell(Zeil,7):="-";
Cell(Zeil,8):="-";
END; // IF game_over
END; // IF Pos

ELSE // there was one or more number not in range
Cell(Zeil,7):= "-";
Cell(Zeil,8):= "-";
END; // IF OK

Cursor:={Zeil+1,1}; //Set the cursor to next line, coloumn A
END; //Symb

////////////////////
NumSetup
// Give up and end the game

BEGIN
LOCAL Zeil;

Zeil:=Cell(1,11);
Cell(Zeil,1):="L";
Cell(Zeil,2):="o";
Cell(Zeil,3):="s";
Cell(Zeil,4):="t";
MSGBOX(L1,TRUE)
END;

Attached File(s)