HTML and CSS Reference
In-Depth Information
Figure 11-5. The completed chess board
Tracking the Captured Pieces
When capturing a piece you simply deleted the object and that works since the piece doesn't need to be
displayed. However, if your application wants to keep track of the pieces that were captured you might want to
keep the object in the store. Now I'll show you how to change this to update the object instead of deleting it. I'll also
show you how to query this store to list the pieces that have been captured.
The first step is to change the removePiece() function. Instead of deleting the object at the end position,
you'll update it and set the killed property. You'll also need to change the pos property since there is a unique
index on this. Since the piece is not displayed, the position can be anything. To ensure it is unique, you'll prefix its
unique id with an “x”. Also, by prefixing these with an “x”, you'll be able to query for them, as I'll explain later.
Comment out the delete() call and add the code shown in bold:
function removePiece(end, oStart, startID, pieceStore) {
var index = pieceStore.index("piecePosition");
index.getKey(end).onsuccess = function (e4) {
var endID =;
if (endID) {
// pieceStore.delete (endID).onsuccess = function (e5) {
// movePiece(oStart, startID, pieceStore)
// }
index.get(end).onsuccess = function (e5) {
oEnd =;
oEnd.pos = 'x'+endID;
oEnd.killed = true;
pieceStore.put(oEnd, endID).onsuccess = function(e6){
movePiece(oStart, startID, end, pieceStore)
Search WWH ::

Custom Search