diff --git a/card.js b/card.js index 0c0a608..dca1639 100644 --- a/card.js +++ b/card.js @@ -99,4 +99,17 @@ MemoryGame.Card.prototype = Object.create(EventDispatcher.prototype); MemoryGame.Card.prototype.constructor = MemoryGame.Card; + /** + * Check to see if the given object corresponds with the semantics for + * a memory game card. + * + * @param {object} params + * @returns {boolean} + */ + MemoryGame.Card.isValid = function (params) { + return (params !== undefined && + params.image !== undefined && + params.image.path !== undefined); + }; + })(H5P.MemoryGame, H5P.EventDispatcher, H5P.jQuery); diff --git a/library.json b/library.json index 158341f..a831a73 100644 --- a/library.json +++ b/library.json @@ -3,7 +3,7 @@ "description": "See how many cards you can remember!", "majorVersion": 1, "minorVersion": 1, - "patchVersion": 6, + "patchVersion": 8, "runnable": 1, "author": "Amendor AS", "license": "MIT", @@ -30,4 +30,4 @@ "path": "popup.js" } ] -} \ No newline at end of file +} diff --git a/memory-game.js b/memory-game.js index 6ca5e48..845fe3b 100644 --- a/memory-game.js +++ b/memory-game.js @@ -103,11 +103,13 @@ H5P.MemoryGame = (function (EventDispatcher, $) { // Initialize cards. for (var i = 0; i < parameters.cards.length; i++) { - // Add two of each card - var cardOne = new MemoryGame.Card(parameters.cards[i], id); - var cardTwo = new MemoryGame.Card(parameters.cards[i], id); - addCard(cardOne, cardTwo); - addCard(cardTwo, cardOne); + if (MemoryGame.Card.isValid(parameters.cards[i])) { + // Add two of each card + var cardOne = new MemoryGame.Card(parameters.cards[i], id); + var cardTwo = new MemoryGame.Card(parameters.cards[i], id); + addCard(cardOne, cardTwo); + addCard(cardTwo, cardOne); + } } H5P.shuffleArray(cards);