Question: Make a C program of a simple Battleship game. Consider the game in 1 dimension. Complete a program by filling the skeleton code. The field

Make a C program of a simple Battleship game.

Consider the game in 1 dimension. Complete a program by filling the skeleton code. The field is 20 length with 3 ships, Carrier(size: 5), Submarine(size: 3), and Destroyer(size: 2).

Suppose these ships are located as follow:

Carrier: from 2 to 6

Submarine: from 15 to 17

Destroyer: from 8 to 9

--------------------------------------------------------------

Reference program:

#include #include #include

struct Ship { char name[32]; int left; int right; int hit; };

void initialize(struct Ship * ships) { strcpy(ships[0].name, "Carrier"); ships[0].left = 2; ships[0].right = 6; ships[0].hit = 0;

strcpy(ships[0].name, "Submarine"); ships[1].left = 15; ships[1].right = 17; ships[1].hit = 0;

strcpy(ships[0].name, "Destroyer"); ships[2].left = 8; ships[2].right = 9; ships[2].hit = 0; }

int isHit(struct Ship ship, int pos) { // Implement this function }

int isFinished(struct Ship * ships, int n) { // Implement this function }

int main() { struct Ship ships[3]; initialize(ships);

while (1) { int pos = 0; scanf("%d", & pos);

int hit = 0; for (int i = 0; i 0) { printf("hit "); if (isFinished(ships, 3)) { printf("All ships are sunk "); break; } } else { printf("miss "); } } return 0; } --------------------------------------------------------

Make a C program of a simple Battleship game. Consider the game

in 1 dimension. Complete a program by filling the skeleton code. The

Make a program which provide the simple Battleship game. See the following link for the details: https://en.wikipedia.org/wiki/Battleship_game) http://www.battleshiponline.org/ Ref) https://en.wikipedia.org/wiki/Battleship_(game) Write a program of battleship game. To simplify the game adopts the following rule: - All ship is sunk with 1 hit - "hit" is displayed if user shoot a part of ship even if the ship was sunk

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!