-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.inc
958 lines (759 loc) · 18.8 KB
/
GUI.inc
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
.code
intro proc
CALL GETPLAYERNAME
CALL MENUGUI
ret
intro endp
;=============================================================;
;=============================================================;
notificationdivider proc ;horizontal line to divide notification area from menu area
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,166
outl12:
mov cx,04
outl11:
int 10h
inc cx
cmp cx,636
jne outl11
inc dx
cmp dx,167
jne outl12
ret
notificationdivider endp
;=============================================================;
;=============================================================;
DRAWNOTIFICATION PROC ;draws notification for main menu
call notificationdivider
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,1506h
int 10h
mov ah, 9 ;Display 'Hi'
mov dx, offset hi
int 21h
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,1509h
int 10h
mov ah,9
mov dx,offset PLAYERNAME+2
int 21h
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,1706h
int 10h
mov ah, 9
mov dx, offset welcomemessage
int 21h
ret
DRAWNOTIFICATION ENDP
;=============================================================;
;=============================================================;
ABOUTGUI PROC ;draws about game screen
MOV AX, 0EH
INT 10H
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,0300h
int 10h
mov ah, 9 ;Display '->To see more about the game press F1$'
mov dx, offset ABOUT
int 21h
CALL NOTIFICATIONDIVIDER
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dh,17h
MOV DL,24
int 10h
mov ah, 9 ;Display '->To see more about the game press F1$'
mov dx, offset ABOUTIN
int 21h
RET
ABOUTGUI ENDP
;=============================================================;
;=============================================================;
showmouse proc ;shows mouse and defines horizontal range for it
mov ax,1 ;show mouse cursor
int 33h
mov ax,8h ;define horizontal range for mouse
mov cx,40
mov dx,200
int 33h
ret
showmouse endp
;=============================================================;
;=============================================================;
hidemouse proc
mov ax,2 ;show mouse cursor
int 33h
ret
hidemouse endp
;=============================================================;
;=============================================================;
outro proc ;outro screen
MOV AH,0 ;CHANGE TO GRAPHICS MODE, THIS CLEARS THE SCREEN
MOV AL,02H ;640x200 pixels and 80x25 text but only 16 colors, al=13h 320x200 and 256 colors
INT 10H
mov ax,4c00h
int 21h
RET
outro ENDP
;=============================================================;
;=============================================================;
initializecounters proc ;initializes counters each time the user goes to main menu to prepare for game mode
mov BLUECOUNT,0
mov GREENCOUNT,0
mov CYANCOUNT,0
mov REDCOUNT,0
mov PINKCOUNT,0
mov BROWNCOUNT,0
mov SQUARECOUNT,0
mov TRIANGLECOUNT,0
mov PARALLELOGRAMCOUNT,0
mov ARROWCOUNT,0
mov HEXAGONCOUNT,0
mov CROSSCOUNT,0
mov numcolortoclick,0
mov numfiguretoclick,0
mov colortoclick,0
mov figuretoclick,0
mov ah,startinglives
mov lives,ah
mov timerbuffer,0
mov timerpos,479
ret
initializecounters endp
;=============================================================;
;=============================================================;
TUTORIAL PROC ;tutorial to teach the user how to play
MOV AX, 0EH ;graphics mode
INT 10H
call notificationdivider
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dh,06h
mov dl,36
int 10h
mov ah, 9
mov dx, offset TUTORIALSTR
int 21h
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,0A10h
int 10h
mov ah, 9
mov dx, offset TUTORIALSTR0
int 21h
mov ah,2 ;Move Cursor to lower middle of screen
mov dx,0C10h
int 10h
mov ah, 9
mov dx, offset TUTORIALSTR1
int 21h
mov ah,2 ;Move Cursor, to middle of screen
mov dx,0E10h
int 10h
mov ah,9
mov dx,offset TUTORIALSTR2
int 21h
mov ah,2 ;Move Cursor, to middle of screen
mov dx,1715h
int 10h
mov ah,9
mov dx,offset TUTORIALSTR3
int 21h
CALL SHOWMOUSE
WAITFORRELEASE:
mov ax,3
int 33h
test bx, 00000001b ; perform bitwise AND with 00000001b
jz WAITFORRELEASE
RET
TUTORIAL ENDP
;=============================================================;
;=============================================================;
MENUGUI PROC ;draws menu gui
MOV AH,0 ;CHANGE TO GRAPHICS MODE, THIS CLEARS THE SCREEN
MOV AL,0EH ;640x200 pixels and 80x25 text but only 16 colors, al=13h 320x200 and 256 colors
INT 10H
MOV SELECTION,0
CALL DRAWSELECTIONMARK
call initializecounters
CALL DRAWNOTIFICATION
mov bh,0
mov ah,2 ;Move Cursor to upper middle of screen
mov dx,0A1Eh
int 10h
mov ah, 9 ;Display '->To see more about the game press F1$'
mov dx, offset mainscreen1
int 21h
mov ah,2 ;Move Cursor to lower middle of screen
mov dx,0C1Eh
int 10h
mov ah, 9 ;Display '->To play GO FIGURE!! press F2$'
mov dx, offset mainscreen2
int 21h
mov ah,2 ;Move Cursor, to middle of screen
mov dx,0E1Eh
int 10h
mov ah,9 ;Display '->To exit the game press ESC$'
mov dx,offset mainscreen3
int 21h
ret
MENUGUI ENDP
;=============================================================;
;=============================================================;
GAMEGUI PROC ;this runs every frame the update timer
; call drawgrid ;uncomment this the see the grid that divides the screen
call updatetimer
ret
GAMEGUI ENDP
;=============================================================;
;=============================================================;
updatetimer proc ;draws a black line that "decrements" the timer when timer buffer reaches timerbufferlimit
inc timerbuffer
MOV AX,TIMERBUFFERLIMIT
cmp timerbuffer,AX
jne notyet
cmp timerpos,162
je lost
cmp timerpos,320
jne notredyet
call redtimer
notredyet:
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,0h ;set black colour
mov dx,14
mov cx,timerpos
sh3bolaloop:
int 10h
inc dx
cmp dx,19
jnz sh3bolaloop
dec timerpos
mov timerbuffer,00h
notyet:
ret
lost:
call playerlost
ret
updatetimer endp
;=============================================================;
;=============================================================;
resettimer proc ;resets the timer back to full
call drawtimer
mov timerpos,479
mov timerbuffer,0
ret
resettimer endp
;=============================================================;
;=============================================================;
drawoutline proc ;draws outline of game and writes player name and lives
call drawtimer
mov ah,2 ;move cursor at desired destination
mov bh,0
mov dl,1
mov dh,56
int 10h
mov ah,09
mov dx,offset ESCTOPAUSE
int 21h
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,0Dh ;set the white colour
mov dx,9
mov cx,04
outl111:
int 10h
inc cx
cmp cx,636
jne outl111
mov ah,2 ;move cursor at desired destination
mov bh,0
mov dx,1
int 10h
mov ah,09
mov dx,offset PLAYERNAME+2
int 21h
mov ah,2 ;move cursor at desired destination
mov bh,0
mov dx,1h ;a5er el screen
add dl,PLAYERNAME+1 ;add playername length
int 10h
mov ah,09
mov dx,offset LIVESSTR ;write "'s lives" after playername
int 21h
mov ah,2 ;move cursor at desired destination
mov bh,0
mov dx,1h
add dl,PLAYERNAME+1
add dl,0Ah ;add length of lives to cursor
int 10h
mov ah,02
mov dl, lives ;then write the lives after adding all that
int 21h
ret
drawoutline endp
;=============================================================;
;=============================================================;
redtimer proc ;when the timer passes the middle point the color turns red
MOV AH,0CH ;interrupt condition
MOV BH,0
MOV AL,04H ;draw red rectangle
MOV DX,14
red1:
MOV CX,162
red2:
INT 10H
INC CX
CMP CX,320
JNZ red2
INC DX
CMP Dx,19
JNZ red1
ret
redtimer endp
;=============================================================;
;=============================================================;
drawtimer proc ;draws the timer rectangle and yellow outline of the timer
MOV AL,0EH ;draw yellow rectangle
MOV AH,0CH ;interrupt condition
MOV BH,0
MOV DX,12
firstw:
MOV CX,160
firstl:
INT 10H
INC CX
CMP CX,480
JNZ firstl
INC DX
CMP Dx,13
JNZ firstw
MOV DX,20
secondw:
MOV CX,160
secondl:
INT 10H
INC CX
CMP CX,480
JNZ secondl
INC DX
CMP Dx,21
JNZ secondw
MOV DX,12
thirdw:
MOV CX,159
thirdl:
INT 10H
INC CX
CMP CX,160
JNZ thirdl
INC DX
CMP Dx,21
JNZ thirdw
MOV DX,12
fourthw:
MOV CX,480
fourthl:
INT 10H
INC CX
CMP CX,481
JNZ fourthl
INC DX
CMP Dx,21
JNZ fourthw
MOV AL,0FH ;draw white rectangle
MOV DX,14
fourthwq:
MOV CX,162
fourthlq:
INT 10H
INC CX
CMP CX,478
JNZ fourthlq
INC DX
CMP Dx,19
JNZ fourthwq
ret
drawtimer endp
;=============================================================;
;=============================================================;
drawgrid proc ;this doesn't actually get invoked but it shows the grid that divides the screen
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,119
qoutl12:
mov cx,04
qoutl11:
int 10h
inc cx
cmp cx,636
jne qoutl11
inc dx
cmp dx,120
jne qoutl12
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,39
weqoutl12:
mov cx,04
weqoutl11:
int 10h
inc cx
cmp cx,636
jne weqoutl11
inc dx
cmp dx,40
jne weqoutl12
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,04
aqoutl12:
mov cx,159
aqoutl11:
int 10h
inc cx
cmp cx,160
jne aqoutl11
inc dx
cmp dx,198
jne aqoutl12
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,04
sqoutl12:
mov cx,319
sqoutl11:
int 10h
inc cx
cmp cx,320
jne sqoutl11
inc dx
cmp dx,198
jne sqoutl12
mov bh,00
mov AH,0CH ;draw pixel int condition
mov al,09h ;set the white colour
mov dx,04
wsqoutl12:
mov cx,479
wsqoutl11:
int 10h
inc cx
cmp cx,480
jne wsqoutl11
inc dx
cmp dx,198
jne wsqoutl12
ret
drawgrid endp
;=============================================================;
;=============================================================;
DRAWFIGURES proc ;draws 8 random figures on the screen
call setrandomseed
call setrandomcolseed
mov ypos,0
;loop on all cells and fill them with random figures
FILLY:
mov xpos,0
FILLX:
; getting random color
CMP GAMETYPE,1
JE BYFIGURE ;if gametype is by figure no need to get rand color, all figures will be grey
call randomcol ;assign random value to eax
and eax,0FFH
mov cl,6
div cl ;now ah has the remainder of the division
inc ah ;to exclude color black (00) add 1
; getting random color
mov color,ah ;put random color in drawing color
; mov color,0FH ;incase of byfigure gametype set color is always grey
call setcolorcounter ;sets color counter with color in ah register
jmp BYCOLOR
BYFIGURE:
mov color,07H ;incase of byfigure gametype set color is always grey
BYCOLOR:
CALL DRAWRANDOMFIGURE ;DRAWS A RANDOM FIGURE AT XPOS AND YPOS WITH COLOR, AT SETS COUNTERS
INC XPOS
CMP XPOS,3
JBE FILLX
INC YPOS
CMP YPOS,1
JBE FILLY
mov figurecount,8
ret
DRAWFIGURES endp
;=============================================================;
;=============================================================;
setcolorcounter proc ;checks color in ah and increases the counter of that color
cmp ah,1
jne notblue
inc bluecount
ret
notblue:
cmp ah,2
jne notgreen
inc greencount
ret
notgreen:
cmp ah,3
jne notcyan
inc cyancount
ret
notcyan:
cmp ah,4
jne notred
inc redcount
ret
notred:
cmp ah,5
jne notpink
inc pinkcount
ret
notpink:
inc browncount
ret
setcolorcounter endp
;=============================================================;
;=============================================================;
DRAWRANDOMFIGURE proc ;draws one random figure in xpos and ypos
call random ;assign random value to eax
and eax,0FFH
mov cl,6
div cl
INC AH ;to exclude color black (00) add 1
CMP AH,1
JNE NOT1
SQUARE XPOS,YPOS,COLOR
INC SQUARECOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd1
add bx,4
dontadd1:
mov figures[bx],0
;fill figures array
RET
NOT1:
CMP AH,2
JNE NOT2
ARROW XPOS,YPOS,COLOR
INC ARROWCOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd2
add bx,4
dontadd2:
mov figures[bx],3
;fill figures array
RET
NOT2:
CMP AH,3
JNE NOT3
PARALLELOGRAM XPOS,YPOS,COLOR
INC PARALLELOGRAMCOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd3
add bx,4
dontadd3:
mov figures[bx],2
;fill figures array
RET
NOT3:
CMP AH,4
JNE NOT4
TRIANGLE XPOS,YPOS,COLOR
INC TRIANGLECOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd4
add bx,4
dontadd4:
mov figures[bx],1
;fill figures array
RET
NOT4:
CMP AH,5
JNE NOT5
HEXAGON XPOS,YPOS,COLOR
INC HEXAGONCOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd5
add bx,4
dontadd5:
mov figures[bx],4
;fill figures array
RET
NOT5:
CROSS XPOS,YPOS,COLOR
INC CROSSCOUNT
;fill figures array
mov bl,xpos ;now bl is xpos and bh is ypos
mov bh,0
cmp ypos,0
je dontadd6
add bx,4
dontadd6:
mov figures[bx],5
;fill figures array
RET
DRAWRANDOMFIGURE endp
;=============================================================;
;=============================================================;
drawgamepausedtext proc ;writes game paused text when game is paused
MOV AH,2 ;Move Cursor to upper middle of screen
MOV DX,030AH
INT 10H
MOV AH, 9 ;Display 'Please enter your name:'
MOV DX, OFFSET PAUSED
INT 21H
RET
drawgamepausedtext endp
;=============================================================;
;=============================================================;
displaycolortopickmes proc ;displays which figure the user should pick
mov ah,2 ;Move Cursor
mov dx,0326H
int 10h
mov ah,02
mov dl,0 ;write null five times to clear old color name
mov cx,5
clearold:
int 21h
loop clearold
mov ah,2 ;Move Cursor
mov dx,0326H
int 10h
mov ah,9 ;Display '->To exit the game press ESC$'
cmp colortoclick,1
jne COLNOTblue
mov dx,offset bluecolor
int 21h
ret
COLNOTblue:
cmp colortoclick,2
jne COLNOTgreen
mov dx,offset greencolor
int 21h
ret
COLNOTgreen:
cmp colortoclick,3
jne COLNOTcyan
mov dx,offset cyancolor
int 21h
ret
COLNOTcyan:
cmp colortoclick,4
jne COLNOTRED
mov dx,offset REDcolor
int 21h
ret
COLNOTRED:
cmp colortoclick,5
jne COLNOTPINK
mov dx,offset PINKcolor
int 21h
ret
COLNOTPINK:
mov dx,offset browncolor
int 21h
ret
displaycolortopickmes endp
;=============================================================;
;=============================================================;
displayfiguretopickmes proc ;displays which figure the user should pick
mov ah,2 ;Move Cursor
mov dx,0326H
int 10h
mov ah,02
mov dl,0 ;write null five times to clear old figure name
mov cx,14
clearoldfig:
int 21h
loop clearoldfig
mov ah,2 ;Move Cursor
mov dx,0326H
int 10h
mov ah,9 ;Display '->To exit the game press ESC$'
cmp figuretoclick,0
jne notSQUARE
mov dx,offset SQUAREfig
int 21h
ret
notSQUARE:
cmp figuretoclick,1
jne notTRIANGLE
mov dx,offset TRIANGLEfig
int 21h
ret
notTRIANGLE:
cmp figuretoclick,2
jne notPARALLELOGRAM
mov dx,offset PARALLELOGRAMfig
int 21h
ret
notPARALLELOGRAM:
cmp figuretoclick,3
jne notARROW
mov dx,offset ARROWfig
int 21h
ret
notARROW:
cmp figuretoclick,4
jne notHEXAGON
mov dx,offset HEXAGONfig
int 21h
ret
notHEXAGON:
mov dx,offset CROSSfig
int 21h
ret
displayfiguretopickmes endp
;=============================================================;
;=============================================================;
CLEARGAMEPAUSEDTEXT PROC ;clears text when game is resumed from pause
MOV AH,2 ;Move Cursor to upper middle of screen
MOV DX,030AH
INT 10H
MOV CX,59
mov ah,02
mov dl, 0 ;then write the score after adding all that
ERASE:
int 21h
LOOP ERASE
call writeclick ;pick all
cmp gametype,1
je dontwritecolor
call displaycolortopickmes ;green
dontwritecolor:
cmp gametype,0
je dontwritefigure
call displayfiguretopickmes ;squares
dontwritefigure:
cmp gametype,1
je cdontwritefigures
call writefigures ;figures (displayed if not in figures' word wasn't displayed)
cdontwritefigures:
RET
CLEARGAMEPAUSEDTEXT ENDP