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 setParams(int score, int place, int gold, float time)
         {
             this.score = score;
             this.m_gold = gold + getBonus(place);
             isShown = true;
             if (place == 1) star = 3;
             else if (place > 1 && place <= 3) star = 2;
             else if (place > 3 && place <= 5) star = 1;
             else star = 0;

             BitmapFont scoreFont = new BitmapFont("Fonts/font_result", "Fonts/font_result_xml", scoreLabel);
             scoreFont.setText("" + score, 0, 0, "GUI", "GUI");
             scoreLabel.transform.localPosition = new Vector3(scoreLabel.transform.localPosition.x - scoreFont.width/2,
                 scoreLabel.transform.localPosition.y, scoreLabel.transform.localPosition.z);

             BitmapFont desFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", gameObject);

             BitmapFont bonusFont = new BitmapFont(desFont, labels[0]);
             bonusFont.setText("BONUS: " + getBonus(place), 0, 15, "GUI", "GUI");

             BitmapFont timeFont = new BitmapFont(desFont, labels[1]);
             timeFont.setText("TIME: " + ((int)(time * 100))/100f, 0, 15, "GUI","GUI");

             BitmapFont placeFont = new BitmapFont(desFont, labels[2]);
             placeFont.setText("PLACE: " + place, 0, 15, "GUI", "GUI");

             BitmapFont goldFont = new BitmapFont(desFont, labels[3]);
             goldFont.setText("GOLD: " + gold, 0, 15, "GUI", "GUI");
         }