-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript-shop.js
82 lines (69 loc) · 2.81 KB
/
javascript-shop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function hideShop()
{
var shop = document.getElementById("shop");
shop.parentNode.removeChild(shop);
var shop2 = document.getElementById("shop2");
shop2.parentNode.removeChild(shop2);
}
function appendShopItem(shopItem)
{
// Create the list item:
item = document.createElement( 'li' );
// Set its contents:
item.appendChild( document.createTextNode(
shopItem.name + ' - ' + shopItem.cost + ' Gold'
) );
item.id = "shop2";
// Add it to the list:
list.appendChild( item );
var radio = document.createElement( 'button' );
var text = document.createTextNode( "Buy " + shopItem.name + " for " + shopItem.cost + " Gold");
radio.name = 'shop';
radio.value = shopItem.name;
radio.id = "shop";
radio.style.display = "inline-block";
radio.style.textAlign = "left";
radio.onclick = function () {
addValue( shopItem );
};
radio.appendChild( text );
document.getElementById("centeredDiv").appendChild( radio );
}
function addValue(shopItem)
{
if (subTotal <= gold)
{
subTotal += parseInt(shopItem.cost);
var object = {name: shopItem.name, description: shopItem.description}
alert("Bought " + shopItem.name + " for " + shopItem.cost + " Gold.")
gold -= shopItem.cost;
document.getElementById("infoHeader").innerHTML = "Your Gold: " + gold;
playerItems.push(object);
document.getElementById("extraSubHeader").innerHTML = "Current Total: " + subTotal + " Gold";
} else
{
alert("You don't have enough Gold....");
}
}
function enterShop(position, locations, buttons, shopItems, shopCosts)
{
document.getElementById("extraHeader").style.visibility = "visible";
document.getElementById("extraHeader").innerHTML = "Welcome to the Shop!";
document.getElementById("extraSubHeader").style.visibility = "visible";
document.getElementById("extraSubHeader").innerHTML = "Current Total: 0 Gold";
document.getElementById("infoHeader").style.visibility = "visible";
document.getElementById("infoHeader").innerHTML = "Your Gold: " + gold;
document.getElementById("list").style.visibility = "visible";
document.getElementById("option1").style.visibility = "hidden";
document.getElementById("option2").style.visibility = "hidden";
document.getElementById("optionalInfo").style.visibility = "hidden";
document.getElementById("list2").style.visibility = "hidden";
document.getElementById("stats").style.visibility = "hidden";
document.getElementById("actionButton").innerHTML = "Leave Shop";
document.getElementById("actionButton").onclick = function (){ loadData(position, locations, buttons, shopItems, shopCosts); hideShop(); }
document.getElementById("header").style.visibility = "hidden";
for( var i = 0; i < shopItems.length; ++i )
{
appendShopItem( shopItems[i] );
}
}