Hello everyone,

I'm taking a C++ class in college and the last assignment for the semester is to write a sub hunter game that's worth 25% of my grade so needless to say I have to do a very good job on it. The due date is in 9 days so I hope I have enough time. I've been reading a lot online about the battleship game which is similar and I have already created a 10x10 array filled with 0s that's gonna represent the game board. This is what my professor wants:

Your final project is to create a game called Sub Hunter.

BOARD:
Is a 10 x 10 grid of cells

Destroyer:
Represented by the @ symbol
Has properties consisting of 
    Direction facing (N,S,E,W)
    Depth charges - a count of remaining depth charges
    Strength - How much damage it can take before sinking
    Damage taken - how much damage it has taken from the sub

Has three action points to spend each round - to be input by the player
Possible Actions:

Move Forward - move one square in the direction facing
Turn Left - make a 90 degree turn to the left in the same square
Turn Right - make a 90 degree turn to the right in the same square
Ping - look for a sub. Ping allows the destroyer to "see" if the sub is within two squares of its current location. If the sub is within two squares, the destroyer only knows the direction from its position (not the distance)
Depth charge - drop a depth charge
Sub:
Represented by the ┴ symbol
Has properties consisting of 
    Direction facing (N,S,E,W)
    Torpedos - a count of remaining torpedos
    Strength - How much damage it can take before sinking
    Damage taken - how much damage it has taken from the destroyer

Has two action points to spend each round - to be determined by the computer
Possible Actions:

Move Forward - move one square in the direction facing
Turn Left - make a 90 degree turn to the left in the same square
Turn Right - make a 90 degree turn to the right in the same square
Scope- look for a destroyer. Scope allows the sub to "see" if the destroyer is within two squares of its current location. If the destroyer is within two squares, the sub knows the direction and distance from its position
Torpedo - shoot a torpedo at the ship (only the direction it is facing)
Game Play:

The user inputs their actions as one turn (e.g. Forward, forward, ping). 
The computer determines the subs actions (Scope, torpedo)
The program the runs the turns, sub first then destroyer based on the users actions and the computers actions and gives appropriate messages to the user based what happens.

When the destroyer runs out of depth charges it is considered to be sunk by the sub
If the sub runs out of torpedos, it can run away (head for the boarder of the map) if it successfully runs away the game is a draw

Depth charges - When dropped they explode in the square they are in causing full damage to that square and half damage to all the squares around it.

Torpedos - run straight in the direction the sub is facing for 2 squares. They hit for full damage if the sub is on that line within two square of the launch point - otherwise they miss.

You should determine damage - limits for the ships and amount caused by the weapons, that make the game playable.

Extra Credit ideas - implement more!

Levels to the game (Easy, Hard etc)
Directional pings - only work in one direction but give exact information
Launchable depth charges can go X squares away before exploding
Homing torpedos
Smarter sub tactics (run quiet ie. harder to find)
Depth to the grid (3d array, meaning you also need depth for the charges to explode, minimum depth for scoping etc etc)
Sound and more. Be creative.

and this is what I have so far, I'm just getting started:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <ctime>

const int ROWS = 10; //rows for the board
const int COLS = 10; //Columns for the board

int gameBoard[ROWS][COLS]; //2D game board array.

void initializeBoard(); //initializes array to all 0's.
void displayBoard(); //displays blank board as all 0's.
void placeShip();
void gameOver();
void userInput();
void executeMove();



using namespace std;

/*
 * 
 */
int main(int argc, char** argv)
{
    int rows = 0,
        cols = 0;
    
    initializeBoard();
    displayBoard();
    
    
    
    
   
    
    
    return 0;
}
void initializeBoard()
{
    cout << "welcome to the sub hunter game!!!\n\n";
    cout << "This is your game board.\n\n";
    
    //Initialize game board to 0.
    int gameBoard[ROWS][COLS] = {0};
}
void displayBoard()
{
    
    for (int rows = 0; rows < ROWS; rows++)
    {
        for (int cols = 0; cols < COLS; cols++)
        {
          cout << gameBoard[rows][cols] << " ";      
        }
        cout << endl;
    }     
    
    
}

There are some variables that I haven't used yet because even though I need them I'm trying to figure out how to use them. I'm trying to take it one step at a time, right now I need to put the destroyer on the grid.

I'm not asking for anyone to give me the code or anything, I see this as a challenge that I want to complete myself but I'd like some ideas, comments or suggestions from those of you that know what you are doing, because honestly....I kinda lost, overwhelmed and stressed with this assignment right now. Therefore any help would be greatly appreciated.

Thanks a lot in advance.

Alex F.

Recommended Answers

All 4 Replies

What will really help you is to make a pseudo code of this program. Mess around with the grid-array and how choosing which array spot corrisponds to the spot on the grid.

What will really help you is to make a pseudo code of this program. Mess around with the grid-array and how choosing which array spot corrisponds to the spot on the grid.

Thanks for the prompt reply. I didn't think about the pseudo code idea because it wasn't required for this assignment and I'm little bit short on time already and I also have other classes to study for besides C++ but you are right maybe that would help.

You are not short on time. 9 days is plenty of time to write this program. Work on it for more than 2 minutes in a day and you will have it done in now time.

You are not short on time. 9 days is plenty of time to write this program. Work on it for more than 2 minutes in a day and you will have it done in now time.

It's not that much time when you are not exactly sure where to start or end. I changed my initial int array to a char array my next step is setting up the destroyer and sub on the grid. Any pointers on how to accomplish that? a for loop maybe?

Also can any of you guys point me to any good sample code for this game or something similar that would help me visualize the whole thing better. I've been googling a lot but I haven't really found anything good yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.