@@ -28,6 +28,7 @@ class Ship {
28
28
isVertical = true ;
29
29
hits = 0 ;
30
30
element : HTMLElement ;
31
+ cells : Cell [ ] ;
31
32
32
33
constructor ( public size : number ) {
33
34
this . element = $ ( "<div class='ship'></div>" ) [ 0 ] ;
@@ -185,6 +186,13 @@ class Board {
185
186
}
186
187
}
187
188
189
+ markShipBombed ( ship : Ship ) {
190
+ for ( var i = 0 ; i < ship . size ; i ++ ) {
191
+ $ ( ship . cells [ i ] . element ) . removeClass ( "cellHit" ) ;
192
+ $ ( ship . cells [ i ] . element ) . addClass ( "cellShipHit" ) ;
193
+ }
194
+ }
195
+
188
196
bombCell ( cellElem : HTMLElement ) {
189
197
var cellPos = Cell . parseCellLocation ( $ ( cellElem ) . data ( "cellLocation" ) ) ;
190
198
var cell = this . cells [ cellPos . row ] [ cellPos . column ] ;
@@ -199,6 +207,7 @@ class Board {
199
207
var ship = this . ships [ cell . shipIndex ] ;
200
208
ship . hits ++ ;
201
209
if ( ship . isSunk ( ) ) {
210
+ this . markShipBombed ( ship ) ;
202
211
if ( this . allShipsSunk ( ) ) {
203
212
this . onEvent . call ( this , 'allSunk' ) ;
204
213
} else {
@@ -266,14 +275,16 @@ class Board {
266
275
var ship = this . ships [ index ]
267
276
ship . hits = 0 ;
268
277
var cells = ship . getCellsCovered ( ) ;
278
+ ship . cells = [ ]
269
279
for ( var cell = 0 ; cell < cells . length ; cell ++ ) {
270
280
var cellPos = Cell . parseCellLocation ( cells [ cell ] ) ;
271
281
var targetCell = this . cells [ cellPos . row ] [ cellPos . column ] ;
272
282
targetCell . shipIndex = index ;
283
+ ship . cells . push ( targetCell ) ;
273
284
}
274
285
}
275
286
276
- $ ( this . element ) . children ( ".cell" ) . removeClass ( "cellHit cellMiss" ) . addClass ( "notBombed" ) ;
287
+ $ ( this . element ) . children ( ".cell" ) . removeClass ( "cellHit cellMiss cellShipHit " ) . addClass ( "notBombed" ) ;
277
288
}
278
289
279
290
private allShipsSunk ( ) {
0 commit comments