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 Color getConnectorColor(){
   Color standardColor = new Color(0,0.5f, 0);
   Color highlightedColor = new Color(0f, 0f, 1f);
   int block0;
   int block1;
   int block2;
   int blockPosition;

   if (this.axis == "x") {
    blockPosition = this.x;
    block0 = this.GetBlockNumber(0,this.y, this.z);
    block1 = this.GetBlockNumber(1,this.y, this.z);
    block2 = this.GetBlockNumber(2,this.y, this.z);
   }
   else if (this.axis == "y") {
    blockPosition = this.y;
    block0 = this.GetBlockNumber(this.x,0, this.z);
    block1 = this.GetBlockNumber(this.x,1, this.z);
    block2 = this.GetBlockNumber(this.x,2, this.z);
   }
   else if (this.axis == "z") {
    blockPosition = this.z;
    block0 = this.GetBlockNumber(this.x,this.y, 0);
    block1 = this.GetBlockNumber(this.x,this.y, 1);
    block2 = this.GetBlockNumber(this.x,this.y, 2);
   }
   else { //not quite sure why axis isn't set but throwing error
    return standardColor;
   }

   //no highlighting needed since connector isn't visible
   if (blockPosition == 2) return standardColor;

   //middle block is blank and first and second blocks match
   if (block1 == BlockScript.emptyBlock
       && block0 != BlockScript.emptyBlock
       && block0 == block2) return highlightedColor;

   //if this block is empty then return standard color
   if (blockPosition == BlockScript.emptyBlock) return standardColor;

   //if the next matches
   if(blockPosition == 0 && block0 == block1 && block0 != BlockScript.emptyBlock) return highlightedColor;
   if(blockPosition == 1 && block1 == block2 && block1 != BlockScript.emptyBlock) return highlightedColor;

   //set the default color
   return standardColor;
  }