/' ************************************* * HI-LO GAME by Brian Turner * * v3.0 * * zxbc -TaB --strict-bool hilo3.bas * ************************************* '/ #include #include 'randomize const TRUE as ubyte=1 const FALSE as ubyte=0 const MAXCARD as ubyte=51 const SPACE as string=" " dim pack(MAXCARD) as ubyte dim cardno,slotno as ubyte dim score,hi,play,correct as ubyte dim suit,face as ubyte dim udg(4,7) as ubyte=>{{60,60,219,231,231,219,24,24}, _ {24,60,126,255,255,126,60,24}, _ {102,255,255,255,126,60,24,24}, _ {24,60,126,255,255,219,24,60}, _ {0,78,209,81,81,81,78,0}} poke uinteger 23675,@udg(0,0) dim i,prev as integer dim suits,faces,response as string '*** initialise suits="\A\B\C\D" 'clubs, diamonds, hearts, spades faces="A23456789\EJQK" play=TRUE score=0 hi=0 for i=0 to MAXCARD pack(i)=i next i '*** main loop do '*** new game randomize cardno=0 slotno=0 score=0 correct=TRUE response="" shuffle() deal() centre(11,"LOWEST=A, HIGHEST=K") pause 100 do '*** game play loop bright 0:paper 4:ink 0 print paper 0;ink 7;bright 0;at 0,19;score;at 0,27;hi print at 11,0;SPACE drawcard(cardno,slotno) if response<>"" then if (response="H" and face>prev) or (response="L" and face < prev) then centre(11,"CORRECT!") pause 50 correct=TRUE score=score+1 else centre(11,"WRONG!") pause 50 if score>hi then hi=score correct=FALSE end if end if if cardno=MAXCARD then centre(11,"DECK CLEARED!") pause 150 correct=FALSE exit do end if if correct then print at 11,1;"Next card ";inverse 1;"H";inverse 0;"I or ";inverse 1;"L";inverse 0;"O? "; do response=ucase(input(1)) loop until (response="H" or response="L") prev=face cardno=cardno+1 slotno=slotno+1 end if if slotno=10 then deal() slotno=0 end if loop until not correct print at 11,1;"Play another game? "; response=ucase(input(1)) if response<>"Y" then play=FALSE else play=TRUE response="" randomize shuffle() end if loop until play=FALSE end '** SUBS and FUNCTIONS - "dim" variables here are LOCAL to sub/func '** draw cards on screen sub drawcard(card as ubyte,slot as ubyte) dim cx,cy,adj as ubyte ink 1:paper 7:bright 1 cy=(int(slot/5))*10+3 adj=slot if slot >= 5 then adj=slot - 5 cx=adj*6+1 print at cy,cx;"\:'\''\''\''\':" for i=1 to 5 print at cy+i,cx;"\: \ :" next i print at cy+6,cx;"\:.\..\..\..\.:" if card<>99 then suit=int(pack(card)/13) face=pack(card) mod 13 print at cy+3,cx+2;ink 0;faces(face) adj=0 if suit=1 or suit=2 then adj=2 print at cy+1,cx+1;ink adj;suits(suit) end if ink 0:paper 4:bright 0 end sub '** initial screen sub deal() dim cn,total as ubyte bright 0:paper 4:ink 0:border 1:cls print paper 0;at 0,0;SPACE;at 22,0;SPACE print at 0,13;paper 0;ink 7;"SCORE:";at 0,22;"HIGH:" print at 0,2;paper 0;ink 7;bright 1;italic 1;"HI-LO GAME" print at 22,6;paper 0;ink 7;"\* Brian Turner 2025" for cn=0 to 9 total=cn+cardno if total<=MAXCARD then drawcard(99,cn) next cn end sub '** shuffle array with card values sub shuffle() dim c1,c2,c3 as integer centre(11,"SHUFFLING ....") for c1=MAXCARD to 0 step -1 c2=int(rnd*c1+1) if c2<>c1 then c3=pack(c2) pack(c2)=pack(c1) pack(c1)=c3 end if next c1 end sub sub centre(row as ubyte,txt as string) dim sl as ubyte sl=int(len(txt)/2) print at row,0;SPACE;at row,16-sl;txt end sub