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:

  public void OnInputEvent(InputActionType action) {
   switch (action) {
    case InputActionType.GRAB_PIECE:
     Node gNode = Finder.RayHitFromScreen(Input.mousePosition);
     if (gNode == null) break;
     piece = gNode.Piece;
     if (piece == null) break;
     if (!piece.IsReady) break;
     if (Click(gNode) && piece && Has(piece) && Click(piece)) {
      piece.Pickup();
      piece.Compute();
      piece.HighlightPossibleMoves();
      piece.HighlightPossibleEats();
      GameManager.Instance.GameState.Grab();
     }

     //check clickable for tile and piece then pass Player
     //check if player has piece - PIECE
     //check if player has piece if not empty - NODE
     break;
    case InputActionType.CANCEL_PIECE:
      if (piece != null) {
       //if (!piece.IsReady) break;
       piece.Drop();
       piece = null;
       GameManager.Instance.GameState.Cancel();
      }
     break;
    case InputActionType.PLACE_PIECE:
     Node tNode = Finder.RayHitFromScreen(Input.mousePosition);
     if (tNode == null) break;
     Piece tPiece = tNode.Piece;
     if (tPiece == null) {
      if (piece.IsPossibleMove(tNode)) {
       if (Rules.IsCheckMove(this,piece,tNode, true)) {
        Debug.Log("Move checked"); // do nothing
       } else {
        piece.MoveToXZ(tNode, Drop);
        GameManager.Instance.GameState.Place();
       }
      }
     } else {
      if (piece.IsPossibleEat(tNode)) {
       if (Rules.IsCheckEat(this,piece,tNode, true)) {
        Debug.Log("Eat checked"); // do nothing
       } else {
        GCPlayer oppPlayer = GameManager.Instance.Opponent(this);
        oppPlayer.RemovePiece(tPiece);
        AddEatenPieces(tPiece);
        tPiece.ScaleOut(0.2f, 1.5f);
        piece.MoveToXZ(tNode, Drop);
        GameManager.Instance.GameState.Place();
       }
      }
     }
     break;
   }
  }