Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to generate a game board for a connect four project. I've look long and hard for info on graphics within dot net but I've had little luck. I was however fortunate enough to com across this solution based on vb6 code.

 

For a = Image1(Index).Index To 42 Step 7
               For b = 1 To 7
                   If LegalMoves(b) = a Then GoTo 300
               Next
           Next

now my question is: is this posiable within the .net? as I'm having no luck at the moment :(

well I hope someone helps me out soon as I'm off to purchase Deitel&Deitel (the best tech books ever)

 

cheers:D

 

[edit]VB is not PHP[/edit]

  • *Experts*
Posted

There are a few things about this VB6 snippet that should be

pointed out.

 

1.) Control arrays are no longer supported in VB.NET like they

were in VB6, so you cannot loop like this. It's also a very

redundant loop statement, because you're accessing the Index of

an Image control whose Index you already know.

 

2.) The use of GoTo is not acceptable to use in this way; a

subroutine should be created to handle the code, and then you

should call the sub.

 

That being said, I still don't understand what you're trying to

accomplish; if you want to draw graphics in VB.NET, look into the

System.Drawing namespace, and look at the sticky thread at the

top of this forum.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Bucky cheers for the reply :)

First off yes I'm aware that this code is far from ideal, as I stated I'm very new to vb.net and this is my very first attempt at graphics within this framework. I merely posted this code as I was fortunate enough to find a tutorial online that accomplished the task I'm trying to solve ( a connect 4 game). The use of this loop is simply to populate the control (a 6,7 matrix). I was just curious if this code has a simple equivalent in .net Anyway cheers once again for the reply I'm off to buy another text book that covers graphics in more detail than my prescribed text.

  • *Experts*
Posted

I would recommend against using many controls for this game, as they are unneeded, and since control arrays are unsupported (in the

forms designer, anyway), it will mean more code than you really

need. What you should do is use one single Panel control as the

main "playing surface" and then programatically check the MouseDown

events.

 

What you should do is create a 2-dimensional array at form level, and

store the values of each of the 42 spots (black, red, empty [or whatever])

in that. Then you can use the Panel's MouseDown or MouseUp event

to both check the position of the point you clicked on, but also check

legal moves, check for winning combinations, etc.

 

If you want to use this method, you will need to read up on the

GDI+, which lives in the System.Drawing namespace. Remember though,

you should keep all your painting code in the _Paint event of the

panel, otherwise you may run into redrawing troubles.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...