Find Jobs
Hire Freelancers

Battleship Create Ships class C#

$10-30 USD

I përfunduar
Postuar about 6 years ago

$10-30 USD

Paguhet në dorëzim
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 [login to view URL]; 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) { [login to view URL]( new Position([login to view URL](0, 10), [login to view URL](0, 10)), ([login to view URL](0, 2) == 0) ? [login to view URL] : [login to view URL]); [login to view URL]([login to view URL]()); [login to view URL](); } [login to view URL](); } } }
ID e Projektit: 16727110

Rreth projektit

4 propozime
Projekt në distancë
Aktive 6 yrs ago

Po kërkoni të fitoni para?

Përfitimet e ofertës për Freelancer

Vendosni buxhetin dhe afatin tuaj
Paguhuni për punën tuaj
Përshkruani propozimin tuaj
Është falas të regjistrohesh dhe të bësh oferta për punë
I dhënë për:
Avatari i Përdoruesit
$30 USD në 1 ditë
4,9 (104 përshtypje)
6,5
6,5

Rreth klientit

Flamuri i UNITED STATES
SEWARD, United States
5,0
5
Mënyra e pagesës u verifikua
Anëtar që nga pri 17, 2018

Verifikimi i klientit

Faleminderit! Ne ju kemi dërguar me email një lidhje për të kërkuar kredinë tuaj falas.
Ndodhi një gabim gjatë dërgimit të email-it tuaj. Ju lutemi provoni përsëri.
Përdorues të regjistruar Punë të postuara
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Po ngarkohet shikimi paraprak
Leja u dha për Geolocation.
Seanca e hyrjes ka skaduar dhe ke dalë. Hyr sërish.