Computer Science Canada Battleship question~ |
Author: | xpurepikex [ Wed May 24, 2006 10:17 am ] |
Post subject: | Battleship question~ |
i just have a little problem at the beginning i just started programming so i just need someone to get me started....how do u make the program so that when the game starts the computer randomly picks the spot, after picking the spot, it checks around so that it checks if the boat can actually fit into the other box (i used label) if u can help thx alot |
Author: | xpurepikex [ Wed May 24, 2006 10:19 am ] |
Post subject: | Re: Battleship question~ |
i'm really stuck~ lets say the boat is 3boxes long...it checks around until it finds the spot where it can fit....i'm a newb so i just made a 5 by 5 small board |
Author: | Brightguy [ Wed May 24, 2006 3:23 pm ] |
Post subject: | Re: Battleship question~ |
If you've just started this might be a little complex... You're going to need to use a matrix (2D array). Each cell will have different attributes, one of which will be if the cell is occupied by a boat. You get the computer to pick a random cell and orientation until you've found a place that isn't occupied. |
Author: | xpurepikex [ Fri May 26, 2006 10:10 am ] |
Post subject: | Re: Battleship question~ |
i'm really stuck could u take a look at it |
Author: | cool dude [ Fri May 26, 2006 5:34 pm ] | ||
Post subject: | |||
wow your code is brutal. here's suggestions 1)indent code!!! i don't care that your new or you want to just get it to work. if u don't indent your code not only is it harder for you to read and debug but it is hard for ppl that are helping u. we will help more if u indent which is really easy to do! 2)why when i look at your instructions you call 2 message boxes? you can just say + vbNewLine to make another line. absolutely pointless to have 2 messages boxes! 3)please comment your code because there are some stuff in your code that i don't really understand the reason of u putting it there as for randomizing the ship you can do it this way:
Note: put this code in your form! this is just an example for u to see that wherever "H" is thats where the ship is |
Author: | xpurepikex [ Mon May 29, 2006 10:09 am ] |
Post subject: | ^^ |
heres my new one that i worked on for a day... it's improved but forgot to comment:P |
Author: | wtd [ Mon May 29, 2006 1:31 pm ] | ||||||
Post subject: | |||||||
You indent some parts, but not others (subroutines and the like). Why?
You're always checking for equality to one value. Use a select statement to save yourself some work. There's lots of this:
What do these numbers mean? Why are they significant? Again, you're only checking for equality with "index". Use a "select case" statement instead of a complex "if" statement.
|
Author: | xpurepikex [ Thu Jun 01, 2006 10:14 am ] |
Post subject: | um |
how do u make sure the first boat thats entered doesn't overlap the second one... |
Author: | cool dude [ Thu Jun 01, 2006 4:45 pm ] | ||
Post subject: | |||
well if your randomizing the ships using the way i showed you then you could make an if statement saying:
this will check that if the numbers are equal then it will increase the other number by 1 to make it not overlap. |
Author: | xpurepikex [ Fri Jun 02, 2006 9:42 am ] |
Post subject: | um |
instead of putting letters i changed it but i can't make it so that it overlaps check the new one that i put up |
Author: | xpurepikex [ Fri Jun 02, 2006 10:11 am ] |
Post subject: | Re: um |
heres my new one i really need help;;;;;i can't get the collision working...the code is confusing and bretty brutal... |
Author: | cool dude [ Fri Jun 02, 2006 7:48 pm ] |
Post subject: | |
firstly 1000+ lines of code thats insane for wat your program does. to be honest with u i could make a good battleship game probably under half the lines of code u have! u have so much pointless code and some of it i just can't even understand why? u should start from scratch learn control arrays better and basically look through a lot of vb tutorials. asside from that note i don't see u randomizing for a ship for one thing, even though i showed u how. wat do u mean by u can't get collision working? wat collision? be more specific. you should look at some previous battle ship game programs made and look how they made it maybe you'll get an idea. also comment your code it will help u and especially me to understand it better. good luck with this game! |
Author: | wtd [ Sat Jun 03, 2006 8:50 am ] |
Post subject: | Re: um |
xpurepikex wrote: heres my new one i really need help;;;;;i can't get the collision working...the code is confusing and bretty brutal...
For the love of Dog man! Indent the contents of subroutines! |
Author: | cool dude [ Sat Jun 03, 2006 5:21 pm ] |
Post subject: | Re: um |
wtd wrote: xpurepikex wrote: heres my new one i really need help;;;;;i can't get the collision working...the code is confusing and bretty brutal...
For the love of Dog man! Indent the contents of subroutines! lol i was actually going to say the exact same thing! |