Get Programming with JavaScript - Listing 15.05

Listing 15.05 - A player view

(function () { var getNameInfo = function (playerData) { return playerData.name; }; var getHealthInfo = function (playerData) { return "(" + playerData.health + ")"; }; var getItemsInfo = function (playerData) { var itemsString = "Items:" + spacer.newLine(); playerData.items.forEach(function (item, i) { itemsString += " - " + item + spacer.newLine(); }); return itemsString; }; var getTitleInfo = function (playerData) { return getNameInfo(playerData) + " " + getHealthInfo(playerData); }; var getInfo = function (playerData) { var info = spacer.box(getTitleInfo(playerData), 40, "*"); info += " " + getItemsInfo(playerData); info += spacer.line(40, "*"); info += spacer.newLine(); return info; }; var render = function (player) { console.log(getInfo(player.getData())); }; if (window.theCrypt === undefined) { window.theCrypt = {}; } theCrypt.playerView = { render: render }; })();