Battleship is played on a 10 x 10 grid. The game begins with the five ships (see below) being placed.

1. (C) Crusor (2 Holes)
2. (A) Aircraft Carrier (5 Holes)
3. (B) Battleship (4 Holes)
4. (S) Submarine (3 Holes)
5. (D) Destroyer (3 Holes)

You will show the player the grid without the ships. If the player's MISSLE misses you will display an M for MISS. If the player MISSLE hits a ship then the letter for that ship is inserted (see letters above).

Your code needs to randomly place the five ships at the beginning of the game.

Your code needs to keep track of all right and wrong guesses. The game ends when all ships are sunk. After each MISSLE you will display the 10 X 10 Grid allow with a MISSLE counter. The goal is for the user to sink all ships with while using the least amount of missles.

The game will have an option to display the past 10 best scores.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define GRID_SIZE 10
#define SPACE ' '
#define MISS 'M'
#define SCORE_NUM 10

* initialize the grid
* @param grid
* @param c
void initGrid(char grid[GRID_SIZE][GRID_SIZE], char c);

* put ship to grid
* @param grid grid
* @param ship_type type of ship
* @param ship_size size of ship
void putShipToGrid(char grid[GRID_SIZE][GRID_SIZE],
       char ship_type, int ship_size);

* show content of grid
* @param grid
void showGrid(char grid[GRID_SIZE][GRID_SIZE]);

* get valid input form user
* @param message message to be showed
* @return
int getValidInput(char * message);

* play the game
* @param hidden_grid the grid
* @param total_holes number of holes we have to hit
* @return number of miss
int play(char hidden_grid[GRID_SIZE][GRID_SIZE], int total_holes);

* read file
* @param scores scores in file
* @param num number of scores
* @param file_name name of file
void readFile(int scores[], int * num, char * file_name);

* bubble sort
* @param scores
* @param num
void sort(int scores[], int num);

* write scores to file
* @param scores
* @param num
* @param file_name
void writeFile(int scores[], int num, char * file_name);...

By purchasing this solution you'll be able to access the following files:
Solution.c and Solution.bin.

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats