Example #1
0
 // Singleton
 public static BattleShipGame getInstance()
 {
     if (instance == null)
     {
         lock (syncRoot) // Is used in order to not to be ambiguity
                         // during execution of different threads...
         {
             if (instance == null)
             {
                 instance = new BattleShipGame();
             }
         }
     }
     return(instance);
 }
Example #2
0
 // 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);
 }
Example #3
0
 public void setToNull()
 {
     instance = null;
 }