#### Archived

This topic is now archived and is closed to further replies.

# VB programming

This topic is 5072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am tring to create the game Abalone using visual basic 6. I am using picture boxes as a control array for the board. To move the pieces on the board I am using the drag and drop method. Can anyone help me with moving through the array? How do I know when a piece is moved on the board?

##### Share on other sites
First, you''ve started on the wrong foot. Back up and go back to an empty form, buddy. Trust me here, I''ve been working with VB for nearly a decade, and VB 6 since it came out.

Now. First, use image controls, not pictureboxes; this uses far less memory and resources. Using drag&drop is fine, and will work for inline moves, but you''d best figure out a convenient way to make broadside moves. Be sure to make it convenient and easy to figure out, too. Might I suggest this; before a move is made, a player must click on up to 3 stones, the ones they want to move, and then they may drag any one of them in the direction they want the stones to move.

Start with making a lookup table, to simplify your code; create a 2D integer array of (1 to 61, 1 to 6) elements. There are 61 holes on the board, and 6 directions to go from a given one. Put into each slot of this table the index of the slot in that direction from the current slot, and put -1 into the directions which go off the board. For instance, the very top-left slot has only 3 on-board directions. If you number your slots in horizontal scanlines and your directions from left clockwise, slot 1 is adjacent to slots 2, 7, 6, -1, -1, and -1. Slot 2 is adjacent to slots 3, 8, 7, 0, -1, and -1. Et cetera.

Now, how to handle drag and drop. In the "dragdrop" event of each image control, you are given the index of the control dropped-into, a reference to the control dragged-from, and some other crap. To find out which imagebox was dragged from, access the "Index" property of the dragged-from control.

Make a form with a control array of images called imgBoard(), and paste in this source to test the concept out.
Private Sub imgBoard_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)  Me.Caption = Source.Index & " into " & IndexEnd Sub

Hope you can figure things out from there!

##### Share on other sites
I would not use any control.. I would paint images directly onto the back of the form. When someone clicks the form you get the x/y location and check what you''ve stuck there and then act on it. Using activeX controls in this way is not what they are designed to do and that would be reflected in the speed of execution.

After you have mastered the paintpicture method of doing things, moving to DirectX will be easier.

##### Share on other sites
ImageBox''s aren''t ActiveX. They''re basic built-in form controls. In actual Win32 implementation, they are actually drawn and managed just like ''drawing on the form'', it''s just that VB handles that stuff for you, and passes to you some convenient and easy-to-handle events. The speed loss is infinitesimal compared to the speed loss incurred by using VB in the first place.

I''ve explained the best ''next step'' for a VB user of Beth''s apparent experience. I''ve been working with C and C++ for years, but more importantly I''ve been writing clean and functional code for most of the previously-mentioned decade. Writing clean code involves knowing your environment, what it provides, and what it can do.

##### Share on other sites
You have no clue what your talking about... But anyhow VB doesn''t compile into win32 code so that is besides the point, and painting onto the form with the method I discussed is faster than using image boxes to do the same task.

If you want to do it the easy way use his.. if you want to do it the correct way use mine.

##### Share on other sites
quote:
Original post by Manip
But anyhow VB doesn''t compile into win32 code

Are you still using VB4? Man, you have my sympathies

##### Share on other sites
Last time I checked VB compiles into P-Code which is then interpreted. Not native Win32 Code.

##### Share on other sites
quote:
Original post by Manip
Last time I checked VB compiles into P-Code which is then interpreted. Not native Win32 Code.

Then you must not have checked since 1997.

##### Share on other sites
I've done way too much game programing in vb.

here are my comments to programing games in VB.

since you seem new I will keep API calls out of this.

dont use any controls, use 'paintpicture' to draw things on your form, use the autoredraw property to backbuffer for you, using cls and refresh to clear and update the form.

if you cant help it (no concept of 2D Graphics Programing), then listen to wyrframe and use Image controls, they are windowless, and as such dont have a dedicated HWND or HDC, the downfall of them is that they are non-interactive(get an event from clicking on them),so you will need to learn how to check a point against a rectangle(very easy) for collision.

if you wont have any controls on your form, turn the form's clipcontrols off.

dont use timer controls for anything, they use the window's timer and as such are slow and incosistant.

instead use the while loop, using a DoEvents call to allow for background proccessing.

e.g.

while(gamerunning)
'game drawing code here
DoEvents
wend

hope that helps ya

Raymond Jacobs,

www.EDIGames.com

www.EtherealDarkness.com

[edited by - EDI on April 6, 2004 3:57:48 PM]