Question: Hello, I'm still having a little trouble with this assignment. The last answer wasn't bad, but still wasn't exact. The first two functions are made

Hello, I'm still having a little trouble with this assignment. The last answer wasn't bad, but still wasn't exact. The first two functions are made to intialize the board and print to user the placeships function I am trying to have the computer randomly place the ships on the board and the shotsfired function is where I'm trying to put the game play (if that makes sense?)

Anyway, all help is always appreciated but if you could also explain your thought process so I can follow along I would really appreciate this as well.

For the most part this is what I am trying to do:

---populate a (10x10) board to sim a game of battleship

---There are 5 ships randomly placed on the board (this is determined randomly by computer and the user nor programmer will know the placements).

---Each ship will take a certain amount of hits to sink (refer to their lengths) and to enter a hit user needs to enter a row then col ( Ex: J9)

---after each attempt a message populates whether the gamer "hit" or "missed" the target and updates the board with an H or M accordingly.

----enforce preventative coding so if the gamer selects outside of the boards region, they are notified that their selection is invalid

---the user is given the option to start a new game or quit at the end

----use structs and dynamic memory allocation as necessary

Example of board:

(Since ship V has already been sunk, it has appeared on the board completely. Other floating ships remain hidden until sunk)

Hello, I'm still having a little trouble with this assignment. The last

#include #include #include #include

#define ROW 10 #define COLS 10

#define SHIPS 5 #define REG_SHIP 'S' #define RUGGED_SHIP 'R' #define GIANT_SHIP 'G' #define LITTLE_SHIP 'L' #define FAVORITE_SHIP 'F' #define LITTLE_SHIP_LEN 2 #define REG_SHIP_LEN 3 #define RUGGED_SHIP_LEN 3 #define FAVORITE_SHIP_LEN 4 #define GIANT_SHIP_LEN 5

#define MISS 'M' #define HIT 'H'

typedef enum { false, true } bool;

void intBoard(char board[][COLS]); void printBoard(char board[][COLS]); void placeShips(char board[][COLS], char shipType[]);

bool shotsFired(char board[][COLS]);

int main() { system("COLOR B0"); char board[ROW][COLS]; char shipType[SHIPS] = {'S', 'R', 'G', 'L', 'F'}; char choice; do{ printf("***Welcome Menu**** "); printf(" Please choose an option below: "); printf("1. Play New Game "); printf("2. Exit The Game "); scanf("%c", &choice); switch(choice){ case 1: intBoard(board); printBoard(board); break; case 2: printf("Thank you for playing!"); break; default: printf("Invalid selection."); break; } }while (choice != 2);

return 0; }

void intBoard(char board[][COLS]) { int i, j;

for (i = 0; i

void printBoard(char board[][COLS]) { int i,j;

printf(" 0 1 2 3 4 5 6 7 8 9 "); for (i = 0; i

void placeShips(char board[][COLS], char shipType[]){ int randomrow, randomcol; int i; srand(time(0)); for(i = 0; i

bool shotsFired(char board[][COLS]){ bool shot= true; int i; int j; for( i = 0; i EXAMPLE GAME BOARD

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!