These exercises are designed for people that are new to programming. The exercices will sharpen you logical thinking.
* : beginner. Very basic
** : more advanced. But still beginner.
*** : normal
**** : harder
***** : Thinkers.
BASIC
1) DBC + DBP :: text practice *
A$ = “hello”
B$ = “world”
Print A$ + B$
Edit the program so, that it will print “hello world” instead of “helloworld” without changing A$ and B$.
2) DBC + DBP :: arrays and rnd() *
Dim numbers(50)
For x = 1 to 50
Next x
Print numbers(x)
Adjust the code, that each array element has to be filled with a random number ranging from !1! to 10. After that, each element has to be displayed, and not only the last one, like this program.
3) DBC + DBP :: Functions *
Nr1 = rnd(20)
Nr2 = rnd(20)
Print Add(Nr1, Nr2)
Suspend for key
End
Function Add( Number1, Number2 )
Endfunction Answer
Make the function working. It has to return the sum of the first and the second number.
5) DBC + DBP :: Conditions *
Add a condition. IF the variable A is smaller than 10 THEN display the text “The value is smaller than 10”. ELSE display the text “The value is greater than 10”.
6) DBC :: doubles **
DBP-users can do this exercise too, but they will have to handle inaccurate values.
A = rnd(20)
B = rnd(20)
C = A + B
Print C
Change the code that everything has to be changes so that it are doubles. A and B have to be ranging from 0.0 to 20.0 (so 19.1 or 12.7 are possibilities).
7) DBC + DBP :: input + answer with cases **
No code this time.
- 1 - **
Create a code, that will ask you
“How do you feel today? (1 = good, 2 = normal, 3 = bad)”.
You have to input 1, 2, 3. By using cases, the, program has to answer
“Hey I feel great too!” for 1,
“Nothing special then…” for 2,
“Cheer up! Live while you can.”
For 3 and for everything else, “What did you say?” and restart the program.
- 2 – **(*)
Code a program that:
Asks the first number.
Asks the second number.
Ask the operator (*, /, +, -). (no numbers!)
Using cases, you calculate the solution. When the user gives a invalid operator name, you have to give an error message, and restart just before you asked the operator. (Not the entire program).
Finally, you display the answer to the screen.
8) DBC + DBP :: timer text function ***
(By phaelax)
Make a function
teletype(txt$, starttime, interval). the function will return a string. It has to look like the computer is typing by itself. The txt$ is the complete text, the starttime is the timer where it started, and interval is the milliseconds between each character.
-- Try and beat Phaelax' function of 5 lines including function and endfunction --
TEXT
1) DBC + DBP :: text *
Ink rgb(250,250,0),0
X = 320
Y = 240
Do
Text X, Y, ”The text”
Loop
What you have to get, is text, jumping around to the screen. When you succeed, you can try to add changing the color jumping too.
2) DBC + DBP :: Buttons ****
Make a function that creates a button: button(x,y,text$). Only the text may be displayed and all sorts of text has to be able to fit in this function. Set text font and set text size may not affect the working of this function. The color has to changes when the mouse hovers over the text, and return a 1 when user clicked on the text.
Colors are free choices.
3) DBC + DBP :: Text commands **
Input “What’s your name? “, name$
Add to the code:
Display the ASCII numbers of each letter beneath each other.
Display the 3 last letters of the name.
Display the 3 first letters of the name.
Display the name in capital letters.
Display the name in lowercase letters.
4) DBP :: Fonts *
Make user input a font. Repeat this program and ask the same question in the previous inputted font. Start with the font “Arial”.
INPUT
1) DBC + DBP :: Basic keys *
Sync on
X = 320
Y = 240
Do
Circle X,Y,5
Sync
loop
Add to this program:
- The ability to move the circle using the up/down/left or right arrow keys.
- Using control you can adjust the circle place by mouse.
2) DBC + DBP :: Mouse control **
Make a program that draws boxes on the screen. The user has to drag a box and you have to render all boxes the user created. You don’t have to add clicking/deleting boxes.
All boxes have to be rendered to the screen every loop.
3) DBC + DBP :: Clipboard *
Make a program that will ask the user to input their name. Then write it to the clipboard and quit the program. See if it works by pressing Crtl + V in an editor like notepad or word.
4) DBC(enhanced) + DBP :: Editor ***** !!!
Make a program that will let the user input text without using the “input a$” command.
There are certain rules for this challenge:
- The user has to be able to type up to 100 lines
- The user can navigate between the lines by pressing the arrow keys. When at the start of a line and left key is pressed, the cursor goes to the end of the previous line. When at end of line and right key is pressed, go to the start of next line.
- A carriage return will let the user go to the end of the next line (not the same effect as down key), and will not add itself to the text.
- The backspace has to do what it is supposed to, such as the delete key.
- When pressing tab, the program has to add 3 spaces instead.
- All text has to be offset 5px to the right.
- You have to be able to scroll.
- The current line and position has to be marked with a flickering “_”.
- You have to be able to edit text at the start, in the text or at the end.
- Colors are free choices.
Tip: Look over the internet for an ASCII table.
FILE
1) DBC + DBP :: File list *
Make a list of all files in the current directory.
If the user presses any key, go to the parent folder, clear screen and display a list of the files in this parent directory.
TIP: “..” is the string that let you go to the parent folder.
2) DBC + DBP :: Reading and writing **
Imagine you have a game and you want to save your progress. The values that have to be stored are:
Name$ (players name) “The Hero”
Posx# (players x position) 502.53
Posy# (players y position) 10.65
Posz# (players z position) 842.94
Angy# (players y angle) 356.72
Level (players level) 17
After this, make another program in the same directory that will load and display these values on the screen. The name of the file is free to choose.
3) DBC + DBP :: File browser ***(*)
Make a file browser. A list of clickable buttons (see the button challenge). The user has to be able to browse through windows.
Changing drives isn’t necessary.
If you want to earn your fourth start, make a browser that – apart from browsing – also can open models, images, music and sounds.
Models can be rotated freely (controls are free choices)
Images can be scrolled, resized and rotated.
Music and sounds can be played, paused and resumed. Volume control for sounds(and in DBP also for music).
DISPLAY
1) DBC + DBP :: Most used commands *
This is very easy
Make a program that displays any text in the exact middle of the screen. In any display mode.
2) DBC + DBP :: Short example *(*)
Just to make you familiar with the window commands of DB.
First: Change the window title to “Window command test”. Turn the window on.
Make a checklist for display modes and display it on the screen.
Second: Hide the window and wait 2 seconds.
Third: Show window and wait 2 seconds.
Fourth: Minimize window and wait 2 seconds
Fifth: Maximize the window and wait 2 seconds
At least: turn the window off.
BASIC 2D
1) DBP + DBC :: Color picker **
DBP: Make a box with in the left-top corner a white color, in the right-top corner a red color, in the right-bottom color a green color and in the left-bottom corner a blue color size 200 on 200.
DBC: Copy this image to your computer and paste the image on the screen in DBC.
Make a color picker, detect the color under the mouse position and display the red, green and blue values separately.
2) DBC + DBP :: Math circle 1 **
(Variation on Math circle)
Make a function to draw a circle. Only use the dot command.
(Try to make an ellipse afterwards)
Goniometry needed!
3) DBC + DBP :: Math circle ***
By Phaelax
Make a function to draw a circle. Simple? You’re not allowed to use the circle command, only line.
Step 2: Use only boxes.
4) DBC + DBP :: Rounded box ***(*)
Originally by Antidote
Make a function for a box with rounded corners.
The color can be adjusted externally, since the function will only draw 2D commands.
-- Personal note: Try and beat my function of 5 lines, 1 command each line. (including function and endfunction) --
5) DBC + DBP :: N polygon function ****(*)
(By phaelax)
Make a function that will draw a N-polygon.
polygon(n, side)
For example, an octagon has 8 sides and each side has to be the size of 10, the function will look like this:
polygon(8, 10).
When you've done the circle challenge, this will be easy, but the real challenge will be: make the polygon filled.
BITMAP
1) DBC + DBP :: Introduction *
Bitmap commands are very slow. Which means it’s not used very much.
Draw 10 randomized boxes on the screen. (bitmap 0).
Wait 2 seconds, flip the bitmap
Wait 2 seconds, flip the bitmap back and mirror the bitmap
Wait 2 seconds, blur the bitmap 3 times.
Wait 2 seconds and quit program.
SOUNDS
1) DBC + DBP :: Sounds *
Load any sound you like. Loop it until the user hits a key.
2) DBC + DBP :: Sound control *
Load any sound you like, and keep looping it.
Increase the speed of the sound with the upkey, decrease the speed with the downkey.
Move the sound pan to the left using the leftkey, move the sound pan to the right using the rightkey.
Try to add boundries.
3) DBC + DBP :: Sounds, sounds and sounds *
Load any sound you like.
Duplicate the sound(without reloading it) 8 times.
Make each sound respond to 1 of the numeric keys (1-2-3-4-5-6-7-8-9).
TIP: No scancode or inkey, because this only takes 1 key at a time. Different keys can be played simultaneously.
4) DBC + DBP :: Media player ***
Make a little media player:
Load any sound you like.
Make 3 buttons: play, stop, pause/resume depending on what state it is now.
Make a volume slider. Real time volume control.
- - - - - - - - - - - - - - - - - - - - -
More exercices will come, when this thread becomes succesful.
Please do not post the answers or parts of answers in this thread. However, questions are always welcome.
If you would like to know if it is correct, mail me at svenboulanger(AT)hotmail.com
Immunity and Annihalation makes Immunihalation...