-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlphabet2048.lpr
3745 lines (3556 loc) · 97.4 KB
/
Alphabet2048.lpr
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{$mode objfpc} // directive to be used for defining classes
{$m+} // directive to be used for using constructor
{TODO -o JordiYaputra -c : Alphabet 2048}
{Done: class console}
{Done: class board}
{Done: class game}
{Done: class controller}
{Done: class UserList}
{Done: class menu}
{Done: class HighScore}
{ToDo: class Setting}
program Alphabet2048;
Uses Crt, Math, SysUtils, Windows;
Const
UserListFName = 'users.bin';
//SettingFName = 'setting.bin';
//HighscoreFName = 'hiscore.bin';
MaxTopScore = 10;
{INTERFACE}
Type
arrayByte = Array of byte;
arrayStcChar = Array [0..255] of char;
EArrow = (NUL = 0, UP, RIGHT, DOWN, LEFT);
ESpKey = (NULL = 0, ENTER, HOME, BACKSPACE, EN, SPACE, DEL);
Point = record
x, y: integer;
end;
RUser = record
username: String;
nickname: String;
password: String;
totalScore: longInt;
end;
RScoreModel = record
username: string;
//nickname: String;
score: longint;
end;
{ TConsole }
TConsole = class
private
x0, y0, x1, y1: integer;
border, padding: boolean;
procedure SetConsoleWindow(NewWidth : integer;NewHeight : integer);
public
width, height: integer;
constructor create(
const i0, j0, i1, j1: integer; const bor, pad: boolean
);
procedure reset();
procedure drawBorder(const symbol: char);
procedure writeNumRight(const num: longint; x, y: integer);
procedure WriteAlignMiddle(const str: string; x, y: integer);
procedure writeXY(const str: string; x, y: integer); overload;
procedure writeXY(const num: longInt; x, y: integer);
procedure fillBlank(const x2, y2, x3, y3: integer);
end;
TSetting = class
public
end;
{ TBoard }
TBoard = class
private
table : arrayByte;
pos : Point;
size: byte;
len: byte;
score: longint;
count: byte;
public
scale: byte;
constructor create(const p: Point; siz: byte); overload;
constructor create(const p: Point; siz, scl: byte); overload;
procedure setSize(const siz: byte);
function getTable(): arrayByte;
procedure setPos(const p: Point);
function getPos(): Point;
procedure setVal(const val: byte); overload;
procedure setVal(const index: byte; const val: byte);
procedure setTable(tb: arrayByte);
procedure insertRandom();
function getVal(const index: byte): byte;
procedure drawFrame();
procedure render();
procedure shift(dir: EArrow);
function getScore(): longint;
procedure setScore(const n: longInt);
procedure addScore(const n: longInt);
function getCount(): byte;
procedure copyTo(var arr: arrayByte);
function noMoveLeft(): boolean;
end;
{ TKeyboardListener }
TKeyboardListener = class
public
lastArrowKey: EArrow;
lastSpKey: ESpKey;
lastKey: byte;
constructor create;
procedure listen();
procedure reset();
end;
{ TUser }
TUser = class
private
totalScore: longint;
password: string;
public
username: string;
nickname: string;
constructor create(const uname, nname, pass: string); overload;
constructor create(const rawUser: RUser); overload;
constructor create(const uname, nname, pass: string; score: longint);
function getScore: longint;
procedure setScore(score: longint);
procedure addScore(num: longint);
function getRaw: RUser;
function getPass(): string;
procedure setPass(const str: string);
end;
{ TUserList }
TUserList = class
private
usersList: Array of TUser;
procedure push(const user: TUser);
procedure pop;
function encrypt(const str: string): string;
function decrypt(const str: string): string;
public
constructor create;
destructor destroy;
function isExist(const username: string): boolean;
function getUser(const username: string) : TUser;
function getLength(): integer;
function getUserAt(i: byte): TUser;
function editUsername(const username, newUname: string): byte;
function editNickname(const username, newNickname: string): byte;
function editPassword(const username, newPass: string): byte;
function forgotPassword(const username, newPass: string): byte;
function addUser(const username, nickname, password: string): byte;
function deleteUser(const username: string): byte;
procedure deleteAll;
procedure dispList;
procedure exportList;
end;
{ TScoreList }
TScoreList = class
private
scoresList: Array of RScoreModel;
fileName: String;
function toSModel(user: TUser; score: longint): RScoreModel; overload;
function toSModel(const username{, nickname}: String; score: longint): RScoreModel;
procedure sort;
procedure push(sModel: RScoreModel);
procedure insert(sModel: RScoreModel; index: byte);
public
constructor Create(const fname: String);
function getAt(id: byte): rScoreModel;
function getLength: byte;
procedure pop;
procedure checkin(user: TUser; score: longint);
procedure displayList;
procedure deleteAll;
procedure deleteAt(index: byte);
procedure exportList;
end;
RHistoryModel = record
table: arrayByte;
score: longInt;
end;
{ TGameSystem }
TGameSystem = class
private
keyboard: TKeyboardListener;
historyPool: Array of RHistoryModel;
maxUndo: byte;
public
size: byte;
board: TBoard;
procedure pour(arr: arrayByte; score: longInt);
function slurp(): RHistoryModel;
procedure drainPool();
procedure undo();
procedure restart();
procedure gameOver();
function isDiff(const arr1, arr2: arrayByte): boolean;
procedure update(var exitState: boolean; var flag: string);
procedure render(var flag: string);
procedure listen();
procedure setup();
procedure play();
constructor create(const siz: byte);
destructor destroy();
procedure routine();
end;
{ TInputBox }
TInputBox = class
private
keyboard: TKeyboardListener;
dispIdx: byte;
cursor: byte;
procedure insert(const c: char);
procedure remove;
procedure delete;
procedure moveCursor(const dir: EArrow);
procedure update(var exitState: boolean);
procedure listen(var exitState: boolean);
public
content: arrayStcChar;
width: byte;
maxChar: byte;
masking: boolean;
pos: Point;
len: byte;
constructor create(keyb: TKeyboardListener); overload;
constructor create(keyb: TKeyboardListener;
wid: byte; x, y: byte; maxCh: byte = 255; mask: boolean = false
);
procedure setup(wid: byte; x, y: byte; maxCh: byte = 255; mask: boolean = false);
procedure render;
procedure showCursor;
procedure setPos(const x, y: byte);
function getContent: string;
function rawRender: string;
procedure routine;
end;
{ TCheckBox }
TCheckBox = class
keyboard: TKeyboardListener;
procedure listen(var exitState: boolean);
public
value: boolean;
message: string;
pos: Point;
constructor create(keyb: TKeyboardListener); overload;
constructor create(
keyb: TKeyboardListener;
const x, y: byte;
const msg: string = '';
val: boolean = false
);
procedure trigger;
procedure render;
procedure drawInit;
procedure routine;
end;
EMenuPages = (
pStartPage = 0, pMainMenu, pPlayGame, pLogin, pHighscore
);
{ TMainSystem }
TMainSystem = class
private
currentPage, prevPage: EMenuPages;
arrowL, arrowR: point;
arrowRactive: boolean;
scorelist: TScoreList;
userlist: TUserList;
currentUser: TUser;
game: TGameSystem;
boardSize: byte;
tmpBoard: arrayByte;
keyboard: TKeyboardListener;
inputBoxes: array [0..4] of TInputBox;
checkBoxes: array [0..1] of TCheckBox;
framecount: longint;
delaytime: byte;
procedure drawArrow(const a: byte);
procedure undrawArrow();
procedure setArrow(const x, y: byte);
procedure setArrow(const xl, yl, xr, yr: byte);
procedure setArrow(var arrow: Point; const x, y: byte);
procedure drawRect(const x1, y1, x2, y2: byte);
procedure drawRoundBox(const x1, y1, x2, y2: byte);
procedure drawSlantBox(const x1, y1, x2, y2: byte);
procedure setup(var changePage, exitState: boolean; var flag: string; var store: arrayByte);
procedure drawPage();
procedure update(var changePage, exitState: boolean; var flag: string; var store: arrayByte);
procedure render(var flag: string; var store: arrayByte);
procedure listen(var changePage, exitState: boolean; var flag: string; var store: arrayByte);
public
constructor create;
destructor destroy;
procedure routine;
end;
{IMPLEMENTATION}
Var
console: TConsole;
setting: TSetting;
function toStr(const arrCh: arrayStcChar; const len: byte): string; forward;
function subStr(const str: string; start, len: integer): string; forward;
{ TCheckBox }
procedure TCheckBox.listen(var exitState: boolean);
begin
keyboard.reset;
keyboard.listen;
if keyboard.lastSpKey in [ENTER, SPACE] then begin
trigger;
exitState:= true;
keyboard.reset;
end else
if (keyboard.lastArrowKey in [UP, DOWN]) then begin
exitState:= true;
end;
end;
constructor TCheckBox.create(keyb: TKeyboardListener);
begin
create(keyb, 1, 1);
end;
constructor TCheckBox.create(keyb: TKeyboardListener; const x, y: byte; const msg: string; val: boolean);
begin
keyboard:= keyb;
pos.x:= x;
pos.y:= y;
message:= msg;
value:= val;
end;
procedure TCheckBox.trigger;
begin
value:= not value;
end;
procedure TCheckBox.render;
var c: char;
begin
if value then c:= 'Y' else c:= 'X';
console.writeXY(c, pos.x + 1, pos.y);
end;
procedure TCheckBox.drawInit;
begin
console.writeXY('[', pos.x, pos.y);
console.writeXY(']', pos.x + 2, pos.y);
console.writeXY(message, pos.x + 4, pos.y);
end;
procedure TCheckBox.routine;
var exitState: boolean;
begin
exitState:= false;
drawInit;
repeat
render;
gotoXY(pos.x + 1, pos.y);
cursoron;
listen(exitState);
until exitState;
cursoroff;
end;
{ TInputBox }
procedure TInputBox.insert(const c: char);
var
i: byte;
begin
if len < maxChar then begin
inc(len);
i:= len;
while (i > cursor) do begin
content[i]:= content[i - 1];
dec(i);
end;
content[cursor]:= c;
moveCursor(RIGHT);
end;
end;
procedure TInputBox.remove;
var
i: byte;
begin
if cursor > 0 then begin
i:= cursor - 1;
while (i < len) do begin
content[i]:= content[i + 1];
inc(i);
end;
dec(len);
moveCursor(LEFT);
end;
end;
procedure TInputBox.delete;
var i: byte;
begin
if cursor <= len then begin
moveCursor(RIGHT);
remove;
end;
end;
procedure TInputBox.moveCursor(const dir: EArrow);
begin
case dir of
LEFT: begin
if cursor > 0 then
dec(cursor);
if cursor < dispIdx then
dec(dispIdx);
end;
RIGHT: begin
if cursor < len then
inc(cursor);
if cursor > dispIdx + width then
inc(dispIdx);
end;
else begin end;
end;
end;
procedure TInputBox.update(var exitState: boolean);
begin
end;
procedure TInputBox.render;
var i: byte;
begin
gotoXY(pos.x, pos.y);
for i:= 1 to width do
write(' ');
i:= dispIdx;
gotoXY(pos.x, pos.y);
while (i < len) and (i < dispIdx + width) do begin
if masking then write('*')
else write(content[i]);
inc(i);
end;
end;
procedure TInputBox.showCursor;
begin
cursoron;
gotoXY(pos.x + cursor - dispIdx, pos.y);
end;
procedure TInputBox.setPos(const x, y: byte);
begin
pos.x:= x;
pos.y:= y;
end;
function TInputBox.getContent: string;
begin
getContent:= toStr(content, len);
end;
function TInputBox.rawRender: string;
var
i: byte;
arCh: arrayStcChar;
begin
for i:= 1 to width do
arCh[i]:= ' ';
i:= dispIdx;
while (i < len) and (i < dispIdx + width) do begin
if masking then arCh[i-dispIdx]:= '*'
else arCh[i-dispIdx]:= content[i];
inc(i);
end;
rawRender:= toStr(arCh, width);
end;
procedure TInputBox.listen(var exitState: boolean);
begin
keyboard.reset;
keyboard.listen;
if keyboard.lastArrowKey <> NUL then begin
case keyboard.lastArrowKey of
LEFT: moveCursor(LEFT);
RIGHT: moveCursor(RIGHT);
else exitState:= true;
end;
if keyboard.lastArrowKey <> UP then
keyboard.reset;
end else
if keyboard.lastSpKey <> NULL then begin
case keyboard.lastSpKey of
ENTER: exitState:= true;
SPACE: insert(' ');
BACKSPACE: remove;
DEL: delete;
HOME: cursor:= 0;
EN: cursor:= len - 1;
end;
keyboard.reset;
end else begin
if keyboard.lastKey in [33..126] then
insert(char(keyboard.lastKey));
keyboard.reset;
end;
end;
constructor TInputBox.create(keyb: TKeyboardListener);
begin
cursor:= 0;
dispIdx:= 0;
len:= 0;
setup(20, 1, 1);
keyboard:= keyb;
end;
constructor TInputBox.create(keyb: TKeyboardListener; wid: byte; x, y: byte;
maxCh: byte; mask: boolean);
begin
create(keyb);
setup(wid, x, y, maxCh, mask);
end;
procedure TInputBox.setup(wid: byte; x, y: byte; maxCh: byte; mask: boolean);
begin
width:= wid;
setPos(x, y);
maxChar:= maxCh;
masking:= mask;
end;
procedure TInputBox.routine;
var
exitState: boolean;
begin
exitState:= false;
repeat
update(exitState);
cursoroff;
render;
showCursor;
listen(exitState);
until exitState;
cursoroff;
end;
{ TMainSystem }
procedure TMainSystem.drawArrow(const a: byte);
begin
gotoXY(arrowL.x-1, arrowL.y);
if a mod 2 = 0 then write('->')
else write('--');
if arrowRactive then
begin
gotoXY(arrowR.x, arrowR.y);
if a mod 2 = 0 then write('<-')
else write('--');
end;
end;
procedure TMainSystem.undrawArrow();
begin
gotoXY(arrowL.x-1, arrowL.y);
write(' ');
if arrowRactive then
begin
gotoXY(arrowR.x, arrowR.y);
write(' ');
end;
end;
procedure TMainSystem.setArrow(const x, y: byte);
begin
arrowL.x:= x;
arrowL.y:= y;
end;
procedure TMainSystem.setArrow(const xl, yl, xr, yr: byte);
begin
arrowL.x:= xl;
arrowL.y:= yl;
arrowR.x:= xr;
arrowR.y:= yr;
end;
procedure TMainSystem.setArrow(var arrow: Point; const x, y: byte);
begin
arrow.x:= x;
arrow.y:= y;
end;
procedure TMainSystem.drawRect(const x1, y1, x2, y2: byte);
var
j: byte;
buff: string;
begin
buff:= '';
for j:= x1 to x2 do
if j in [x1, x2] then
buff:= buff+'+'
else
buff:= buff+'-';
for j:= y1 to y2 do
begin
gotoXY(x1, j);
if j in [y1, y2] then
write(buff)
else begin
write('|');
gotoXY(x2, j);
write('|');
end;
end;
end;
procedure TMainSystem.drawRoundBox(const x1, y1, x2, y2: byte);
var
i: byte;
buff: string = '';
begin
for i:= x1+1 to x2-1 do
if i in [x1+1, x2-1] then
buff:= buff + 'o'
else
buff:= buff + '-';
for i:= y1 to y2 do
begin
if (i in [y1, y2]) then
console.writeXY(buff, x1+1, i)
else if (y2 - y1 > 2) and (i = y1 + 1) then
begin
console.writeXY('/', x1, i);
console.writeXY('\', x2, i);
end
else if (y2 - y1 > 2) and (i = y2 - 1) then
begin
console.writeXY('\', x1, i);
console.writeXY('/', x2, i);
end
else begin
console.writeXY('|', x1, i);
console.writeXY('|', x2, i);
end;
end;
end;
procedure TMainSystem.drawSlantBox(const x1, y1, x2, y2: byte);
var
i: byte;
buff: string;
begin
buff:= '';
for i:= 1 to (x2-x1)-(y2-y1) do
buff:= buff + '-';
for i:= 0 to y2-y1 do begin
gotoXY(x1 + i, y1 + i);
if (i in [0, (y2-y1)]) then begin
if (i = 0) then write('<');
write(buff);
if (i = y2-y1) then write('>');
end
else begin
write('\');
console.writeXY('\', x2 - (y2-y1) + i , y1 + i);
end;
end;
end;
procedure TMainSystem.setup(var changePage, exitState: boolean;
var flag: string; var store: arrayByte);
var
i: byte;
begin
case currentPage of
pStartPage: begin
setArrow(31, 27, 44, 27);
arrowRactive:= true;
end;
pLogin: begin
setArrow(66, 27, 73, 27);
arrowRactive:= true;
if length(store) <> 4 then
setLength(store, 4);
//store[0] = ulist start,
//store[1] = select user,
//store[2] = message flag,
//store[3] = counter;
for i:= 0 to 3 do
store[i]:= 0;
flag:= 'init';
end;
pMainMenu: begin
setArrow(13, 6, 1, 1);
arrowRactive:= false;
if length(store) <> 1 then
setLength(store, 1);
store[0]:= 4;
flag:= 'init';
end;
pPlayGame: begin
delayTime:= 0;
//boardSize:= 3;
case boardSize of
3: scorelist:= TScoreList.create('3x3.bin');
4: scorelist:= TScoreList.create('4x4.bin');
5: scorelist:= TScoreList.create('5x5.bin');
6: scorelist:= TScoreList.create('6x6.bin');
//7: scorelist:= TScoreList.create('7x7.bin');
//8: scorelist:= TScoreList.create('8x8.bin');
else scorelist:= TScoreList.create('what.bin');
end;
game:= TGameSystem.create(boardSize);
setLength(tmpBoard, boardSize*boardSize);
if length(store) <> 1 then
setLength(store, 1);
game.board.insertRandom();
game.pour(game.board.getTable(), game.board.getScore());
store[0]:= 1;
game.board.copyTo(tmpBoard);
flag:= 'init';
end;
pHighscore: begin
if length(store) <> 2 then
setLength(store, 1);
store[0]:= 4;
store[1]:= 0;
setArrow(4, 27, 11, 27);
flag:= 'initChange';
end;
end;
end;
procedure TMainSystem.drawPage();
var
f: textFile;
x, y, e: byte;
buff: string;
begin
case currentPage of
pStartPage: begin
assign(f,'AsciiArtAlphabet2048.txt');
try
reset(f);
except
console.writeAlignMiddle('Alphabet 2048', console.width div 2, 10);
rewrite(f);
reset(f);
end;
y:= 2;
x:= 6;
while not eof(f) do
begin
readln(f, buff);
gotoXY(x, y);
write(buff);
inc(y);
end;
close(f);
console.WriteAlignMiddle(
'START GAME',
console.width div 2, y+2
);
y:= 26;
x:= 61;
console.writeXY('Created by:',x, y);
console.writeXY('Jordi Yaputra',x+2, y+1);
end;
pLogin: begin
drawRect(3, 2, console.width-2, 4);
console.writeXY('Play as:', 5, 3);
drawRect(3, 6, 56, 8); //UserSelectBoxHeader
drawRect(3, 8, 56, console.height-6); //userSelectBox
drawRect(3, console.height-4, console.width-2, console.height-2);
console.writeAlignMiddle('Create New User',console.width div 2, 24);
drawRect(58, 6, console.width-2, 8);
x:= 63;
console.writeXY('Login', x, 7);
drawRect(58, 10, console.width-2, 12);
console.writeXY('Edit', x, 11);
drawRect(58, 14, console.width-2, 16);
console.writeXY('Delete', x, 15);
gotoXY(6, console.height);
write('Back');
gotoXY(console.width-8, console.height);
write('Done');
end;
pMainMenu: begin
x:= 6;
y:= 4;
drawSlantBox(x, y, x + 68,y+4);
console.writeXY('Play Game', x + 9, y + 2);
inc(x, 5); inc(y, 6);
drawSlantBox(x, y, x + 27,y+4);
console.writeXY('Change User', x + 9, y + 2);
inc(x, 5); inc(y, 6);
drawSlantBox(x, y, x + 26,y+4);
console.writeXY('High Score', x + 9, y + 2);
inc(x, 5); inc(y, 6);
drawSlantBox(x, y, x + 21,y+4);
console.writeXY('Exit', x + 9, y + 2);
x:= 45;
y:= 10;
console.writeXY('# # # ### # #', x, y + 0);
console.writeXY('## ## # # # ## #', x, y + 1);
console.writeXY('# # # ##### # # # #', x, y + 2);
console.writeXY('# # # # # # # ##', x, y + 3);
console.writeXY('# # # # # ### # #', x, y + 4);
x:= x + 4;
y:= y + 6;
console.writeXY('# # ##### # # # #', x, y);
console.writeXY('## ## # ## # # #', x, y+1);
console.writeXY('# # # #### # # # # #', x, y+2);
console.writeXY('# # # # # ## # #', x, y+3);
console.writeXY('# # # ##### # # ### ', x, y+4);
end;
pPlayGame: begin
console.writeXY('Score:', 2, 2);
end;
pHighscore: begin
x:= 2;
y:= 2;
drawRect(x, y, console.width, y + 2);
console.writeAlignMiddle('TOP 10 HIGHSCORES', console.width div 2, y + 1);
drawRect(x, y + 2, console.width, 24);
console.writeXY('Back', 6, console.height);
end;
end;
end;
procedure TMainSystem.update(var changePage, exitState: boolean;
var flag: string; var store: arrayByte);
var i: byte;
begin
case currentPage of
pStartPage: begin
end;
pLogin: begin
case flag of
'': begin
if (store[3] > 0) then dec(store[3]);
end;
'initCreateUser': begin
for i:= 0 to 3 do
inputBoxes[i]:= TInputBox.create(keyboard, 30, 16, 10 + i*2);
inputBoxes[2].masking:= true;
inputBoxes[3].setup(30, 25, 16, 255, true);
end;
'initLogin': begin
inputBoxes[0]:= TInputBox.create(keyboard, 20, 16, 12, 255, true);
checkBoxes[0]:= TCheckbox.create(keyboard, 16, 13, 'Show Password');
end;
'login': begin
inputBoxes[0].masking:= not checkBoxes[0].value
end;
'initEdit': begin
for i:= 0 to 3 do
inputBoxes[i]:= TInputBox.create(keyboard, 30, 16, 10 + i*2);
inputBoxes[2].masking:= true;
inputBoxes[3].setup(30, 25, 16, 255, true);
end;
'initFPass': begin
for i:= 1 to 3 do
inputBoxes[i]:= TInputBox.create(keyboard, 30, 16, 10 + i*2);
inputBoxes[2].masking:= true;
inputBoxes[3].setup(30, 25, 16, 255, true);
end;
end;
end;
pMainMenu: begin
case flag of
'': begin
if (ArrowL.y = 6) then
arrowRactive:= false
else
arrowRactive:= true;
end;
end;
end;
pPlayGame: begin
case flag of
'init': begin
delayTime:= 0;
end;
'play': begin
console.writeXY(' ', 2, 4);
if game.board.noMoveLeft then begin
flag:= 'initGameover';
arrowRactive:= true;
setArrow(34, 12, 41, 12);
delayTime:= 200;
end else begin
if game.isDiff(tmpBoard, game.board.getTable) then begin
console.writeXY('change', 2, 4);
game.board.copyTo(tmpBoard);
game.pour(tmpBoard, game.board.getScore());
if store[0] < 3 then
inc(store[0]);
game.board.insertRandom();
end;
game.board.copyTo(tmpBoard);
end;
end;
'initPause': begin
arrowRactive:= true;
setArrow(33, 12, 42, 12);
end;
'undo': begin
dec(store[0]);
game.undo();
game.board.copyTo(tmpBoard);
flag:= 'play';
end;
end;
end;
pHighScore: begin
case flag of
'initChange': begin
store[1]:= 0;
case store[0] of
3: scorelist:= TScoreList.create('3x3.bin');
4: scorelist:= TScoreList.create('4x4.bin');
5: scorelist:= TScoreList.create('5x5.bin');
6: scorelist:= TScoreList.create('6x6.bin');
//7: scorelist:= TScoreList.create('7x7.bin');
//8: scorelist:= TScoreList.create('8x8.bin');
else scorelist:= TScoreList.create('what.bin');
end;
end;
end;
end;
end;
end;
procedure TMainSystem.render(var flag: string; var store: arrayByte);
var
i, x, y: byte;
buff: string;
begin
case currentPage of
pStartPage: begin
case flag of
'': drawArrow(framecount mod 2);
'change': begin
undrawArrow;
for i:= 28 downto 0 do
begin
writeln;
sleep(20);
end;
flag:= 'next';
end;
end;
end;
pLogin: begin
case flag of
'init': begin
console.fillBlank(14, 3, 73, 3);
console.fillBlank(4, 7, 55, 7);
console.fillBlank(4, 9, 55, console.height-7);
console.writeAlignMiddle('Username list', 3 + (56 - 3) div 2, 7);
flag:= '';
end;
'': begin
drawArrow(framecount mod 2);
console.writeXY(subStr(currentUser.username, 1, 59), 14, 3);
i:= 0;
while (i < 6) and (i < userlist.getLength()) do begin
console.writeXY(
subStr(userlist.getUserAt(i+store[0]).username, 1, 48),
7, 9 + i*2
);