// Project: SwapShop // Created: 2020-10-22 // show all errors SetErrorMode(2) // set window properties SetWindowTitle( "SwapShop" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts gosub LoadTheImages //MakelNumbers l numbers are the image number to use in each cell // the l is followed by two numbers px and py, px 1 to 10 for the 10 columns and py 1 to 5 for the 5 rows // like this // ________________________________________ _________________________________________ //| | | | | | | | | | | | //| l11 | l21 | l31 | l41 | l51 | | l61 | l71 | l81 | l91 | l101 | //| | | | | | | | | | | | // ________________________________________ _________________________________________ //| | | | | | | | | | | | //| l12 | l22 | l32 | l42 | l52 | | l62 | l72 | l82 | l92 | l102 | //| | | | | | | | | | | | // ________________________________________ _________________________________________ //| | | | | | | | | | | | //| l13 | l23 | l33 | l43 | l53 | | l63 | l73 | l83 | l93 | l103 | //| | | | | | | | | | | | // ________________________________________ _________________________________________ //| | | | | | | | | | | | //| l14 | l24 | l34 | l44 | l54 | | l64 | l74 | l84 | l94 | l104 | //| | | | | | | | | | | | // ________________________________________ _________________________________________ //| | | | | | | | | | | | //| l15 | l25 | l35 | l45 | l55 | | l65 | l75 | l85 | l95 | l105 | //| | | | | | | | | | | | // ________________________________________ _________________________________________ //make dummy p1$ and p2$ to set up initial sprites p1$="aaaaabbbbbcccccdddddeeeeefffff" p2$="ggggghhhhhiiiiijjjjjkkkkklllll" gosub MakelNumbers //CreateInitialSprites sets up the images to be associated with the 'fixed' sprites gosub CreateInitialSprites CreateText(1,solution1$) SetTextSize(1,35) SetTextPosition(1,10,430) CreateText(2,solution2$) SetTextSize(2,35) SetTextPosition(2,10,450) //gosub SetTheSprites winner=0 gamestate=1 //gamestate= 1 is Intro, 2 is game play, 3 is game completed successfully //may add other gamestate numbers for help screen, do select gamestate case 1 //Intro Screen ClearScreen() print ("Press SPACE to Start") sync() while GetRawKeyState(32)<>1 endwhile gosub LoadThePuzzles //puzzles are two strings p1$ and p2$ p1$=Make21String(p1$) p2$=Make21String(p2$) solution1$=p1$ solution2$=p2$ //now we mix up p1$ and p2$ gosub MixUpPuzzles clearscreen() gamestate=2 winner=0 //THIS SEEMS TO WORK OK endcase case 2 //Gameplay gosub MakelNumbers clearscreen() if lower(p1$)=lower(solution1$) or lower(p1$)=lower(solution2$) then winner=1 while GetPointerState()<>1 gosub SetTheSprites sync() endwhile if winner=1 then sleep(5000) pos=TurnPXandPYIntopos(GetPointerX(),GetPointerY()) if pos<>0 op1$=mid(p1$,pos,1) op2$=mid(p2$,pos,1) np1$="" np2$="" for m=1 to 21 if m=pos then np1$=np1$+op2$ else np1$=np1$+mid(p1$,m,1) if m=pos then np2$=np2$+op1$ else np2$=np2$+mid(p2$,m,1) next p1$=np1$ p2$=np2$ Sleep(150) endif if lower(p1$)=lower(solution1$) or lower(p1$)=lower(solution2$) then gamestate=3 endcase case 3 //Game complete, congratulate and start over clearscreen() gosub MakelNumbers gosub SetTheSprites //I put these in temporarily to show the game has ended complete print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print (" ") print("WELL DONE - Press SPACE to go again") sync() sleep(2000) While GetRawKeyState(32)<>1 endwhile gamestate=1 endcase endselect Sync() loop Function TurnPXandPYIntopos(px,py) pos=0 puzx=0 puzy=0 if px>=10 and px<90 then puzx=1 if px>=90 and px<170 then puzx=2 if px>=170 and px<250 then puzx=3 if px>=250 and px<330 then puzx=4 if px>=330 and px<410 then puzx=5 if px>=430 and px<510 then puzx=1 if px>=510 and px<590 then puzx=2 if px>=590 and px<670 then puzx=3 if px>=670 and px<750 then puzx=4 if px>=750 and px<830 then puzx=5 if py>=10 and py<90 then puzy=1 if py>=90 and py<170 then puzy=2 if py>=170 and py<250 then puzy=3 if py>=250 and py<330 then puzy=4 if py>=330 and py<410 then puzy=5 if puzx=1 and puzy=1 then pos=1 if puzx=2 and puzy=1 then pos=2 if puzx=3 and puzy=1 then pos=3 if puzx=4 and puzy=1 then pos=4 if puzx=5 and puzy=1 then pos=5 if puzx=1 and puzy=2 then pos=6 if puzx=2 and puzy=2 then pos=0 if puzx=3 and puzy=2 then pos=7 if puzx=4 and puzy=2 then pos=0 if puzx=5 and puzy=2 then pos=8 if puzx=1 and puzy=3 then pos=9 if puzx=2 and puzy=3 then pos=10 if puzx=3 and puzy=3 then pos=11 if puzx=4 and puzy=3 then pos=12 if puzx=5 and puzy=3 then pos=13 if puzx=1 and puzy=4 then pos=14 if puzx=2 and puzy=4 then pos=0 if puzx=3 and puzy=4 then pos=15 if puzx=4 and puzy=4 then pos=0 if puzx=5 and puzy=4 then pos=16 if puzx=1 and puzy=5 then pos=17 if puzx=2 and puzy=5 then pos=18 if puzx=3 and puzy=5 then pos=19 if puzx=4 and puzy=5 then pos=20 if puzx=5 and puzy=5 then pos=21 //print (pos) endfunction pos function GetPos2Low(pos) pos2=0 if pos=1 then pos2=16 if pos=3 then pos2=21 if pos=5 then pos2=26 if pos=6 then pos2=18 if pos=8 then pos2=23 if pos=10 then pos2=28 if pos=11 then pos2=20 if pos=13 then pos2=25 if pos=15 then pos2=30 endfunction pos2 function GetPos2High(pos) pos2=0 if pos=16 then pos2=11 if pos=21 then pos2=23 if pos=26 then pos2=5 if pos=18 then pos2=6 if pos=23 then pos2=8 if pos=28 then pos2=10 if pos=20 then pos2=11 if pos=25 then pos2=13 if pos=30 then pos2=15 endfunction pos2 function Make21String(aq$) ret$=mid(aq$,1,1)+mid(aq$,2,1)+mid(aq$,3,1) ret$=ret$+mid(aq$,4,1)+mid(aq$,5,1)+mid(aq$,17,1) ret$=ret$+mid(aq$,22,1)+mid(aq$,27,1)+mid(aq$,6,1) ret$=ret$+mid(aq$,7,1)+mid(aq$,8,1)+mid(aq$,9,1) ret$=ret$+mid(aq$,10,1)+mid(aq$,19,1)+mid(aq$,24,1) ret$=ret$+mid(aq$,29,1)+mid(aq$,11,1)+mid(aq$,12,1) ret$=ret$+mid(aq$,13,1)+mid(aq$,14,1)+mid(aq$,15,1) endfunction ret$ function RandomMixNumber(seed) mf1=OpenToRead("Random.dat") for m=1 to random2(2,35421) num1=ReadInteger(mf1) next numb$=bin(num1) mix$=right(numb$,21) CloseFile(mf1) //print (mix$) //seems to work fine endfunction mix$ CreateInitialSprites: CreateSprite(1,1) CreateSprite(2,l11) CreateSprite(3,l21) CreateSprite(4,l31) CreateSprite(5,l41) CreateSprite(6,l51) CreateSprite(7,l12) CreateSprite(8,l22) CreateSprite(9,l32) CreateSprite(10,l42) CreateSprite(11,l52) CreateSprite(12,l13) CreateSprite(13,l23) CreateSprite(14,l33) CreateSprite(15,l43) CreateSprite(16,l53) CreateSprite(17,l14) CreateSprite(18,l24) CreateSprite(19,l34) CreateSprite(20,l44) CreateSprite(21,l54) CreateSprite(22,l15) CreateSprite(23,l25) CreateSprite(24,l35) CreateSprite(25,l45) CreateSprite(26,l55) CreateSprite(27,l61) CreateSprite(28,l71) CreateSprite(29,l81) CreateSprite(30,l91) CreateSprite(31,l101) CreateSprite(32,l62) CreateSprite(33,l72) CreateSprite(34,l82) CreateSprite(35,l92) CreateSprite(36,l102) CreateSprite(37,l63) CreateSprite(38,l73) CreateSprite(39,l83) CreateSprite(40,l93) CreateSprite(41,l103) CreateSprite(42,l64) CreateSprite(43,l74) CreateSprite(44,l84) CreateSprite(45,l94) CreateSprite(46,l104) CreateSprite(47,l65) CreateSprite(48,l75) CreateSprite(49,l85) CreateSprite(50,l95) CreateSprite(51,l105) CreateSprite(52,35) //CreateSprite(53,34) return MakelNumbers: l11=asc(lower(mid(p1$,1,1)))-95 l21=asc(lower(mid(p1$,2,1)))-95 l31=asc(lower(mid(p1$,3,1)))-95 l41=asc(lower(mid(p1$,4,1)))-95 l51=asc(lower(mid(p1$,5,1)))-95 l12=asc(lower(mid(p1$,6,1)))-95 l22=28 l32=asc(lower(mid(p1$,7,1)))-95 l42=29 l52=asc(lower(mid(p1$,8,1)))-95 l13=asc(lower(mid(p1$,9,1)))-95 l23=asc(lower(mid(p1$,10,1)))-95 l33=asc(lower(mid(p1$,11,1)))-95 l43=asc(lower(mid(p1$,12,1)))-95 l53=asc(lower(mid(p1$,13,1)))-95 l14=asc(lower(mid(p1$,14,1)))-95 l24=30 l34=asc(lower(mid(p1$,15,1)))-95 l44=31 l54=asc(lower(mid(p1$,16,1)))-95 l15=asc(lower(mid(p1$,17,1)))-95 l25=asc(lower(mid(p1$,18,1)))-95 l35=asc(lower(mid(p1$,19,1)))-95 l45=asc(lower(mid(p1$,20,1)))-95 l55=asc(lower(mid(p1$,21,1)))-95 l61=asc(lower(mid(p2$,1,1)))-95 l71=asc(lower(mid(p2$,2,1)))-95 l81=asc(lower(mid(p2$,3,1)))-95 l91=asc(lower(mid(p2$,4,1)))-95 l101=asc(lower(mid(p2$,5,1)))-95 l62=asc(lower(mid(p2$,6,1)))-95 l72=32 l82=asc(lower(mid(p2$,7,1)))-95 l92=31 l102=asc(lower(mid(p2$,8,1)))-95 l63=asc(lower(mid(p2$,9,1)))-95 l73=asc(lower(mid(p2$,10,1)))-95 l83=asc(lower(mid(p2$,11,1)))-95 l93=asc(lower(mid(p2$,12,1)))-95 l103=asc(lower(mid(p2$,13,1)))-95 l64=asc(lower(mid(p2$,14,1)))-95 l74=28 l84=asc(lower(mid(p2$,15,1)))-95 l94=29 l104=asc(lower(mid(p2$,16,1)))-95 l65=asc(lower(mid(p2$,17,1)))-95 l75=asc(lower(mid(p2$,18,1)))-95 l85=asc(lower(mid(p2$,19,1)))-95 l95=asc(lower(mid(p2$,20,1)))-95 l105=asc(lower(mid(p2$,21,1)))-95 return SetTheSprites: //SetSpritePosition(SpriteNumber,x,y) SpriteNumber is fixed, it's image is defined in ANOTHER GOSUB SetSpriteImage(2,l11) SetSpriteImage(3,l21) SetSpriteImage(4,l31) SetSpriteImage(5,l41) SetSpriteImage(6,l51) SetSpriteImage(7,l12) SetSpriteImage(8,l22) SetSpriteImage(9,l32) SetSpriteImage(10,l42) SetSpriteImage(11,l52) SetSpriteImage(12,l13) SetSpriteImage(13,l23) SetSpriteImage(14,l33) SetSpriteImage(15,l43) SetSpriteImage(16,l53) SetSpriteImage(17,l14) SetSpriteImage(18,l24) SetSpriteImage(19,l34) SetSpriteImage(20,l44) SetSpriteImage(21,l54) SetSpriteImage(22,l15) SetSpriteImage(23,l25) SetSpriteImage(24,l35) SetSpriteImage(25,l45) SetSpriteImage(26,l55) SetSpriteImage(27,l61) SetSpriteImage(28,l71) SetSpriteImage(29,l81) SetSpriteImage(30,l91) SetSpriteImage(31,l101) SetSpriteImage(32,l62) SetSpriteImage(33,l72) SetSpriteImage(34,l82) SetSpriteImage(35,l92) SetSpriteImage(36,l102) SetSpriteImage(37,l63) SetSpriteImage(38,l73) SetSpriteImage(39,l83) SetSpriteImage(40,l93) SetSpriteImage(41,l103) SetSpriteImage(42,l64) SetSpriteImage(43,l74) SetSpriteImage(44,l84) SetSpriteImage(45,l94) SetSpriteImage(46,l104) SetSpriteImage(47,l65) SetSpriteImage(48,l75) SetSpriteImage(49,l85) SetSpriteImage(50,l95) SetSpriteImage(51,l105) SetSpriteImage(52,35) //SetSpriteImage(53,34) //Well Done SetSpritePosition(1,0,0) SetSpritePosition(2,10,10) SetSpritePosition(3,90,10) SetSpritePosition(4,170,10) SetSpritePosition(5,250,10) SetSpritePosition(6,330,10) SetSpritePosition(7,10,90) SetSpritePosition(8,90,90) SetSpritePosition(9,170,90) SetSpritePosition(10,250,90) SetSpritePosition(11,330,90) SetSpritePosition(12,10,170) SetSpritePosition(13,90,170) SetSpritePosition(14,170,170) SetSpritePosition(15,250,170) SetSpritePosition(16,330,170) SetSpritePosition(17,10,250) SetSpritePosition(18,90,250) SetSpritePosition(19,170,250) SetSpritePosition(20,250,250) SetSpritePosition(21,330,250) SetSpritePosition(22,10,330) SetSpritePosition(23,90,330) SetSpritePosition(24,170,330) SetSpritePosition(25,250,330) SetSpritePosition(26,330,330) SetSpritePosition(27,430,10) SetSpritePosition(28,510,10) SetSpritePosition(29,590,10) SetSpritePosition(30,670,10) SetSpritePosition(31,750,10) SetSpritePosition(32,430,90) SetSpritePosition(33,510,90) SetSpritePosition(34,590,90) SetSpritePosition(35,670,90) SetSpritePosition(36,750,90) SetSpritePosition(37,430,170) SetSpritePosition(38,510,170) SetSpritePosition(39,590,170) SetSpritePosition(40,670,170) SetSpritePosition(41,750,170) SetSpritePosition(42,430,250) SetSpritePosition(43,510,250) SetSpritePosition(44,590,250) SetSpritePosition(45,670,250) SetSpritePosition(46,750,250) SetSpritePosition(47,430,330) SetSpritePosition(48,510,330) SetSpritePosition(49,590,330) SetSpritePosition(50,670,330) SetSpritePosition(51,750,330) SetSpritePosition(52,GetPointerX(),GetPointerY()) //SetSpritePosition(53,2000,2000) return LoadTheImages: loadimage(1,"Background.png") LoadImage(2,"A.png") LoadImage(3,"B.png") LoadImage(4,"C.png") LoadImage(5,"D.png") LoadImage(6,"E.png") LoadImage(7,"F.png") LoadImage(8,"G.png") LoadImage(9,"H.png") LoadImage(10,"I.png") LoadImage(11,"J.png") LoadImage(12,"K.png") LoadImage(13,"L.png") LoadImage(14,"M.png") LoadImage(15,"N.png") LoadImage(16,"O.png") LoadImage(17,"P.png") LoadImage(18,"Q.png") LoadImage(19,"R.png") LoadImage(20,"S.png") LoadImage(21,"T.png") LoadImage(22,"U.png") LoadImage(23,"V.png") LoadImage(24,"W.png") LoadImage(25,"X.png") LoadImage(26,"Y.png") LoadImage(27,"Z.png") LoadImage(28,"28.png") LoadImage(29,"29.png") LoadImage(30,"30.png") LoadImage(31,"31.png") LoadImage(32,"32.png") LoadImage(33,"33.png") LoadImage(34,"WellDone.png") LoadImage(35,"pointer1.png") return LoadThePuzzles: //p1$="aaaaabbbbbcccccdddddeeeeefffff" //p2$="uuuuuvvvvvwwwwwxxxxxyyyyyzzzzz" file=OpenToRead("5x5puzzles.txt") gp1=random2(0,999999) gp2=random2(0,999999) SetFilePos(file,gp1*32) p1$="" for n=1 to 30 p1$=p1$+chr(ReadByte(file)) next SetFilePos(file,gp2*32) p2$="" for n=1 to 30 p2$=p2$+chr(ReadByte(file)) next closefile(file) return MixUpPuzzles: mix$=RandomMixNumber(Random2(1,1000000)) np1$="" np2$="" for n=1 to 21 op1$=mid(p1$,n,1) op2$=mid(p2$,n,1) if mid(mix$,n,1)="1" then np1$=np1$+op2$ else np1$=np1$+mid(p1$,n,1) if mid(mix$,n,1)="1" then np2$=np2$+op1$ else np2$=np2$+mid(p2$,n,1) next p1$=np1$ p2$=np2$ return