Skip to content
← Back to Community
OOP Battleship Game
Profile icon
christianbm1

OOP C++ Battleship Game. It's a simple, 1 way game: player battles the computer.

There might be bugs.

Thanks a lot, Captain!

Voters
Profile icon
PorterCorbett
Profile icon
xxhoamailanxx
Profile icon
HarrietLai
Profile icon
coderash
Profile icon
Steven_The_GuyT
Profile icon
coder787878
Profile icon
ArnavPoddar
Profile icon
SPQR
Profile icon
AydenB
Profile icon
Zonnielilbro
Comments
hotnewtop
Profile icon
ElliottKness

Honestly, I didn't mean to find this bug, but I accidentally typed "a*" into an attack and the whole page crashed on me. It did advance to try displaying the Previous Shots, but the website otherwise seized up. I'm assuming (in Java terms) the program was trying to throw a InputMismatchException or OutOfBounds error but failed and got stuck in an infinite loop. I don't know C++ that well, but I imagine this would be a simple fix to restrict a player to a specific format of typing and denying any character that is a special character or overall invalid format.

Profile icon
christianbm1

@ElliottKness That's right, should be an easy fix. An overloaded Getline() and string parsing should do the trick.

Profile icon
ElliottKness

@christianbm1 - I figured it wouldn't be too complicated. Overall, this is such a cool concept! My AP Computer Science teacher was having us build a similar style of Battleship but within Java.

Profile icon
[deleted]

Add something like usleep(2000000) that waits for two seconds then move on at the start. Cause when you start it shows all of it at same time and that's not really convenient for iPad or small screen users

Profile icon
[deleted]

Very Nice code and ideas [email protected]

Profile icon
CuriousMonkey

hey there is a library called ncurses where you can print characters wherever you want so you dont have to worry about new lines and stuff. i use it all the time in my games and it is very useful. here is a link for a tutorial: http://www.cs.ukzn.ac.za/~hughm/os/notes/ncurses.html#:~:text=%20Ncurses%20Programming%20Guide%20%201%20Using%20ncurses,cursor.%20%205%20X%20window.%20%20More%20

Profile icon
coderash

I like it, you could add 2 human player setting???

Profile icon
christianbm1

@coderash This would be nice. To be honest, I would welcome help in that regard though!

Profile icon
ArnavPoddar

I also think that it should display a message that says if a ship has been sunk for people that didn't read the beginning because it can cause people to waste shots

Profile icon
ArnavPoddar

GIVE US MORE SHOTS

Profile icon
christianbm1

Thanks a lot for the feedback! Fixed a few of the bugs folks; still have a few more to squash.

Hope you guys enjoyed the game as much as I do!

Profile icon
MuntahaIslam

Nice idea! Though it has a lot of bugs. Likewise, it does not take integers with 2 digits, hitting the shore reply's in two ways, no hit or exit, last question triggers system to pause etc. If you want, I can fork it out with trying to solve some of them by myself! Good job and good luck!

Profile icon
katyadee

@MuntahaIslam Seconding this! A few bugs, but still a really good idea. :D

Profile icon
JoshuaSturgell

Yay! I won with no hits to spare. Good job!