HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Battle ship game

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
battlegameship

Problem

I have been programming for a couple months now and really wanted to make my own game, so I chose battle ship due to is simplicity (I learned out how wrong I was). I know one thing I am going to hear about is that it isn't portable due to the fact I am using the windows library. All I have to say is I tried finding other ways but sadly I am not smart enough. I would also love to convert it to OOP, but I have no idea how to start.

```
#include
#include
#include
#include
#include
using namespace std;

const int COLS = 10;
const int ROWS = 10;
const int CARRIER = 5;
const int BATTLE_SHIP = 4;
const int CRUISER = 3;
const int SUBMARINE = 3;
const int PATROL = 2;
//Prototypes
void playerSetUp(HANDLE, char[][COLS], int, int playerCarrier[], int playerBattleShip[], int playerCruiser[], int playerSubmarine[], int playerPatrol[]);
void mapGenerator(char[][COLS], int, int carrier[], int battleShip[], int cruiser[], int submarine[], int patrol[]);
void displayScoreBoard(HANDLE, char[][COLS], char[][COLS], int, int enemyCarrier[], int enemyBattleShip[], int enemyCruiser[], int enemySubmarine[], int enemyPatrol[], int &, int &, int &, int &, int &, int &, int &, int &, int &, int &, int playerCarrier[], int playerBattleShip[], int playerCruiser[], int playerSubmarine[], int playerPatrol[]);
void placeCursor(HANDLE, int, int);
int winCondition(int, int);
int startMenu();
int shipCheck(char[][COLS], int, int ship[], int);
int letterVal(char);
int numValidation(int);
void displayBoard(HANDLE, char[][COLS], int);
void playerTurn(HANDLE, char[][COLS], char[][COLS], int);
void enemyTurn(HANDLE, char[][COLS], int, int);
void stringInputCheck(HANDLE, string, int&, int&, int, int);

int main()
{
//computer map
char computer[ROWS][COLS] = {
{ 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O' },
{ 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O' },
{ 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O' },
{ 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O

Solution

Here's just some observations about coding and design:

  • Instead of A, B, C choices, try S for start and Q to quit. This way people don't have to mentally "translate" the choice.



  • At the beginning, you ask them to choose A, B, or C. But what is option C? Probably a copy/paste from further down.



  • Use a tolower(choice) and only compare a, b, or c and remove the uppercase checks.



  • I have mixed emotions about putting in "under construction" references. If it's not ready, why put it in? But then again, it may want me to purchase the update to the program.



  • Instead of the big "if tower" for the alphabet, try `cout

Context

StackExchange Code Review Q#109601, answer score: 4

Revisions (0)

No revisions yet.