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

Username:   Password: 
 RegisterRegister   
 Hit Dection For Battle Ship Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Pooko




PostPosted: Thu Jun 12, 2008 12:31 pm   Post subject: Hit Dection For Battle Ship Help

I have started this battle ship game and i need help with a hit dection, my board is in an array and it will draw a single ship (box)
when the space is picked in a randint. i just need a hit dection or something to make it so when you click on the ship the box will turn red and if you miss, it will turn a differnt colour and say that you missed.

Any help would be great.



Battle Ship.zip
 Description:

Download
 Filename:  Battle Ship.zip
 Filesize:  2.65 KB
 Downloaded:  92 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
S_Grimm




PostPosted: Thu Jun 12, 2008 12:42 pm   Post subject: RE:Hit Dection For Battle Ship Help

mouse.where

us it to determine if you clicked the right place
Pooko




PostPosted: Thu Jun 12, 2008 12:45 pm   Post subject: Re: Hit Dection For Battle Ship Help

i tried that but i have no idea to know if i clicked in the wright spot that was randomly chosen as the randint. unless i make liek 400 lines for evey box...
Tony




PostPosted: Thu Jun 12, 2008 3:44 pm   Post subject: Re: Hit Dection For Battle Ship Help

Pooko @ Thu Jun 12, 2008 12:45 pm wrote:
unless i make liek 400 lines for evey box...

Why would you need to do that?

If you know that your target is at position X and the mouse was clicked at position Y, then it should be simple if the two correspond to the same cell on the map.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: Thu Jun 12, 2008 3:44 pm   Post subject: RE:Hit Dection For Battle Ship Help

Using Mouse.Where, you can figure out where the user's mouse is when they click. Since you know the coordinates of your grid, it should be easy to use arithmetic to determine the coordinates they clicked on.

Hint: assuming your grid has width and height h for each box, and is offset from the lower left corner by (x, y), then you need to do something like this (though your code can be much neater):

% Adjust so that the grid starts at 0, 0
gridPixelX := mouseX - x
gridPixelY := mouseY - y

gridX := gridPixelX / h
gridY := gridPixelY / h

You can, of course, do that all in one line for each X and Y, and it will be a lot nicer. You should be able to figure that out on your own (as well as being able to figure out what x, y and h are. Remember that gridX and gridY have to be integers (NOT real numbers), so you may have to use round() or something like that (don't have the Turing documentation with me right now).
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  [ 5 Posts ]
Jump to:   


Style:  
Search: