A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: need help creating a class for scores in a game

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 2005
    Posts
    5

    need help creating a class for scores in a game

    hey i've been trying to create a class for keeping track of a players score in a game, and giving them a ranking based on their score.
    What i have so far is:

    class score {

    private var points: Number ;
    private var rank: String ;

    //constructor
    function score(newpoints:Number, newrank:String){
    points = newpoints ;
    rank = newrank ;
    }

    //set methods
    public function setpoints(p:Number) : Void {this.points = p ;}
    public function setrank(rank:String) : Void {this.rank = rank ;}

    //get methods
    public function getpoints() : Number {return points;}
    public function getrank() : String {return rank;}

    Now what i was wondering is what i would need to add so it keeps track of their score and shows them their score when they lose.

  2. #2
    Retired SCORM Guru PAlexC's Avatar
    Join Date
    Nov 2000
    Location
    NJ
    Posts
    1,387
    Just create an instance of the class, and use your getter/setter methods like any other AS object. On your timeline, you would put the following:
    code:

    import score;
    myScore:Score = new Score(0, "rookie" );
    /* assuming you start with 0 points at a rank of rookie */



    In your game, you would invoke the getter/setter methods.

    code:

    myScore.setpoints(20);
    myScore.setrank("veteran");



    At the end, let's say you have a screen with a textfield with an instance name of "displayScore_tf".
    code:

    displayScore_tf.text = myScore.getpoints();

    "What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
    ...and now I have tape all over my face.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center