using System.Collections.Generic;
using System.Threading.Tasks;
public enum AddressNumber { Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven };
public enum AddressLetter { X, A, B, C, D, E, F, J, H, I, G, Y }
public enum CellState { InitialEmpty, InitialDeck, AffectedEmpty, AffectedDeck }
public enum ShipName { FourDecker, ThreeDecker_1, ThreeDecker_2, TwoDecker_1, TwoDecker_2, TwoDecker_3, SingleDecker_1, SingleDecker_2, SingleDecker_3, SingleDecker_4 }
public AddressNumber Number { get; private set; }
public AddressLetter Letter { get; private set; }
public Coordinate(AddressLetter letter, AddressNumber number)
public override string ToString()
return Letter + ((int)Number).ToString();
public Coordinate Address { get; private set; }
public CellState State { get; set; }
public Cell(Coordinate address)
State = CellState.InitialEmpty;
public abstract class Board
public List<Cell> Cells { get; private set; }
Cells = new List<Cell>(144);
foreach (AddressLetter letter in Enum.GetValues(typeof(AddressLetter)))
foreach (AddressNumber number in Enum.GetValues(typeof(AddressNumber)))
Cells.Add(new Cell(new Coordinate(letter, number)));
public class ShipBoard : Board
public ShipBoard() : base()
public class ShotsBoard : Board
public ShotsBoard() : base()
private bool _isShipSunk;
public ShipName Name { get; private set; }
public Coordinate[] shipCoordinate { get; set; }
public int DeckNumber { get; private set; }
public int UnharmedDeckNumber { get; set; }
get { return (UnharmedDeckNumber == 0); }
public Ship(ShipName name, int deckNumber)
UnharmedDeckNumber = deckNumber;
Coordinate[] coordinate = new Coordinate[DeckNumber];
List<Coordinate> SetShips(List<Ship> myShip);
public class Player_1 : IPlayer
private List<Ship> _player1Ships = new List<Ship>();
public List<Coordinate> SetShips(List<Ship> myShips)
List<Coordinate> shipsCoordinates = new List<Coordinate>();
foreach (Ship certainShip in myShips)
int n = certainShip.DeckNumber;
Console.WriteLine("Enter {0} coordinates for your {0}-deck ship:", n);
string coordinates = Console.ReadLine().ToUpper();
string[] coordinates1 = coordinates.Split(' ');
List<Coordinate> certainShipCoordinates = new List<Coordinate>();
foreach (string c in coordinates1)
string[] partOfCoordinate = c.Split();
foreach (string part in partOfCoordinate)
AddressLetter letter = (AddressLetter)Enum.Parse(typeof(AddressLetter), part[0].ToString());
AddressNumber number = (AddressNumber)Enum.Parse(typeof(AddressNumber), (part[1].ToString()+part[2].ToString()).ToString());
Coordinate coordinateOfShip = new Coordinate(letter, number);
certainShipCoordinates.Add(coordinateOfShip);
certainShip.shipCoordinate = certainShipCoordinates.ToArray();
shipsCoordinates.AddRange(certainShipCoordinates);
Console.WriteLine("List of coordinates are: {0}", shipsCoordinates.ToString());
public List<Ship> CreateShips()
List<Ship> myShips = new List<Ship>();
Ship fourdeck = new Ship(ShipName.FourDecker, 4);
Ship threedeck1 = new Ship(ShipName.ThreeDecker_1, 3);
Ship threedeck2 = new Ship(ShipName.ThreeDecker_2, 3);
Ship twodeck1 = new Ship(ShipName.TwoDecker_1,2);
Ship twodeck2 = new Ship(ShipName.TwoDecker_2,2);
Ship twodeck3 = new Ship(ShipName.TwoDecker_3,2);
Ship onedeck1 = new Ship(ShipName.SingleDecker_1,1);
Ship onedeck2 = new Ship(ShipName.SingleDecker_2,1);
Ship onedeck3 = new Ship(ShipName.SingleDecker_3,1);
Ship onedeck4 = new Ship(ShipName.SingleDecker_4,1);
public static void Main(string[] args)
Coordinate shot = new Coordinate(AddressLetter.D, AddressNumber.Four);
ShipBoard board = new ShipBoard();
Ship fourdeck = new Ship(ShipName.FourDecker, 4);
fourdeck.shipCoordinate = new Coordinate[4];
fourdeck.shipCoordinate[0] = new Coordinate(AddressLetter.A, AddressNumber.One);
fourdeck.shipCoordinate[1] = new Coordinate(AddressLetter.A, AddressNumber.Two);
fourdeck.shipCoordinate[2] = new Coordinate(AddressLetter.A, AddressNumber.Three);
fourdeck.shipCoordinate[3] = new Coordinate(AddressLetter.A, AddressNumber.Four);
string a = string.Format("4-deck ship 'four-deck' is located into coordinate: 1 - {0}, 2 - {1}, 3 - {2}, 4 - {3}", fourdeck.shipCoordinate[0], fourdeck.shipCoordinate[1], fourdeck.shipCoordinate[2], fourdeck.shipCoordinate[3]);
fourdeck.UnharmedDeckNumber = 0;
Console.WriteLine(fourdeck.IsShipSunk.ToString());
Player_1 player = new Player_1();
List <Ship> player1Ships = player.CreateShips();
player.SetShips(player1Ships);