Computer Science / Game Programming

profilesehar
studentcontroller.ctxt

#BlueJ class context comment0.params=records\ writer\ level\ score comment0.target=void\ updateHighScoreRecords(comp1022p.assignment.GameRecord[],\ java.io.PrintWriter,\ int,\ int) comment0.text=\r\n\ Updates\ the\ highscore\ records\ and\ write\ them\ to\ a\ file.\r\n\ \r\n\ The\ highscore\ records\ stores\ a\ maximum\ of\ 10\ records.\r\n\ \r\n\ This\ method\ updates\ the\ highscore\ records\ if\ the\ score\ of\ the\ current\r\n\ game\ play\ is\ high\ enough.\ It\ first\ asks\ for\ the\ user\ to\ input\ his/her\r\n\ name\ for\ forming\ the\ current\ record.\ If\ the\ name\ has\ more\ than\ 20\r\n\ characters,\ it\ should\ be\ trimmed\ down\ to\ the\ first\ 20\ characters\ only.\r\n\ \r\n\ The\ current\ record\ should\ be\ inserted\ into\ the\ highscore\ records\ only\ if\r\n\ either\ one\ of\ the\ following\ conditions\ is\ satisfied\:\r\n\ \r\n\ Condition\ 1.\ There\ are\ less\ than\ 10\ records\ in\ the\ highscore\ records.\r\n\ \r\n\ Condition\ 2.\ There\ are\ 10\ records\ in\ the\ highscore\ records\ and\ the\ score\ of\ the\r\n\ current\ record\ is\ strictly\ higher\ than\ at\ least\ one\ of\ the\ scores\ in\ the\r\n\ highscore\ records.\r\n\ \r\n\ Condition\ 3.\ There\ are\ 10\ records\ in\ the\ highscore\ records\ and\ the\ score\ of\ the\r\n\ current\ record\ is\ equal\ to\ some\ of\ the\ scores\ in\ the\ highscore\ records\ and\ the\ \r\n\ current\ level\ is\ strictly\ higher\ than\ at\ least\ one\ of\ those\ records\ in\ the\ highscore\ \r\n\ records.\r\n\ \r\n\ For\ condition\ 2\ and\ condition\ 3,\ after\ each\ successful\ insertion,\ the\r\n\ record\ with\ the\ lowest\ score\ and\ lowest\ level\ should\ be\ removed\ to\ keep\ a\r\n\ total\ of\ 10\ records.\ In\ case\ there\ are\ more\ than\ one\ record\ with\ the\r\n\ lowest\ score\ and\ the\ lowest\ level,\ any\ one\ of\ those\ can\ be\ removed.\r\n\ \r\n\ If\ the\ player's\ name\ already\ exists\ in\ the\ highscore\ records,\ replace\ the\ old\ record\ \r\n\ with\ the\ new\ record\ if\ the\ new\ record\ is\ better.\ (i.e.\ either\ the\ new\ score\ is\ strictly\ \r\n\ higher\ than\ the\ old\ score,\ or\ the\ new\ level\ is\ higher\ than\ the\ old\ level\ when\ the\ scores\ \r\n\ are\ the\ same).\r\n\ \r\n\ The\ highscore\ records\ are\ then\ written\ to\ a\ file\ for\ storage.\ The\ format\r\n\ of\ the\ record\ should\ be\ name\ followed\ by\ level\ followed\ by\ score.\ Each\ \r\n\ item\ should\ be\ separated\ by\ a\ tab\ character\ '\\t'.\r\n\ \r\n\ @param\ highScoreRecords\ \ The\ previously-saved\ highscore\ records,\ with\ a\ maximum\ of\ 10\ records\ only.\r\n\ @param\ writer\ \ \ \ \ \ \ \ \ \ \ \ The\ writer\ used\ to\ write\ the\ record\ to\ a\ file.\ You\ can\ assume\ that\ the\ writer\ is\ already\ properly\ initialized\ and\ that\ it\ will\ be\ properly\ closed\ by\ the\ caller\ of\ this\ method\ after\ its\ use.\r\n\ @param\ level\ \ \ \ \ \ \ \ \ \ \ \ \ The\ level\ of\ the\ current\ game\ play.\r\n\ @param\ score\ \ \ \ \ \ \ \ \ \ \ \ \ The\ score\ obtained\ by\ the\ current\ game\ play.\r\n comment1.params=reader comment1.target=void\ outputHighScoreTable(java.io.BufferedReader) comment1.text=\r\n\ Outputs\ a\ highscore\ table\ by\ reading\ all\ the\ previously\ saved\ game\ records.\r\n\ \r\n\ You\ can\ assume\ there\ are\ only\ 10\ records\ in\ total.\r\n\ \r\n\ This\ method\ reads\ all\ the\ previously\ saved\ game\ records\ and\ outputs\ a\ highscore\ table\ in\ the\ terminal.\r\n\ You\ have\ to\ ensure\ that\ the\ records\ are\ sorted\ first\ by\ the\ score\ and\ then\ by\ the\ level\ in\ the\ table.\r\n\ The\ format\ of\ the\ highscore\ table\ is\ as\ follows\:\r\n\ \r\n\ 1.\ The\ name\ column\ should\ always\ has\ a\ width\ of\ 20\ characters.\r\n\ 2.\ The\ level\ column\ should\ always\ has\ a\ width\ of\ 10\ characters.\r\n\ 3.\ The\ score\ column\ should\ always\ has\ a\ width\ of\ 10\ characters.\r\n\ 4.\ The\ names\ in\ the\ name\ column\ should\ aligned\ to\ the\ left.\r\n\ 5.\ The\ levels\ in\ the\ level\ column\ should\ align\ to\ the\ right.\r\n\ 6.\ The\ scores\ in\ the\ score\ column\ should\ align\ to\ the\ right.\r\n\ 7.\ The\ second\ line\ should\ contains\ 40\ "-"\ characters.\r\n\ \r\n\ Here\ is\ an\ example\ of\ the\ highscore\ table\:\r\n\ \r\n\ name\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ level\ \ \ \ \ score\r\n\ ----------------------------------------\r\n\ abc\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 3\ \ \ \ \ \ \ \ 15\r\n\ hello\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ \ 15\r\n\ testing\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 3\ \ \ \ \ \ \ \ 14\r\n\ def\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ \ \ 8\r\n\ gg\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ \ \ \ \ \ \ \ \ 8\r\n\ 123\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ \ \ \ \ \ \ \ \ 4\r\n\ 667\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ \ \ 3\r\n\ 567\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 3\ \ \ \ \ \ \ \ \ 2\r\n\ \r\n\ @param\ reader\ \ \ \ The\ reader\ used\ to\ read\ all\ the\ records\ from\ a\ file.\ You\ can\ assume\ that\ the\ reader\ is\ already\ properly\ initialized\ and\ that\ it\ will\ be\ properly\ closed\ by\ the\ caller\ of\ this\ method\ after\ its\ use.\r\n\ @throws\ IOException\ If\ an\ error\ occurs\ when\ reading\ a\ line\ from\ the\ file.\r\n numComments=2