Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Battleship against computer
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jay_vee




PostPosted: Sun Jun 03, 2007 8:59 pm   Post subject: Battleship against computer

Hey, for my grade 9 ISP I'm making a battleship game with one player against the computer. I'm pretty clueless about how to put the computer's ships in a random place though. I know that I have to use randInt, but how would I use that to randomly choose a box on the grid?

And also, for the placement of the player's ships, how would I save the coordinates from the box they choose?

I'm soooo confused Sad . I tried looking at other people's programs for help but I don't understand half the codes they use, since I've only been learning turing for a few months... if anyone has ever made a battleship game before, any tips? I appreciate it very very much, because I'm running out of time and brain power Neutral
Sponsor
Sponsor
Sponsor
sponsor
DIIST




PostPosted: Mon Jun 04, 2007 6:07 am   Post subject: Re: Battleship against computer

I haven't made a battleship game, but i know its not as easy as some people think it is. But if you want to start take a look at the turing walk trough. It will be really helpful. If you know the number of boxes on the screen, just randint form one to that number and then choose the box that randint value returns. Wink

BattleShip game for grade 9, i remember all we did for the final project was a tutorial using the draw module and delay. Laughing
berrberr




PostPosted: Mon Jun 11, 2007 1:50 pm   Post subject: Re: Battleship against computer

I don't think battleship should be too hard. It would be as hard as you make it Wink. Some advice for you if youre trying to make it as simple as possible - stay away from a GUI. For example, make the player input the coords by typing them in (IE 3, 5) instead of clicking on a grid.


Storing the ships coords is not a problem at all...You could use a variable (ship1X = 1, ship1Y = 6) or a 2D array (ship1[1][6]) or even a 3D array (ship[1][1][6])!


For the computer, you could write a really basic system where it randomly chooses 2 integers (1 for horizontal/x row, 1 for vertical/y row) that are in the range of the heigh/width of youre game board. Then run those values through a for loop checking them agains the values that you have tored for the ships. You could always expand on that system to have a bit of fun, like if the ship is hit, then the next guesses will be surronding the ship and not random. Also, you might want to store the computers previously guessed coordinates so that it does not keep guessing the same coords over and over again.


Good luck with your game, hope it works out for you.
jay_vee




PostPosted: Tue Jun 12, 2007 4:24 pm   Post subject: RE:Battleship against computer

thanks for the help Smile. but my program was due a few days ago and I got a 93% Wink.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: