Color Guess

Post Reply
DragWx
Posts: 403
Joined: Tue Mar 07, 2023 9:07 pm

Color Guess

Post by DragWx »

This is a very simple game written in BASIC, and is similar to a reflex test.

After a countdown, a screen full of colors will be shown, then quickly hidden. The game will then ask you a question about the colors you just saw. There are four game modes:
Mode 1, "How many colors were there?" - Could you tell how many unique colors were on the screen?
Mode 2, "Which color was not there?" - Given a list of all the correct colors plus one fake, choose the fake.
Mode 3, "Which color was there?" - Given a list of colors, only one was actually shown on the screen, choose it.
Mode 4, Random question each time.

You can also select between four speeds, which affect how much time you can view the colors. There are also some simple PSG sound effects thrown in for fun.

-- V1.1 (attached as COLORGUESS-V1-1.BAS) --
Added "which color was there" question.
Optimized code, especially the loop that draws the flashed screen.
Made menus prettier.

Try It Now!

Code: Select all

1 A=0:B=0:C=0:D=0:E=0:F=0:G=0:H=0:I=0
2 SCREEN128:PSGINIT:DIMC%(9):A=RND(0)
3 DATA$34,$50,$8F,$AB,$C7,$DC,$F1,$01,$0F,$0C

10 COLOR1,12:CLS
11 LOCATE3,10:PRINT"\X98\X01\X12\X96\XE9\XDF\X98  \X9A\XE9\XDF\X98  \X1E\XE9\XDF\X98  \X9E\XE9\XDF\X98  \X96\XE9\XDF\X98  \X9A\XE9\XDF\X92"
12 LOCATE4,10:PRINT"\X97\X01\X12\X96C \X9CO \X9AL \X9FO \X1ER \X99  \X9EG \X81U \X96E \X9CS \X9AS \X92"
13 LOCATE5,10:PRINT"\X98\X01  \X9C\XDF\XE9  \X9F\XDF\XE9  \X99\XDF\XE9  \X81\XDF\XE9  \X9C\XDF\XE9  "
14 COLOR1,12:LOCATE6,8:PRINT"\X9BBY DRAGWX             V1.1\X05"
15 LOCATE8,5:PRINT"A SCREEN OF COLORS WILL APPEAR,"
16 LOCATE10,5:PRINT"THEN QUICKLY DISAPPEAR."
17 LOCATE14,5:PRINT"\X9E1\X05 - HOW MANY COLORS WERE THERE?"
18 LOCATE16,5:PRINT"\X9E2\X05 - WHICH COLOR WAS NOT THERE?"
19 LOCATE18,5:PRINT"\X9E3\X05 - WHICH COLOR WAS THERE?"
20 LOCATE20,5:PRINT"\X9E4\X05 - RANDOM QUESTION"
21 LOCATE24,5:PRINT"\X9E5\X05 - EXIT TO BASIC"
22 LOCATE27,5:INPUT"\X9EWHICH GAME TYPE";MT%:ONMT%GOTO31,32,33,34,35
23 GOTO10

31 GT$="HOW MANY COLORS WERE THERE?":GOTO40
32 GT$="WHICH COLOR WAS NOT THERE?":GOTO40
33 GT$="WHICH COLOR WAS THERE?":GOTO40
34 GT$="RANDOM QUESTION":GOTO40
35 COLOR1,12:CLS:END

40 COLOR1,12:CLS
41 LOCATE4,5:PRINTGT$
42 LOCATE14,5:PRINT"\X9E1\X05 - SLOW"
43 LOCATE16,5:PRINT"\X9E2\X05 - MEDIUM"
44 LOCATE18,5:PRINT"\X9E3\X05 - FAST"
45 LOCATE20,5:PRINT"\X9E4\X05 - TURBO!"
46 LOCATE24,5:PRINT"\X9E5\X05 - GO BACK"
47 LOCATE27,5:INPUT"\X9EWHICH SPEED";MS%:ONMS%GOTO51,52,53,54,10
48 GOTO40

51 T=60:GOTO100
52 T=30:GOTO100
53 T=15:GOTO100
54 T=5:GOTO100

100 COLOR1,12:CLS
101 LOCATE14,18:PRINT"READY!"
102 RESTORE:FORA=0TO9:READ C%(A):NEXT
103 FORA=0TO9
104 B=RND(1)*(10-A)+A
105 C=C%(A):C%(A)=C%(B):C%(B)=C
106 NEXT

110 G=INT(RND(1)*15)+5:F=INT(G*(4/3)+0.5)
111 F=319/F:G=239/G:E=INT(RND(1)*5)+2
112 C=F-1:D=G-1:H=320-C:I=240-D

120 RECT0,0,319,239,0
121 FORB=0TOISTEPG:FORA=0TOHSTEPF
122 RECTA,B,A+C,B+D,C%(RND(~)*E):NEXT:NEXT

130 LOCATE16,19:PRINT"-3-":PSGPLAY0,"L48O5C":SLEEPT
131 LOCATE16,19:PRINT"-2-":PSGPLAY0,"L48O5C":SLEEPT
132 LOCATE16,19:PRINT"-1-":PSGPLAY0,"L48O5C":SLEEPT
133 COLOR1,0:CLS:PSGPLAY0,"L24O6C":SLEEPT
134 COLOR1,12:CLS:ONMT%GOTO200,300,400,500

140 LOCATE28,25:PRINT"AGAIN? (Y/N)";
141 LOCATE27,25
142 IFG%=ATHENPRINT"YOU GOT IT! ";:PSGPLAY0,"O5L24CEG>L12C"
143 IFG%<>ATHENPRINT"TOO BAD...  ";:PSGPLAY0,"O2L6C"

150 GETA$:IFA$="Y"THEN100
151 IFA$="N"THEN10
152 GOTO150

200 LOCATE14,8:PRINT"HOW MANY COLORS WERE THERE?"
201 G%=0:LOCATE16,18:INPUTG%
202 IFG%<1THEN201
203 COLOR1,0:CLS:COLOR1,11
204 LOCATE27,5:PRINT"ACTUAL:"; E
205 LOCATE28,5:PRINT" GUESS:"; G%;
206 A=E:GOTO140

300 RECT28,204,E*16+51,227,11
301 A=INT(RND(1)*(E+1))
302 FORB=0TOE
303 IFB<ATHENC=C%(B)
304 IFB=ATHENC=C%(E)
305 IFB>ATHENC=C%(B-1)
306 RECTB*16+33,209,B*16+46,222,C
307 LOCATE26,B*2+4:PRINTB+1;
308 NEXT
309 LOCATE14,8:PRINT"WHICH COLOR \X12WAS NOT\X92 THERE?"
310 COLOR1,0:LOCATE27,5:PRINTRPT$(32,E*2+2);
311 LOCATE28,5:PRINTRPT$(32,E*2+2);:COLOR1,12
312 A=A+1:G%=0
313 LOCATE16,18:INPUTG%
314 IFG%<1THEN313
315 IFG%>E+1THEN313
316 COLOR1,0:CLS:COLOR1,11
317 LOCATE26,G%*2+3:PRINT"X";
318 LOCATE26,A*2+3:PRINTRIGHT$(STR$(A),1);
319 GOTO140

400 RECT28,204,(8-E)*16+51,227,11
401 A=INT(RND(1)*(9-E))
402 FORB=0TO8-E
403 IFB<ATHENC=C%(E+B)
404 IFB=ATHENC=C%(RND(1)*E)
405 IFB>ATHENC=C%(E+B-1)
406 RECTB*16+33,209,B*16+46,222,C
407 LOCATE26,B*2+4:PRINTB+1;
408 NEXT
409 E=8-E
410 LOCATE14,10:PRINT"WHICH COLOR WAS THERE?"
411 GOTO 310

500 A=INT(RND(1)*3)+1
501 ONAGOTO200,300,400

---- Older versions ----

-- V1.0 (attached as COLORGUESS.BAS) --
Try It Now!


---- Other Remarks ----

This is screen mode 128, and I'm using the text layer to mask the graphics layer.
The color select window is drawn on the graphics layer and a transparent "hole" is cut out of the text layer to show it, because the graphics layer is 256 colors, but the text layer is 16-color only (or else the masking effect won't work).
I really struggle when there's 5 or more colors on the screen. :P
Attachments
COLORGUESS-V1-1.BAS
(3.52 KiB) Downloaded 237 times
COLORGUESS.BAS
(2.59 KiB) Downloaded 231 times
DragWx
Posts: 403
Joined: Tue Mar 07, 2023 9:07 pm

Re: Color Guess

Post by DragWx »

I learned that you can put escape codes in untokenized BASIC files, so I spent some time making the menus prettier and adding a third question, "which color was there?", which definitely seems like the hardest of the three, but that might just be because I have a lot of practice with the first two questions. :P

Medium speed seems to be where I top out in terms of consistency. Fast and turbo are pretty fun, but are challenging for me. :D
Post Reply