S60UIExamplemodel.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:2k
源码类别:

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include <e32std.h>
  3. #include "S60UIExampleModel.h"
  4. const TInt KMaxHighScores = 5;
  5. // -----------------------------------------------------------------------------
  6. // CS60UIExampleModel::NewL()
  7. // Two-phased constructor.
  8. // -----------------------------------------------------------------------------
  9. //
  10. CS60UIExampleModel* CS60UIExampleModel::NewL()
  11.     {
  12.     CS60UIExampleModel* self = CS60UIExampleModel::NewLC();
  13.     CleanupStack::Pop(self);
  14.     return self;
  15.     }
  16. // -----------------------------------------------------------------------------
  17. // CS60UIExampleModel::NewLC()
  18. // Two-phased constructor.
  19. // -----------------------------------------------------------------------------
  20. //
  21. CS60UIExampleModel* CS60UIExampleModel::NewLC()
  22.     {
  23.     CS60UIExampleModel* self = new (ELeave) CS60UIExampleModel();
  24.     CleanupStack::PushL(self);
  25.     self->ConstructL();
  26.     return self;
  27.     }
  28. // -----------------------------------------------------------------------------
  29. // CS60UIExampleModel::ConstructL()
  30. // Symbian 2nd phase constructor can leave.
  31. // -----------------------------------------------------------------------------
  32. //
  33. void CS60UIExampleModel::ConstructL()
  34.     {
  35.     // Initialise Model
  36.     iGameStarted = EFalse;
  37.     }
  38. // -----------------------------------------------------------------------------
  39. // CS60UIExampleModel::~CS60UIExampleModel
  40. // Destructor.
  41. // -----------------------------------------------------------------------------
  42. //
  43. CS60UIExampleModel::~CS60UIExampleModel()
  44.     {
  45.     iHighScores.Close();    
  46.     }
  47.     
  48. // -----------------------------------------------------------------------------
  49. // CS60UIExampleModel::InsertInHighScoresL
  50. // Inserts a name and score into highscores.
  51. // Ordered by score
  52. // Rejected if not in top set (KmaxHighScores)
  53. // -----------------------------------------------------------------------------
  54. //
  55. void CS60UIExampleModel::InsertInHighScoresL(TDesC& aName, TInt aScore)
  56.     {
  57.     THighScore highScore;
  58.     highScore.iScore = aScore;
  59.     highScore.iName = aName.Left(20);
  60.     iHighScores.InsertInSignedKeyOrderAllowRepeatsL(highScore);
  61.     if (iHighScores.Count() > KMaxHighScores)
  62.         {
  63.         iHighScores.Remove(0);
  64.         }
  65.     }
  66. // End of File