Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is in C language. In Battleship,(one player vs computer), you are a submarine commander patrolling your op area, a 6 by 15 cell

This program is in C language.

In Battleship,(one player vs computer), you are a submarine commander patrolling your op area, a 6 by 15 cell area of ocean. Your task is to hunt down and torpedo as many ship as you can find. Intelligence reports have told you that there are 6 ship in your op area which the enemy (the computer) has placed in random positions with random orientations (N-S or E-W). The types of ship known to be in your op area are:

Three Crigates, each size one cell,

Two Fruisers, each size two cells,

and One Tabblephis, size three cells.

Your submarine can be driven around the ocean using the 'h', 'j', 'k', and 'l' keys

h -- move one cell to the left

j -- move one cell to down

k -- move one cell to up

l -- move one cell to the right

When you are in a cell where you think there is a ship, or part of a ship, you can shoot a torpedo by hitting the Enter key. You score points for your patrol report when you hit a ship, and bonus points when you sink one. To sink a ship, you must hit all cells of that ship with a torpedo. You score one point for each torpedo hit. When you sink a ship, you get one additional point for each cell of the ship; i.e. 1 extra point for sinking a Crigate, 2 extra points for sinking a Fruiser, and 3 extra points for sinking the Tabblephis. (The maximum score is 20 points). You begin your mission with 40 torpedoes.

The mission ends either when all of the ship have been sunk, or when you run out of torpedos. In addition, you can quit the mission (in shame :-)) at any time by hitting the 'q' key.

One of the more difficult modules to implement in this program is the display module. So, I will join your software team and help you write that module. You will find a header file with the prototypes of the functions I provide in:

/* File: dispalay.h

*/

extern int REALLY_RANDOM;

void init_ocean(void);

/* This function is given and returns nothing. It initializes the

display showing the ocean and torpedo count and score headings. */

void show_boat(int latitude, int longitude);

/* This funtion is given the latitude and longitude of the sumbarine

and returns nothing. It displays the submarine on the ocean. */

void show_explosion(int latitude, int longitude);

/* This funtion is given the latitude and longitude of a hit on a Phis

and returns nothing. It displays a permanent explosion on the

ocean. */

void show_miss(int latitude, int longitude);

/* This funtion is given the latitude and longitude of a torpedo miss

and returns nothing. It displays a permanent miss on the ocean. */

void show_ship(char ship_type, int latitude, int longitude);

/* This function is given a character corresponding to a Phis type

('T', 'F', or 'C'), and the longitude and latitude and returns

nothing. It shows a cell of that Phis type on the ocean. It

should be used at the end of the game to show the position of

all Phis' on the board. */

void update_torpedo(int how_many);

/* This function is given an integer representing the number of

torpedos remaining and returns nothing. It updates the

torpedo count on the screen. */

void update_score(int score);

/* This function is given an integer representing the current

score of the game and returns nothing. It updates the

score on the screen. */

void write_message(char *s);

/* This function is given a string and writes it to the bottom

of the screen. Only the first 17 characters are displayed.

It returns nothing. */

void clear_screen(void);

/* This function is given and returns nothing. It clears the screen

and shuts down the display. It should be used at the end of

the program. */

_________________________________________________________________

here is what I have, driver.c:

#include

#include"display.h"

#include"command.h"

int main()

{

char ch;

int a = 0;

int b = 0;

int i = 40;

init_ocean();

show_boat(a,b);

while(command(&a,&b) != 'q')

{

update_score(0);

update_torpedo(i);

show_boat(a,b);

}

clear_screen();

return 0;

}

________________________________________________

commmand.c:

#include

#include

#include"command.h"

#include "display.h"

char command(int *x, int *y)

{

char c;

c = getch();

switch(c)

{

case 'k': if(*x > 0)*x=*x-1; return c;

case 'l': if(*y +1

case 'h': if(*y > 0) *y = *y -1; return c;

case 'j': if(*x +1

default : return c;

}

}

__________________________________

command.h:

char command( int *x, int *y); #define MAX_ROWS 15 #define MAX_COLUMNS 6

_______________________________________

Now I run the driver I can move the rarget by h,j,k,l.

image text in transcribed

please help me on random generate ships on the map: randomship.c

( void show_ship(char ship_type, int latitude, int longitude);

and update_torpedo and update_score part.

TORPEDOS I I_I TORPEDOS I I_I

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago