// Parametrezid Singleton private BattleShipGame(BattleShipPlayer _first, BattleShipPlayer _second) { if (_first != null) { player1 = _first; } if (_second != null) { player2 = _second; } }
// Singleton + Builder public static BattleShipGame getInstance(BattleShipPlayer _first, BattleShipPlayer _second) { if (instance == null) { lock (syncRoot) // Is used in order to not to be ambiguity // during execution of different threads... { if (instance == null) { player1 = _first; // player1 is of type BattleShipPlayer abstract class player2 = _second; // player2 is of type BattleShipPlayer abstract class instance = new BattleShipGame(); } } } return(instance); }
public static void setPlayer2(BattleShipPlayer _second) { player2 = _second; }
public static void setPlayer1(BattleShipPlayer _first) { player1 = _first; }
private BattleShipGame() { player1 = player2 = null; }