CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2008
    Posts
    6

    battleship in c++

    Does anyone have a battleship game using classes that works?...

    This is kind of a bet with a friend of mine to have a funcional battleship game ready for tomorrow...

    I guess i don't have the time to do it so, yes i know it was a bad bet, if anyone could help i would really appreciate that....

    Thanks for ur time

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: battleship in c++

    I think you should just be sporting and let your friend win the bet.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Re: battleship in c++

    Quote Originally Posted by pyx
    Does anyone have a battleship game using classes that works?...

    This is kind of a bet with a friend of mine to have a funcional battleship game ready for tomorrow...

    I guess i don't have the time to do it so, yes i know it was a bad bet, if anyone could help i would really appreciate that....

    Thanks for ur time
    Sure its not some school project ??

  4. #4
    Join Date
    May 2008
    Posts
    6

    Wink Re: battleship in c++

    If it was a school project i woul have know it a loooong time ago...

    No worry, i'll do it =D

    The deadline is what make this a stupid bet, but tonight i'll make it xD

  5. #5
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: battleship in c++

    Pyx,

    I'm curious to know how you would go about doing this.
    care to share your design?

    Thanks.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: battleship in c++

    Were it me, I'd simply hold a 2D array of 0s, and then put a row of 5 1s to represent a battleship, 2 2s to represent a patrol boat, etc.

    Testing a location simply looks up the index there, and increments the hit count on the hit vessel (if any). Once a vessel takes enough hits it is destroyed.

    Of course, you'd need to reject previously guessed positions first for this to work. Maybe use the sign bit to do that (since it doesn't matter if a 0 position is guessed twice).

  7. #7
    Join Date
    May 2008
    Posts
    24

    Re: battleship in c++

    Quote Originally Posted by ch0co
    Sure its not some school project ??
    That's what I think :P

  8. #8
    Join Date
    May 2008
    Posts
    6

    Re: battleship in c++

    Here is the project of the game....all the text is in portuguese xD sorry....

    Now i'm trying to change my implementation that uses a vector of vector to a map...Can anyone help?
    Attached Files Attached Files

  9. #9
    Join Date
    May 2008
    Posts
    6

    Re: battleship in c++

    Btw, is uses a configuration text file that changes the size of the board and the configuration of the boats....xD

  10. #10
    Join Date
    Jan 2008
    Posts
    60

    Re: battleship in c++

    I'm guessing your NOT going to UCLA. and NOT taking the cs32 class who the professor is NOT SmallBerg.
    Lol, a bet with a friend!

  11. #11
    Join Date
    May 2008
    Posts
    6

    Re: battleship in c++

    I'm guessing im Portuguese...i'm NOT a student in UCLA....xD

  12. #12
    Join Date
    May 2008
    Posts
    6

    Re: battleship in c++

    Besides that, if i was a student in UCLA why did my code is all in portuguese?

  13. #13
    Join Date
    Jan 2008
    Posts
    60

    Re: battleship in c++

    I had to check since we are doing the same project at ucla and it's due tommorow. I have a battleship program fresh from the oven. and it's in english. but I didn;t look at your requirements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured