C# Battleship program with Windows Form RRS feed

  • Question

  • Hi I am new to C# and programming and have to develop a C# Battleship game and forms for a GUI. With the following guidelines:

    • 10 by 10 grid with letters vertically and numbers horizontal
    • At least two ship types e.g. Battleship (5 grid spaces) and Destroyer (4 spaces) that can be positioned at different locations by a computer (and hidden to the player when a game is loaded)
    • GUI that allows user to input a location on grid to hit ship e.g. A5
    • Provide a way to save game game, load new or existing

    So far I declared an ocean class as well as a ship class and sub classes for different ships that inherit from ship.

    public class Ship  
            private string shipName;
            private int sLength;
            private string orientation; 
            private int numHits; //Number of Hits
            private bool sunk;
            private Point sCoord; // start coordinates for ship
            private Point eCoord; // end coordinates for ship

            public string ShipName { get; set; }
            public int SLength { get; set; }
            public string Orientation { get; set; }
            public Point SCoord { set; get; }
            public Point Ecoord { get; set; }
            public int NumHits { get; set; }
            public bool Sunk
                get { return numHits >= SLength;  } 


    class Ocean
            int[,] shipMap = new int[10, 10];
            int[,] hitMap = new int[10, 10];

     public class Destroyer:Ship
            public Destroyer()
                ShipName = "Destroyer";
                SLength = 2;
                // Panel element


          public class Battleship : Ship

            public Battleship()
                ShipName = "Battleship";
                SLength = 4;



    I am unsure of how I would implement constructors,  getters and setters and / or relevant behavioural methods in the ocean class. Do you have any advice of the next steps I would take?

    Kind Regards,

    Jack Porter

    Friday, February 23, 2018 9:38 PM

All replies