Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need this in C# please can any one help me out and write the full code start from using system till end i am

i need this in C# please can any one help me out and write the full code start from using system till end i am confused and C# is getting me hard.I saw codes from old posts in Chegg but i need the ful complete code please thanks.

Module 4 Programming Assignment OO Design and implementation (50 points)

Our Battleship game needs to store a set of ships.

Create a new class called Ships.

Ships should have the following properties:

A way to store a collection of the Ship class from last week.

If you do not have working code from last week, please ask your instructor.

Does the Ships class represent the IS-A (inheritance) or the HAS-A (composition) relationship? Design your class accordingly. Use suitable generic collection classes.

void Add(Ship)

This is the method that allows you to add a ship.

The add method should validate that no ships are overlapping. How you do this is up to you to design. Feel free to discuss it in the forums but do not post code.

If there is a collision this method should throw a suitable exception.

void Clear()

This is the method that allows you to reset the collection.

bool SunkMyBattleship {get; private set}

This readonly property returns true if the battleship has been sunk.

The private set part is optional depending on how you implement it. But the property should be readonly to users of the class.

bool Attack(int x, int y)

This is the method that attacks the collection of ships and marks any positions as hit.

This should also mark the ship as Sunk if all positions are hit.

The method should return an indication of a hit (true) or a miss (false).

Your attack method should validate that x and y are positive integers and throw a suitable exception if they are not.

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

You may add as much code and data structures as you like to fulfill all the requirements.

Create a test program that creates a Ships collection and populates it with some ships. You may hard-code positions although your instructor will test your code with different ones so make sure to test your code thoroughly.

The test code should ask the user for X, Y positions and attack the ship collection until the battleship is hit.

There is no need to create any UI but it might help you test if you do. ;-) Your program does not have to look like an actual Battleship game. Remember this is purely code to help you test your Ships data structure.

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions