Miscellaneous > Programming & Networking
Game of Life
Jordan:
I, along with ArmTheHomeless, am taking a really dumb Visual Basic programming class. (Its the school's fault for not offering C++ or similar). We have to make a similar rendition of John Conway's Game of Life. And since I am completely unmotivated in this horrible pro-Microsoft class, I have no idea about anything. Does anyone have source code or tips, etc? Thanks-
Faust:
This is the one where there are lots of little squares yeah? Theres a "creature" in each square and if it has above x members it dies, if it has below y neighbours it also dies? Find a way to represent a 2 dimensional "array" called field or something of "creatures" where creatures are a new class holding a boolean called "alive" and a function, "neighbours," that returns the number of neighbours in integer format. Also the routines "live" and "die" to flick the boolean should be in the new class. Then have something like-
if array.item(creature).neighbours < y OR array.item(creature).neighbours > x then
array.item(creature).die
else
array.item(creature).live
end
If you were to loop through that every 20 seconds, and apply the if part to each seperate creature each time with a sub loop then you would be right. Probably also a display routine in the array to show the field after each loop... I'm sure with VB it will be a point and click afair so hopefully they have some quik and easy way to display 2D arrays, because I have no idea how (unless you make like one array for each row...)
Faust:
I'm sure your teacher will be more help etcetera...
Ah stuff it I'll have a quick go tonight once I find how to make a 2D array.
Faust:
Hmmm... Just thought that if you have a straight array of 9 items that could be represented as a field by printing 3 items a line... Then all you have to do is tell the program what neighbours what.
shuiend:
Well I made that in c++ a good while ago. But for vb i am not sure. If you would like the c++ source code i could look for it. Jus pm me.
Navigation
[0] Message Index
[#] Next page
Go to full version