Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     private void CheckMasterClient(int leavingPlayerId)
     {
         bool currentMasterIsLeaving = this.mMasterClient != null && this.mMasterClient.ID == leavingPlayerId;
         bool someoneIsLeaving = leavingPlayerId > 0;

         // return early if SOME player (leavingId > 0) is leaving AND it's NOT the current master
         if (someoneIsLeaving && !currentMasterIsLeaving)
         {
             return;
         }

         // picking the player with lowest ID (longest in game).
         if (this.mActors.Count <= 1)
         {
             this.mMasterClient = this.mLocalActor;
         }
         else
         {
             // keys in mActors are their actorNumbers
             int lowestActorNumber = Int32.MaxValue;
             foreach (int key in this.mActors.Keys)
             {
                 if (key < lowestActorNumber && key != leavingPlayerId)
                 {
                     lowestActorNumber = key;
                 }
             }

             this.mMasterClient = this.mActors[lowestActorNumber];
         }

         // make a callback ONLY when a player/Master left
         if (someoneIsLeaving)
         {
             SendMonoMessage(PhotonNetworkingMessage.OnMasterClientSwitched, this.mMasterClient);
         }
     }