Slurpee Posted April 21, 2003 Posted April 21, 2003 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] Quote
*Experts* Bucky Posted April 21, 2003 *Experts* Posted April 21, 2003 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. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Slurpee Posted April 21, 2003 Author Posted April 21, 2003 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. Quote
*Experts* Volte Posted April 21, 2003 *Experts* Posted April 21, 2003 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. Quote
Slurpee Posted April 21, 2003 Author Posted April 21, 2003 Thanx for that most excellent advice ;) I'll be finished ina day or two. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.