Battleship against computer
Author |
Message |
jay_vee
|
Posted: 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 . 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DIIST
|
Posted: 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.
BattleShip game for grade 9, i remember all we did for the final project was a tutorial using the draw module and delay. |
|
|
|
|
|
berrberr
|
Posted: 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 . 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
|
Posted: Tue Jun 12, 2007 4:24 pm Post subject: RE:Battleship against computer |
|
|
thanks for the help . but my program was due a few days ago and I got a 93% . |
|
|
|
|
|
|
|