Keksicle

Hall of Fame

Aug 17th, 2017
593
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2.  
  3. import openfl.Lib;
  4. import openfl.display.Sprite;
  5. import openfl.text.TextField;
  6. import openfl.text.TextFormat;
  7. import openfl.text.TextFieldAutoSize;
  8. import openfl.events.MouseEvent;
  9.  
  10. /**
  11.  * ...
  12.  * @author Reka
  13.  */
  14. class HallofFame extends Sprite
  15. {
  16.     private var myTextFormat:TextFormat;
  17.    
  18.     // Clean previous screen and setup the current screen
  19.     public function new()
  20.     {
  21.         super();
  22.        
  23.         removeChildren();   // Clean up previous screen
  24.         hallofame();
  25.     }
  26.    
  27.     // Setup the current screen
  28.     function hallofame()
  29.     {
  30.         // Setup a default text format
  31.         myTextFormat = new TextFormat("_sans", 14, 0xAA2023, true);
  32.        
  33.         // Add the neccessary elements
  34.         addLeaderboard();
  35.         goBacktoMenu();
  36.     }
  37.    
  38.     // Get leaderboard scores and get them displayed
  39.     function addLeaderboard()
  40.     {
  41.         var scores = Database.GetScores();
  42.         var scoreCount = 0;
  43.         for (score in scores)
  44.         {
  45.             addScore(scoreCount, score.playerName, score.playerScore);
  46.             scoreCount += 1;
  47.         }
  48.     }
  49.    
  50.     // Displays a single leaderboard score
  51.     function addScore(scoreID:Int, name:String, score:Int)
  52.     {
  53.         // Rank
  54.         var textRank = new TextField();
  55.         textRank.defaultTextFormat = myTextFormat;
  56.         textRank.selectable = false;
  57.         textRank.text = Std.string(scoreID + 1);       
  58.         textRank.x = 10;
  59.         textRank.y = 100 + (scoreID * 30);
  60.         addChild( textRank );
  61.        
  62.         // Player Name
  63.         var textName = new TextField();
  64.         textName.defaultTextFormat = myTextFormat;
  65.         textName.selectable = false;
  66.         textName.text = name;  
  67.         textName.width = 320;
  68.         textName.x = 50;
  69.         textName.y = 100 + (scoreID * 30);
  70.         addChild( textName );
  71.        
  72.         // Player Score
  73.         var textScore = new TextField();
  74.         textScore.defaultTextFormat = myTextFormat;
  75.         textScore.selectable = false;
  76.         textScore.text = Std.string(score);    
  77.         textScore.x = 400;
  78.         textScore.y = 100 + (scoreID * 30);
  79.         addChild( textScore );
  80.     }
  81.    
  82.     // a function for a button to take the player back to the main menu
  83.     function goBacktoMenu()
  84.     {
  85.         var buttonText:TextField = new TextField();
  86.         buttonText.autoSize = TextFieldAutoSize.LEFT; //position button to the left
  87.         buttonText.defaultTextFormat = myTextFormat;
  88.         buttonText.text = "Back to Menu"; //displays text on button
  89.         buttonText.x = 50; //positions button on screen with coordinates
  90.         buttonText.y = 50;
  91.         addChild( buttonText ); //adds the button itself
  92.         buttonText.addEventListener( MouseEvent.CLICK, backtoMenu); //makes button respond to clicking by redirecting player to menu
  93.     }
  94.     // a function for a button to take the player back to the main menu
  95.     function backtoMenu(evt:MouseEvent)
  96.     {
  97.         removeChildren();
  98.         var newScreen = new Menu();
  99.         addChild(newScreen);
  100.     }
  101. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×