You mean something like this?Code: QB64: [Select]
try = try + 1
Pete
- I'm really more of a one-liner kind of guy.
Sure, libraries. For instance, I made a keyboard / mouse routine I can use in any program. Steve has one of a similar nature. I suppose if the community promoted library routines, eventually we would wind up adding OOP support to QB64. The push against that. and count me in as a big pusher, is that the spirit of BASIC is to build these routines, not just utilize them. If the community became divided over such philosophical differences, I would simply recommend doing what PowerBASIC did, simply split the project. Have an OOP version and a BASIC version. In regard to PB, that would be their PowerBASIC for WIndows vs PpwerBASIC for DOS.
Pete
nobody ask me why, but i just made a game in 10 lines. keep your mouse on the money to gain it, otherwise you lose it. your total is in the titleCode: QB64: [Select]
@Pete Wow nice 3 liner!
@STxAxTIC now I know why money doesn't grow on trees, too busy riding down that river. Nice spontaneous game!
Cool... "10 Liners"... Back in the mid 80's I ran an Amstrad CPC464... 4mhz cpu with only 64K of ram... Learning to program efficiently was the thing back then. In the magazines that I purchased were "10 liners". It was amazing, back then, that so much could be done with so little coding. Mind you, the CPC, was capable of having long lines of code... But still... amazing...
I don't like lines extended over to China horizontally because of use of colons but do like these little ditties, with single statements per line. Neither do I like too many single letter variables unless they are obvious like x, y, mx, my, s$ for temp string of text$. I like nice readable short code.
I have an idea for a game library to make writing 10 liners, more or less, easier.
Why waste code on the usual sh... stuff?
For instance the game library could have:Code: QB64: [Select]
Actually that would be the main code and then $Include the 10 liner game.
The full and expanded BASIC listing is:
GRAPHICS 18
? #6;" M*N PUZZLE"
Initializes the screen and prints the game title. Uses standard graphics mode 2 (big text) without normal text window at the bottom, and default colours.
R=120
DIM A$(R),B$(R),D(3),J(15)
S=DPEEK(88)+40
M=4
N=M
A$="."
A$(R)=A$
B$=A$
Initializes constants and variables:
R is the the length of the screen area where the maze will be placed.
S is the memory location of the playfield.
M is the width and N is the height, starting at 4x4.
A$ has a copy of the playfield containing the solved puzzle, and B$ has a copy of the current playfield during the game. Both string variables need to be of the same maximum size R for the string comparison to work.
D() and J() arrays store movement information as follows...
FOR I=0 TO 3
READ D,J
D(I)=D
J(J)=D
NEXT I
DATA -20,13,1,11
DATA -1,7
DATA 20,14
Set up screen deltas for random and joystick movements for all four directions. Graphics mode 2 uses 20 bytes per line, then you have to substract 20 bytes to find the screen position of the piece in the upper side of the current screen position, and add 1 to find the one at the right.
D(0-3) array stores the four deltas for random shufle
J(0-15) store the same four deltas for UP, RIGHT, LEFT and DOWN joystick positions and zero ("dont' move") for the other positions (default values in TurboBASIC XL).
Data instructions were placed at the end of other lines to save space.
WHILE 1
End-less loop...
REPEAT
Begin of the routine to select the size of the puzzle, from 2x2 up to 6x6.
MOVE S, S+1, 199
Clears playfield area.
P = S + 70 - 20*(N DIV 2) - M DIV 2
Finds the upper left position in screen area of the puzzle for the current size of it.
FOR I=0 TO N*M-2
X=P+I+(I DIV M)*(20-M)
POKE X, (33-42*(I>25)+I*65) MOD 256
NEXT I
Draws the puzzle, except the last piece.
X is the screen position of the current piece.
The pieces starts alphabetically from A to Z. In sizes that require more than 26 pieces, numbers 1 to 9 are included, giving 35 pieces for the largest 6x6 mode (including one empty space).
At the same time, it asigns a colour for every piece, obtaining a different pattern based on current puzzle size.
PAUSE 9
Just a pause before accepting a change of the size. If there is no pause, it's possible to change the size two times in just one move.
REPEAT
J=15-STICK(0)
K=1-STRIG(0)
UNTIL J+K
Waits until joystick is moved or button is pressed. Bits are being negated to be more useful: 0=released, 1=pressed for button and one bit per direction for joystick.
IF K=0
M=M+(J&8>0)*(M<6)-(J&4>0)*(M>2)
N=N+(J&2>0)*(N<6)-(J&1>0)*(N>2)
ENDIF
Based on the joystick movement, changes the width and/or height of the puzzle. Diagonal movement is allowed!
M increases by one only if the right bit of the joystick is set and the current size is less than the maximum allowed size, and decreased only if the left bit is set and current size is more than the minimum allowed size. The same for N in the other axis... BTW, all this happens only if the button was not pressed.
UNTIL K
Quits the game setup routine when the button is pressed.
MOVE S,ADR(A$),R
Saves the screen data for the solved puzzle in A$.
X=X+1
Z=X+1
C=N*M*8
Sets the current position as the empty cell in X, the previous position in Z (fake for the first time), and the number of moves required to shuffle the puzzle in C, based on the selected size of the puzzle.
WHILE C
Begin of the shuffling routine.
REPEAT
D=RAND(4)
Y=X+D(D)
Q=PEEK(Y)
UNTIL Q AND Y<>Z
Randomly select a direction to find a piece to be moved to the empty space. Q is the piece, Y is it's position on screen. It shouldn't be the same piece from the previous move.
SOUND 0,20+D*3,8,8
Plays a sound. The tone is based on the selected direction.
POKE Y,0
POKE X,Q
Move the selected piece to the empty position.
Z=X
X=Y
C=C-1
Sets the position of the last moved piece, the new new position of the empty space and decreases the pending move's counter.
WEND
SOUND
End of the shufling routine. Needs to turn off shuffling sound.
REPEAT
Begin of the gameplay routine.
REPEAT
J=STICK(0)
Y=X+J(J)
Q=PEEK(Y)
UNTIL Q
Select the piece to move based on the joystick position. Note that joystick movement is inverted: UP moves the empty space down, i.e. moves up the piece under it. There are no pieces neither in the empty position (joystick in released position) nor outside the puzzle area.
POKE 77,0
Clears the attract mode register. This prevents the change of screen colours while playing, or restore the screen colours after a long pause while playing.
SOUND 0,20+J,8,8
Plays a sound, the tone is based on the joystick position.
POKE Y,0
POKE X,Q
X=Y
Move the selected piece to the empty space and set in X the new position of the empty space.
PAUSE 8
SOUND
Stop the sound after a small pause.
C=C+1
POSITION 9+(C<10),9
? #6;C
Increase and print the count of movements.
WHILE STICK(0)<15
WEND
Waits until joystick is released. No continuous moves in this game.
MOVE S,ADR(B$),R
Copies the current playfield to B$.
UNTIL B$=A$
Compares the current payfield against the solved one. If they match, the game ends.
POSITION 8,11
? #6; "DONE!";
FOR I=0 TO 9
SOUND 0,60-5*I,12,8
PAUSE 4
NEXT I
SOUND
Congratulations! You solved the puzzle. Bells and whistles...
WHILE STRIG(0)
WEND
Wait for the button to be pressed to start again.
WEND
@bplus
I know that you have a lot of imagination maybe you can show us some complete program less than 10 lines or 2 or 3 lines
happy to see you always active
for x=0 to 262144 do pset x%512,x\512,rgb(x%256,(x%512 xor x\512)%256,x\512%256)
Here's Charlie's (who was coloning all over the place):
(SNIP!)
note: This game forces you to put your hands in very awkward position over a, e, i in order to hit letters fast enough.
(SNIP!)
"Coloning" is my expression for using : for multiple statements on single line. I also call it double parking.
@CharlieJV I did not learn typing, what fingers are you suppose to use for a, e and i?
@bplus You have a lot of tricks up your sleeve, but I'll bet DIMming k$ as "LONG" is not one of them. :D
I completely agree about the line challenge and non-use of colons. Every colon is another line, in my opinion. Oh course, characters could be counted, but that's not entirely fair either, as certain keywords are longer than others.
I use the same approach to most of my larger programs. Make a central hub, and run sub-routines from it. This method allowed me to always know the program flow would continuously be cycled through that hub. Back in the old days, it provided a way to time the program, and evoke a screen saver. Other advantages existed, too.
@Dav Speaking of screen savers, in the paragraph above, I would have loved to have the plasma one you posted! Very cool!
@Kiara87 I get it, more of a discussion concerning optimization of BASIC code, rather than the use of BASIC libraries to develop OOP. Most of what I see of a practical aspect of this is the use of creative algorithms, mostly math formulas, like Dav and Bill posted in their 10-liners. The downside of "optimization" when it comes to limiting lines of code, ironically, results in obfuscation, much the same too many lines of convoluted code produce. Use of GOTO statements, for example, to cut down on a loop line code. I consider that bad coding practice, especially to introduce it, in a positive way, to a beginner. I consider BASIC best for coders who like to build things from the foundation up. All I ever heard from C communities is "You need a library for that." That was their response to me trying to write a keyboard function in C. I eventually accomplished it, because it was possible with C/C++ statements, but I was not too happy that such a large community completely lost track of how to build a program from the foundation up.
Pete
PS @Dimster That was just a typo on Mark's part. He was just giving a skeleton, almost pseudo-code, example of how to set up a 10-line hub to run a program. Sorry for the late reply, you posted while I was writing.
Yeah what I am finding is these things are really 100 lines or less:
https://www.vitoco.cl/atari/10liner/MNPUZZLE/
[ This attachment cannot be displayed inline in 'Print Page' view ]
I say make it 100 lines with no colons and get something as enjoyable to read as to play!
That would be way more educational and inspiring for all levels of hobbiests.