Đã hoàn thành

Battleship Create Ships class C#

C#

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.

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

o 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)

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

o 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.

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

• void Clear()

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

• bool SunkMyBattleship {get; private set}

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

o 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)

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

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

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

o 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.

Here is the code from last week.

using System;

using [url removed, login to view];

namespace Battleship

{

public class Program

{

private static void Main(string[] args)

{

Random random = new Random(1337);

IList theShips = new List

{

new AircraftCarrier(),

new Battleship(),

new Destroyer(),

new PatrolBoat(),

new Submarine()

};

foreach (Ship ship in theShips)

{

[url removed, login to view](

new Position([url removed, login to view](0, 10), [url removed, login to view](0, 10)),

([url removed, login to view](0, 2) == 0) ? [url removed, login to view] : [url removed, login to view]);

[url removed, login to view]([url removed, login to view]());

[url removed, login to view]();

}

[url removed, login to view]();

}

}

}

Kĩ năng: Lập trình C, Lập trình C#, Lập trình C++, Java, Kiến trúc phần mềm

Xem nhiều hơn: A b c d e f g h i j k l m n o p q r s t u v w x y x.......a , Create our new logo design for our new website! See the attached image for our old boring logo., Create our new logo design for our new website! See the attached image for our old boring logo. The \ G\ was a power \ on/off\ , 1. Site to handle the questions and create the document based on the user answers. 2. The functionaltiy to be similar to the roc, one of our clients there is looking for a senior javascript developer team lead for their espoo offices just outside of helsinki, create our own logo, create our logo, create data structures erd, battleship game data structures, create loop java mortgage calculator graphic user interface, create jsp count usage website individual user, software paraphrase create sentence structures, type create movie trailers voice, type create jpg different fonts

Về Bên Thuê:
( 0 nhận xét ) SEWARD, United States

ID dự án: #16727110

Được trao cho:

$30 USD trong 1 ngày
(51 Đánh Giá)
5.4

5 freelancer đang chào giá trung bình $142 cho công việc này

$222 USD trong 1 ngày
(42 Nhận xét)
6.2
$200 USD trong 1 ngày
(73 Nhận xét)
6.0
$223 USD trong 1 ngày
(13 Nhận xét)
5.3
ppgjsc

Hi. I checked your job in depth and i can add value and complete your project professionally and in a timely manner with my 7+ years of c# development. In reality, a months ago, i developed battleship game. I ha Thêm

$35 USD trong 1 ngày
(13 Nhận xét)
4.8