PlayerRecords.monkey2 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #Import "PoolMod"
  2. Class ScoreTable
  3. Field fileName:String=""
  4. Field recordList:RecordList
  5. Field frame:FrameAnimation
  6. Field fileHandler:FileSystem
  7. Field stream:FileStream
  8. Field down:Int=0
  9. Method New(fileName:String)
  10. Self.fileName=fileName
  11. Self.recordList=New RecordList()
  12. Self.frame=New FrameAnimation(media,50,20,DEVICE_WIDTH-100,DEVICE_HEIGHT-40,2,40)
  13. Self.fileHandler= New FileSystem()
  14. If(Self.fileHandler.FileExists(fileName))
  15. Self.stream=Self.fileHandler.ReadFile(fileName)
  16. Repeat
  17. Local name:String=Self.stream.ReadString()
  18. If((name).Length<>0)
  19. Local record:Record=New Record()
  20. record.name=name
  21. record.score=Self.stream.ReadInt()
  22. record.mostBallSinRow=Self.stream.ReadInt()
  23. record.mostPocketed=Self.stream.ReadInt()
  24. record.mostCompletedSets=Self.stream.ReadInt()
  25. Self.recordList.AddLast(record)
  26. Else
  27. Exit
  28. End
  29. Forever
  30. End
  31. Self.down=0
  32. End
  33. Field ready:Int=0
  34. Method InitFrame:Void()
  35. Self.frame.Init()
  36. Self.ready=0
  37. End
  38. Method SetRecord:Void(record:Record)
  39. Self.recordList.AddLast(record.GetCopy())
  40. Self.recordList.Sort(0)
  41. While(Self.recordList.Count()>50)
  42. Self.recordList.RemoveLast()
  43. End
  44. End
  45. Method SaveTable:Void()
  46. Self.stream=Self.fileHandler.WriteFile(Self.fileName)
  47. For Local record:Record = Eachin Self.recordList
  48. Self.stream.WriteString(record.name)
  49. Self.stream.WriteInt(record.score)
  50. Self.stream.WriteInt(record.mostBallSinRow)
  51. Self.stream.WriteInt(record.mostPocketed)
  52. Self.stream.WriteInt(record.mostCompletedSets)
  53. End
  54. Self.fileHandler.SaveAll()
  55. End
  56. Method Update:Bool()
  57. Local done:Int=0
  58. If(Self.ready=0)
  59. If(Self.frame.Update()=0)
  60. Self.ready=1
  61. End
  62. Else
  63. If Mouse.ButtonDown(MouseButton.Left)
  64. Self.down=1
  65. End
  66. If Mouse.ButtonDown(MouseButton.Left)=0 And Self.down=1
  67. Self.down=0
  68. done=1
  69. End
  70. End
  71. Return Not done
  72. End
  73. Method Render:Void(canvas:Canvas)
  74. Self.frame.Render(canvas)
  75. If(Self.ready=1)
  76. Local x:Float=80.0
  77. Local y:Float=130.0
  78. Local n:Float=0.0
  79. If Not recordList.Empty
  80. Text.Draw(canvas," TOP 10 ",100,30)
  81. Text.Draw(canvas," Name score Sets continuos pocketed ",100,80)
  82. Text.Draw(canvas,"========================",80,100)
  83. For Local record:Record = Eachin Self.recordList
  84. record.Render(canvas,x,y+n*20.0)
  85. n=n+1.0
  86. If(n>10.0)
  87. Exit
  88. End
  89. End
  90. Else
  91. Text.Draw(canvas,"Recored List is Empty",200,250)
  92. End
  93. Text.Draw(canvas," Press To Exit",80,400)
  94. End
  95. End
  96. End
  97. Class RecordList Extends List<Record>
  98. Method Compare:Int(lhs:Record,rhs:Record)
  99. If(lhs.score<rhs.score) Return -1
  100. If(lhs.score>rhs.score) Return 1
  101. If(lhs.mostCompletedSets<rhs.mostCompletedSets) Return -1
  102. If(lhs.mostCompletedSets>rhs.mostCompletedSets) Return 1
  103. If(lhs.mostBallSinRow<rhs.mostBallSinRow) Return -1
  104. If(lhs.mostBallSinRow>rhs.mostBallSinRow) Return 1
  105. If(lhs.mostPocketed<rhs.mostPocketed) Return -1
  106. Return lhs.mostPocketed>rhs.mostPocketed
  107. End
  108. End
  109. Class Record
  110. Field name:String=""
  111. Method SetName:Void(str:String)
  112. Self.name=str
  113. End
  114. Field score:Int=0
  115. Field mostBallSinRow:Int=0
  116. Field mostPocketed:Int=0
  117. Field mostCompletedSets:Int=0
  118. Method GetCopy:Record()
  119. Local record:Record=New Record()
  120. record.name=Self.name
  121. record.score=Self.score
  122. record.mostBallSinRow=Self.mostBallSinRow
  123. record.mostPocketed=Self.mostPocketed
  124. record.mostCompletedSets=Self.mostCompletedSets
  125. Return record
  126. End
  127. Method Render:Void(canvas:Canvas,x:Float,y:Float)
  128. canvas.Color = New Color(1,1,1)
  129. Text.Draw(canvas,name,x,y)
  130. Text.Draw(canvas,String(score),x+160.0,y)
  131. Text.Draw(canvas,String(mostCompletedSets),x+240.0,y)
  132. Text.Draw(canvas,String(mostBallSinRow),x+330.0,y)
  133. Text.Draw(canvas,String(mostPocketed),x+420.0,y)
  134. End
  135. Method IncrementPocketed:Void()
  136. Self.mostPocketed+=1
  137. End
  138. Method Reset:Void()
  139. Self.score=0
  140. Self.mostBallSinRow=0
  141. Self.mostPocketed=0
  142. Self.mostCompletedSets=0
  143. End
  144. Method UpdateBallSinRow:Void(ballSinRow:Int)
  145. If(ballSinRow>Self.mostBallSinRow)
  146. Self.mostBallSinRow=ballSinRow
  147. End
  148. End
  149. Method IncrementCompletedSets:Void()
  150. Self.mostCompletedSets+=1
  151. End
  152. End