@@ -85,8 +85,81 @@ function testAsteroidsAttractMenuFlow() {
8585 assert . equal ( scene . attractController . active , false ) ;
8686}
8787
88+ function testAsteroidsGameOverQualifyingScoreInitialsFlow ( ) {
89+ const scene = new AsteroidsGameScene ( ) ;
90+ const storage = createStorage ( ) ;
91+ scene . highScoreService = new AsteroidsHighScoreService ( { storage, tableSize : 5 } ) ;
92+ scene . highScoreRows = [
93+ { initials : 'ACE' , score : 1800 } ,
94+ { initials : 'VTR' , score : 1400 } ,
95+ { initials : 'ION' , score : 1000 } ,
96+ { initials : 'CPU' , score : 700 } ,
97+ { initials : 'BOT' , score : 500 } ,
98+ ] ;
99+ scene . session . players = [
100+ { id : 1 , score : 1900 , lives : 0 , nextExtraLifeScore : 10000 , worldState : null } ,
101+ ] ;
102+ scene . session . activePlayerIndex = 0 ;
103+ scene . session . mode = 'game-over' ;
104+ scene . initialsEntry . cancel ( ) ;
105+
106+ const engine = {
107+ input : createInput ( ) ,
108+ canvas : { style : { } } ,
109+ } ;
110+
111+ scene . update ( 0.016 , engine ) ;
112+ assert . equal ( scene . initialsEntry . active , true ) ;
113+ assert . equal ( scene . initialsEntry . score , 1900 ) ;
114+ assert . equal ( scene . isGameOverScreenVisible ( ) , false ) ;
115+
116+ engine . input = createInput ( { pressed : [ 'Enter' ] } ) ;
117+ scene . update ( 0.016 , engine ) ;
118+
119+ assert . equal ( scene . initialsEntry . active , false ) ;
120+ assert . equal ( scene . session . mode , 'menu' ) ;
121+ assert . equal ( scene . highScoreRows . length , 5 ) ;
122+ assert . equal ( scene . highScoreRows [ 0 ] . initials , 'AAA' ) ;
123+ assert . equal ( scene . highScoreRows [ 0 ] . score , 1900 ) ;
124+ for ( let index = 1 ; index < scene . highScoreRows . length ; index += 1 ) {
125+ assert . equal ( scene . highScoreRows [ index - 1 ] . score >= scene . highScoreRows [ index ] . score , true ) ;
126+ }
127+ }
128+
129+ function testAsteroidsMenuHighScoreUsesLeaderboardTop ( ) {
130+ const scene = new AsteroidsGameScene ( ) ;
131+ scene . highScoreRows = [
132+ { initials : 'ACE' , score : 1800 } ,
133+ { initials : 'VTR' , score : 1400 } ,
134+ { initials : 'ION' , score : 1000 } ,
135+ { initials : 'CPU' , score : 700 } ,
136+ { initials : 'BOT' , score : 500 } ,
137+ ] ;
138+ scene . session . highScore = 2500 ;
139+ scene . session . mode = 'menu' ;
140+ scene . attractController . active = false ;
141+
142+ const textCalls = [ ] ;
143+ const renderer = {
144+ drawRect ( ) { } ,
145+ strokeRect ( ) { } ,
146+ drawPolygon ( ) { } ,
147+ drawLine ( ) { } ,
148+ drawCircle ( ) { } ,
149+ drawText ( text , ...rest ) {
150+ textCalls . push ( [ text , ...rest ] ) ;
151+ } ,
152+ } ;
153+
154+ scene . render ( renderer ) ;
155+ assert . equal ( textCalls . some ( ( [ text ] ) => text === 'HIGH SCORE 1800' ) , true ) ;
156+ assert . equal ( textCalls . some ( ( [ text ] ) => text === 'HIGH SCORE 2500' ) , false ) ;
157+ }
158+
88159export function run ( ) {
89160 testAsteroidsHighScoreService ( ) ;
90161 testAsteroidsInitialsEntry ( ) ;
91162 testAsteroidsAttractMenuFlow ( ) ;
163+ testAsteroidsGameOverQualifyingScoreInitialsFlow ( ) ;
164+ testAsteroidsMenuHighScoreUsesLeaderboardTop ( ) ;
92165}
0 commit comments