Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Our Battleship game needs several different kinds of ship we need a type to store the ships and information about it. Create a base class

Our Battleship game needs several different kinds of ship we need a type to store the ships and information about it.

Create a base class called Ship.

Create child classes for each of the ship types in the game (https://en.wikipedia.org/wiki/Battleship_(game)#Description) that inherit from Ship.

Ships should have the following properties:

A private array of positions

A Position is composed of an X and Y coordinate you should create a struct to encapsulate this.

A read-only length

The constructor for each inherited type should set this to the correct length for the ship type.

A read-only color to be drawn in

The constructor for each inherited type should set this to a different ConsoleColor for drawing.

A flag called Sunk

This should default to false for all ships.

A property called IsBattleship

This property should be overridden by each child type. Only the BattleShip should return true.

A method called Reset

This method should reset the members to their empty defaults

A method called Place(Position start, Direction direction)

Direction should be an enumeration of either Horizontal or Vertical.

This will complete the Position array with the set of coordinates that the ship is covering. E.g., place (new Position(1, 1), Direction.Horizontal) on a patrol boat will fill the array with the points (1, 1) and (2, 1).

Notes:

This is a separate program from previous weeks. You do not need to consider or implement anything to do with the grid or guessing.

You should choose the correct types and access modifiers for each type.

Create a test program that can run code such as the following:

AircraftCarrier ac = new AircraftCarrier(); Console.WriteLine(ac.IsBattleShip); ac.Place(new Position(1, 1), Direction.Horizontal); ac.Reset();

You should write additional code to test all the methods and ship types.

Given that the positions array is private, how can you test that the values are correct?

(( I have attached a picture to what the output of the data structure should look like))image text in transcribed

C:AWINDOWS1system32\cmd.exe Exer cise the ship class and 5 descendent ships Kind: Aircraft Carrier oordinates: 0,0 0,1 0,2 0,3 0,4 ength: 5 Sunk: False isBattleship: False Kind: BattleShip oordinates: 1,3 2,3 3,3 4,3 Length: 4 isBattleship: True ind: Destroyer ordinates:-6,7 7,7 Sunk: False isBattleship: False Kind: Patrol Boat oordinates: 4,4 4,5 4,6 Length: 3 Sunk False isBattleship: False Kind: Submarine dinates: 7,0 8,0 9,0 oor ength: Sunk: True isBattleship: False ress [Enter]

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

match each formula below with what calculates:

Answered: 1 week ago