Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Help OO template for the basic battleship game BattleShipGame.sc ~ using System; namespace BattleshipSimple { internal class BattleShipGame { private Grid grid; public BattleShipGame(int

C# Help

OO template for the basic battleship game

BattleShipGame.sc ~

using System;

namespace BattleshipSimple { internal class BattleShipGame { private Grid grid;

public BattleShipGame(int gridSize) { grid = new Grid(gridSize); }

internal void Reset() { grid.Reset();

}

internal void Play() { while (grid.HasShipsLeft) { grid.Draw();

//Read input from user into x, y int x, y;

grid.DropBomb(x, y);

} } } }

Program.cs ~

using System;

namespace BattleshipSimple { class Program { static void Main(string[] args) { var game = new BattleShipGame(10); ConsoleKeyInfo response; do { game.Reset(); game.Play();

Console.WriteLine("Do you want to play again (y/n)"); response = Console.ReadKey();

} while (response.Key == ConsoleKey.Y); } } }

The template has the outline of a battleship game using OO constructs. You need to add the Grid class and complete the code so that it runs correctly.

At a minimum you need to complete the Draw and DropBomb methods.

adding 2 new features:

Variable sized grid - the trivial part of this is making a 2d array based on the passed in size. The second part is adding some ships to that grid - You need to come up with a very simple algorithm to add a few ships to the grid. This is purely test code so it doesn't have to be sophisticated in any way.

Game over detection. This will be implemented in the readonly property Grid.HasShipsLeft. In this property you will determine if there are any ships left not hit with a bomb. The algorithm should look through the array for any remaining ships each time the property is read.

You may add as many other methods, fields or properties as you feel are required.

Notes:

The code will be tested with grids ranging in side from 5 (the smallest you can fit a size 5 ship) upwards. Make sure that all aspects of the game work correctly without crashing or hanging

You must use the template code provided!

Please make sure you show the ships in the grid, at this point we are merely testing our game logic and hidden ships make the game very hard to test.

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

What are the key characteristics of Handelsbankens approach?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago