New game for the QL

Anything QL Software or Programming Related.
FrancoisLanciault
Trump Card
Posts: 167
Joined: Mon Aug 08, 2011 11:08 pm

New game for the QL

Post by FrancoisLanciault »

I there,

Some of you might know the game "2048" available for various mobile devices. It is a simple yet VERY addictive game where you shuffle numbers around a board. So when I came back from work I decided to write a version for the QL. So 6 hours later there it is!

The game consist of a 4x4 bord with tiles. The object of the game is to reach a value of 2048 on one of the tiles. You can move your tiles in any four direction with the cursor keys. Every time you send the tiles in a given direction, they all accumulate to the opposite wall BUT if two tiles next to each other have the same number, they will merge and the resulting value will be the sum of both. Each time you make a move however, a new tile with a value of 2 or 4 (may more 2 than 4) is added to the board. The game is over when there no room on the board for a new tile.

This game is VERY addictive as I said, so I can't be held responsible if you loose your job because you don't show up anymore, or your wife decide to leave you for someone else etc etc.

I don't know how to send to BASIC program to the list, so here is the complete listing. It is not too long so someone motivated can re-type it. Or I guest many will find a way to copy and past it in their preferred emulator. The game should work on any QL, even an unexpended one. This is a quick and dirty job with no frills. Also the code is far from elegant. Let me know if you find any bug!

I will also post this mail on the QL forum, if I can remember my password. So don't be surprised to see it there also.


Have fun!

By the way, my best score is 71524 with a tile of 4096, another of 2048 and various other lower value ones. Try to beat me but no cheat!


100 REMark 2048 for the Sinclair QL
105 MODE 8
110 WINDOW 512,256,0,0:PAPER 2:CLS
120 WINDOW 206,202,(512-206)/2,4
125 OPEN#3,scr_150x200a0x0
127 PAPER#3,2:CLS#3
130 CSIZE#3,3,1:INK#3,1:PRINT#3;" 2048 "
140 INK#3,0:CSIZE#3,2,0
150 BORDER 2,0:PAPER 0:CLS
160 DIM b(4,4):score=0:numt=0
170 draw_board
190 w=add_number:w=add_number
200 REPeat game_loop
210 moved=0
220 IF w=16 && check_game_over THEN EXIT game_loop
230 r=CODE(INKEY$(-1))
240 SELect ON r
250 ON r=192 : a=2:c=4:d=-1:sleftright
260 ON r=200 : a=3:c=1:d=1:sleftright
270 ON r=208 : a=2:c=4:d=-1:supdown
280 ON r=216 : a=3:c=1:d=1:supdown
290 END SELect
300 IF moved=0 THEN NEXT game_loop
310 draw_board
320 w=add_number
330 END REPeat game_loop
340 PRINT#3;"Game Over"
350 STOP
360 DEFine FuNction add_number
380 REPeat loop
390 x=RND(1 TO 4)
400 y=RND(1 TO 4)
410 IF b(y,x)=0 THEN EXIT loop
420 END REPeat loop
430 numt=numt+1
440 b(y,x) = 2*(RND>.9)+2
460 STRIP 6:INK 0
470 FOR i=1 TO 3
480 BLOCK 48,48,(x-1)*50,(y-1)*50,0
490 PAUSE 3
500 BLOCK 48,48,(x-1)*50,(y-1)*50,6
510 v$=b(y,x)
520 CURSOR (x-1)*50+20-LEN(v$)*5,(y-1)*50+13
530 PRINT v$;
540 PAUSE 3
550 END FOR i
560 RETurn numt
570 END DEFine add_number
580 REMark
590 DEFine PROCedure sleftright
600 FOR y=1 TO 4
610 FOR x=a TO c STEP -d
620 v=b(y,x)
630 IF v<>0
640 dx=x+d
650 REPeat loop
660 dest=b(y,dx)
670 IF dest <> 0 || dx=a+d THEN EXIT loop
680 dx=dx+d:moved=1
690 END REPeat loop
700 SELect ON dest
710 ON dest=0 : b(y,dx)=v:b(y,x)=0:moved=1
720 ON dest=v : b(y,dx)=-2*v:b(y,x)=0:score=score+2*v:numt=numt-1:moved=1
730 ON dest=REMAINDER : b(y,x)=0:b(y,dx-d)=v
740 END SELect
750 END IF
760 END FOR x
770 FOR x=1 TO 4:b(y,x)=ABS(b(y,x))
780 END FOR y
790 END DEFine sleftright
800 REMark slide updown
810 DEFine PROCedure supdown
820 FOR x=1 TO 4
830 FOR y=a TO c STEP -d
840 v=b(y,x)
850 IF v<>0 THEN
860 dy=y+d
870 REPeat loop
880 dest=b(dy,x)
890 IF dest <> 0 || dy=a+d THEN EXIT loop
900 dy=dy+d:moved=1
910 END REPeat loop
920 SELect ON dest
930 ON dest=0 : b(dy,x)=v:b(y,x)=0:moved=1
940 ON dest=v : b(dy,x)=-2*v:b(y,x)=0:score=score+2*v:numt=numt-1:moved=1
950 ON dest=REMAINDER : b(y,x)=0:b(dy-d,x)=v
960 END SELect
970 END IF
980 END FOR y
990 FOR y=1 TO 4:b(y,x)=ABS(b(y,x))
1000 END FOR x
1010 END DEFine supdown
1020 DEFine PROCedure draw_board
1030 CSIZE 2,1
1060 FOR y=1 TO 4
1070 FOR x=1 TO 4
1080 IF b(y,x)<>0
1090 color=6-INT(LOG10(b(y,x)^1.5)):INK 0
1100 ELSE
1110 color=7:INK 7
1120 END IF
1130 STRIP color
1140 BLOCK 48,48,(x-1)*50,(y-1)*50,color
1150 v$=b(y,x)
1160 CURSOR (x-1)*50+20-LEN(v$)*5,(y-1)*50+13
1170 PRINT v$;
1180 END FOR x
1200 END FOR y
1210 AT#3,4,0:PRINT#3;"Score: ";score
1220 END DEFine draw_board
1230 DEFine FuNction check_game_over
1235 LOCal g_o
1237 g_o=1
1240 FOR j=1 TO 4
1250 FOR i=1 TO 3
1260 IF b(j,i)=b(j,i+1) THEN g_o=0
1270 END FOR i
1280 END FOR j
1285 FOR i=1 TO 4
1287 FOR j=1 TO 3
1288 IF b(j,i)=b(j+1,i) THEN g_o=0
1289 END FOR j
1290 END FOR i
1295 RETurn g_o
1300 END DEFine check_game_over


FrancoisLanciault
Trump Card
Posts: 167
Joined: Mon Aug 08, 2011 11:08 pm

Re: New game for the QL

Post by FrancoisLanciault »

Quote :

I will also post this mail on the QL forum, if I can remember my password. So don't be surprised to see it there also.

End quote

Obviously I did not change a single word in my previous message when I pasted the one I sent the QL mailing list. What I meant was that this same message was also sent to the QL mailing list.

P.S. I just realized that I did not check if someone had already produced that kind of game for the QL. Sorry if I am late to the party.

François


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: New game for the QL

Post by Mr_Navigator »

Screen Shot
Untitled-1.png
Untitled-1.png (7.34 KiB) Viewed 4903 times


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
User avatar
belg4rion67
Trump Card
Posts: 189
Joined: Sun Feb 20, 2011 6:15 pm
Location: Milan - Italy

Re: New game for the QL

Post by belg4rion67 »

Hi dear,
good job :) it's very nice game and I'm very happy to see this game for our beloved QL
Thank you so much!
Ciao
Paolo


Only original hardware! :)
thorsinclair
Trump Card
Posts: 199
Joined: Mon Jan 10, 2011 5:08 pm

Re: New game for the QL

Post by thorsinclair »

Yes, it's cool and addicting :?

Screenshot of my first try ...

Good job !
tiles.jpg


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: New game for the QL

Post by ppe »

Hi François,

that is a really, really nice implementation of the game! I've been playing it a *lot* on the ipad but it's great to have it on the QL.

Thank you so much for creating this and sharing it, awesome job!!

Edit: Turboed the program and it seems to run at decent speed on an unexpanded QL :)

Cheers,
Petri


FrancoisLanciault
Trump Card
Posts: 167
Joined: Mon Aug 08, 2011 11:08 pm

Re: New game for the QL

Post by FrancoisLanciault »

ppe wrote:Hi François,

that is a really, really nice implementation of the game! I've been playing it a *lot* on the ipad but it's great to have it on the QL.

Thank you so much for creating this and sharing it, awesome job!!

Edit: Turboed the program and it seems to run at decent speed on an unexpanded QL :)

Cheers,
Petri
Was it really too slow running in SuperBasic on a unexpanded QL ? Sure the program could be made to run faster. For example, I decided to redraw the whole board after each move to keep the listing short, but it could be possible to redraw only the tiles that have changed.

Keep posting your high score! Remember you have to beat me ! (Score 71524, larger tile achieved: 4096)

I have never been able to do a 8192, anybody knows if it is possible ?

François


User avatar
belg4rion67
Trump Card
Posts: 189
Joined: Sun Feb 20, 2011 6:15 pm
Location: Milan - Italy

Re: New game for the QL

Post by belg4rion67 »

ppe wrote:Hi François,

that is a really, really nice implementation of the game! I've been playing it a *lot* on the ipad but it's great to have it on the QL.

Thank you so much for creating this and sharing it, awesome job!!

Edit: Turboed the program and it seems to run at decent speed on an unexpanded QL :)

Cheers,
Petri
Hi Petri, what turbo compiler have you used to compile this game? I made an exe file with turbo compiler but it gives me an error
thanks in advance
Paolo


Only original hardware! :)
RWAP
RWAP Master
Posts: 2839
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: New game for the QL

Post by RWAP »

belg4rion67 wrote: Hi Petri, what turbo compiler have you used to compile this game? I made an exe file with turbo compiler but it gives me an error
thanks in advance
Paolo
That is interesting - what error did you get from Turbo?


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: New game for the QL

Post by ppe »

Hi Paolo,

I used the one available on Dilwyn's site - trbop15.zip & trbot13.zip

What kind of an error are you getting?

Best regards,
Petri


Post Reply