Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the

THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the playerBoard and computerBoard to place my ships, and now need to create the salvos Board for both Player A and Player B.

How do I go about doing that?

I have included the code I have now and what I am trying to do. Thank you so much.

This is what I'm trying to do:

image text in transcribed

This is my Code:

#include

#include

void initializeBoard(int **playerBoard, int **compBoard)

{

const int rows = 10,

cols = 10;

for (int i = 0; i

{

playerBoard[i] = (int *)malloc(sizeof(int)*cols);

compBoard[i] = (int *)malloc(sizeof(int)*cols);

for (int j = 0; j

{

playerBoard[i][j] = '-';

compBoard[i][j] = '-';

}

}

}

void printBoard()

{

const int rows = 10,

cols = 10;

int **playerBoard = (int **)malloc(sizeof(int *)*rows);

int **compBoard = (int **)malloc(sizeof(int *)*rows);

initializeBoard(playerBoard, compBoard);

{

printf("SHIPS ");

printf(" | ");

for (char c = 'A'; c

{

printf("%c ", c);

printf("| ");

}

printf(" ");

for (int i = 0; i

{

printf("%2d ", i + 1);

printf("|");

for (int j = 0; j

{

printf(" %c ", playerBoard[i][j]);

if (i == 10)

puts(""); //only triggers if i=10, 10x10grid

printf("|");

}

printf(" ");

}

}

puts(" ");

printf(" | ");

for (char c = 'A'; c

{

printf("%c ", c);

printf("| ");

}

printf(" ");

for (int i = 0; i

{

printf("%2d ", i + 1);

printf("|");

for (int j = 0; j

{

printf(" %c ", compBoard[i][j]) + "|";

if (i == 10)

puts("");

printf("|");

}

printf(" ");

}

}

//Each Player's game board should be initialized

/o ships have been placed on either board

int main(void)

{

printBoard();

return 0;

}

SHIPS: SALVOS: SHIPS A|BICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJ

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Distinguish between : a) Business risk and financial risk

Answered: 1 week ago