1- define ( [ 'lodash' , 'serverGateway' , 'userCountView' , 'multipierView' , 'user' , 'userAccountAmountView' , 'minefieldView' , 'minefield' , 'minesView' , 'authenticationService' , 'game' ] ,
2- function ( _ , ServerGateway , UserCountView , MultipierView , User , UserAccountAmountView , MinefieldView , MinefieldModel , MinesView , AuthenticationService , Game ) {
1+ define ( [ 'lodash' , 'serverGateway' , 'userCountView' , 'multipierView' , 'user' , 'userAccountAmountView' , 'minefieldView' , 'minefield' , 'minesView' , 'authenticationService' , 'game' , 'bootbox' ] ,
2+ function ( _ , ServerGateway , UserCountView , MultipierView , User , UserAccountAmountView , MinefieldView , MinefieldModel , MinesView , AuthenticationService , Game , bootbox ) {
33 function MainPageController ( ) {
44 this . userCountView = new UserCountView ( ) ;
55 this . multipierView = new MultipierView ( ) ;
@@ -32,7 +32,7 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
3232 this . minesView . disableMinesSelect ( ) ;
3333 this . multipierView . disable ( ) ;
3434 } else {
35- alert ( 'Your bet is greater than your cash amount. Please deposit or change your bet.' ) ;
35+ this . minefieldView . showMessage ( 'Your bet is greater than your cash amount. Please deposit or change your bet.' ) ;
3636 }
3737 }
3838
@@ -44,6 +44,11 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
4444 this . minefieldView . cleanState ( ) ;
4545 this . minefieldModel . cleanState ( ) ;
4646 this . updateMinesMultiplier ( ) ;
47+ if ( Game . isFinishedByUser ( ) ) {
48+ this . minefieldView . showMessage ( "You won!" ) ;
49+ } else {
50+ this . minefieldView . showMessage ( "Sorry, you lost!" ) ;
51+ }
4752 Game . finishByApp ( ) ;
4853 }
4954
@@ -77,15 +82,23 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
7782 }
7883 }
7984
85+ MainPageController . prototype . initViews = function ( ) {
86+ this . userCountView . update ( Game . getUserCount ( ) ) ;
87+ this . userAccountAmountView . update ( this . user . getAccountAmount ( ) ) ;
88+ this . multipierView . update ( Game . getAvailableBets ( ) , this . user . getAccountAmount ( ) ) ;
89+ }
90+
8091 MainPageController . prototype . handleRequest = function ( ) {
8192 var that = this ;
93+
8294 this . serverGateway = ServerGateway ;
8395 this . authenticationService . authenticate ( ) ;
8496
85- this . serverGateway . registerCallback ( "objectsync" , function ( objectsyncJson ) {
86- var objectSync = JSON . parse ( objectsyncJson ) ;
97+ this . initViews ( ) ;
8798
8899
100+ this . serverGateway . registerCallback ( "objectsync" , function ( objectsyncJson ) {
101+ var objectSync = JSON . parse ( objectsyncJson ) ;
89102
90103 if ( _ . isObject ( objectSync ) ) {
91104 _ . forEach ( objectSync , function ( value , key ) {
@@ -134,11 +147,6 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
134147 that . updateMinesMultiplier ( object . multi ) ;
135148
136149 } else if ( _ . has ( object , 'done' ) ) {
137- if ( Game . isFinishedByUser ( ) ) {
138- that . minefieldView . showMessage ( "You won!" ) ;
139- } else {
140- that . minefieldView . showMessage ( "Sorry, you lost!" ) ;
141- }
142150 that . finishGameAction ( ) ;
143151 }
144152 }
@@ -149,8 +157,9 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
149157 console . log ( value ) ;
150158
151159 if ( _ . has ( value , 'cash' ) ) {
152- that . user . setAccountAmount ( value [ 'cash' ] ) ;
153- that . userAccountAmountView . update ( value [ 'cash' ] ) ;
160+ var transformedMoney = value [ 'cash' ] / 100000000 ;
161+ that . user . setAccountAmount ( transformedMoney ) ;
162+ that . userAccountAmountView . update ( transformedMoney ) ;
154163 }
155164 if ( _ . has ( value , 'address_deposit' ) ) {
156165 that . user . setDepositAddresses ( value [ 'address_deposit' ] ) ;
@@ -165,10 +174,12 @@ define(['lodash', 'serverGateway', 'userCountView', 'multipierView', 'user', 'us
165174
166175 if ( _ . has ( value , 'users' ) ) {
167176 that . userCountView . update ( value [ 'users' ] ) ;
177+ Game . setUserCount ( value [ 'users' ] ) ;
168178 }
169179
170180 if ( _ . has ( value , 'availiablebets' ) ) {
171181 that . multipierView . update ( value [ 'availiablebets' ] , that . user . getAccountAmount ( ) ) ;
182+ Game . setAvailableBets ( value [ 'availiablebets' ] )
172183 }
173184 }
174185 }
0 commit comments