Advertisement

Help with connect 4 game

Started by November 26, 2002 05:43 AM
3 comments, last by Malachi 21 years, 11 months ago
I have been working on a project to create a connect 4 game in visual basic 6. At first I was going to use a flexgrid but it was too much hassle. So I started again, this time Im using picture boxes as the grid. Only problem is I dont know how to make my program detect when 4 picture boxes are in a row. I have looked for examples but I dont understand how they work as they are all using different methods. Can anyone give me some help on this please?
fuk off
Advertisement
I love baldy men. Especially chief!!!

assuming you have some form of 2 dimensional array that represents the grid, you need to check the maximum number of connected disc for each position.

Usually, this woiuld be done recursively, but you could just do it the ''long-handed'' way by looping through each of the eight directions and keeping a total count of the connected discs.

dim iCurrentType as Integerdim iLeftTotal as Integerdim bDoneLeft as BooleaniCurrentType = GetType(iXPos, iYPos)iLeftTotal = 0bDoneLeft = falsewhile not bDoneLeft   iXPos = iXPos + 1   if iCurrentType <> GetType(iXPos, iYPos) then       bDoneLeft = true   else       iCurrentType =GetType(iXPos, iYPos)   end ifend while 



... and so on for each of the eight directions.
Of course there are better ways of doing this (it fits neatly into the recursive style as pointed out earlier), but this should get you going.

Note: if you are working through the array from top-left to bottom-right, then you only need check north, east, northeast and northwest as other directions will eventually be checked anyway.

Hope this was a bit more help than the last two posters...
<a href="http://www.purplenose.com>purplenose.com
Thanks Corrot, I will give it a try. Hopefully I can get this done.

This topic is closed to new replies.

Advertisement