THIS IS A C++ CODE. Please dont use the one found online. Use object oriented pr
ID: 3888970 • Letter: T
Question
THIS IS A C++ CODE. Please dont use the one found online. Use object oriented programming techniques and need an original code.
follow all constraints below, please dont just post the one already on chegg. i posted this twice already and got the the same code. that is not the one i need.
Program the game of battleship against the computer. Each side
has 2 grids. The first grid contains the location of the player’s ships. The second grid contains the location of the player’s shots and the outcome of the shot (hit or miss). The objective is to hit and sink all 5 enemy ships before they do the same to you. Each side recieves ships listed in figure 1.
Add statements to the main() function to do the following:
The grids are 10 x 10 squares.
Use whatever method is expedient to generate the computer
moves; this isn’t an AI class.
Constraints.
• Filter the input for valid numbers.
• Use Object Oriented Programming techniques.
• Use a Ship class.
• Use an assert to protect at least two of your methods.
carrier- size 5
Battleship- size 4
crusier- size 3
sub- size 3
destroyer- size 2
Explanation / Answer
using System;
{
class Battleships
{
const int seasize = 10;
const int EMPTY_SEA = 0, ATTACKED = 1, BATTLESHIP = 2, CRUISER = 3, SUBMARINE = 4, ROWINGBOAT = 5;
static int[,] sea = new int[seasize, seasize];
static void clearsea(){
//Clears the sea to empty
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
sea[x, y] = 0;
}
}
}
static void drawsea() {
//Draws the sea on the users screen
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
Console.Write(sea[x, y]);
} Console.WriteLine("");
}
}
static void placeships() {
//Places ships in the sea
sea[0, 5] = BATTLESHIP;
sea[2, 7] = BATTLESHIP;
sea[0, 0] = CRUISER;
sea[2, 0] = CRUISER;
sea[4, 3] = CRUISER;
sea[5, 6] = SUBMARINE;
sea[8, 8] = ROWINGBOAT;
}
static void Main() {
clearsea();
placeships();
drawsea();
Console.ReadLine();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.