COC / wwwroot /script.js
Sahil
Create wwwroot/script.js
cdc08c6 verified
raw
history blame contribute delete
768 Bytes
async function updatePlayer() {
const res = await fetch('/player');
const player = await res.json();
document.getElementById('gold').textContent = player.Gold;
document.getElementById('elixir').textContent = player.Elixir;
document.getElementById('buildings').textContent = player.Buildings.join(', ');
document.getElementById('troops').textContent = player.Troops.join(', ');
}
async function collectGold() {
await fetch('/collect-gold', { method: 'POST' });
updatePlayer();
}
async function placeBuilding(name) {
await fetch(`/place-building/${name}`, { method: 'POST' });
updatePlayer();
}
async function trainTroop(type) {
await fetch(`/train-troop/${type}`, { method: 'POST' });
updatePlayer();
}
// Load initial state
updatePlayer();