108 lines
3.1 KiB
JavaScript
108 lines
3.1 KiB
JavaScript
function create_player_stats() {
|
|
let x = Math.floor(Math.random() * 2) + 1;
|
|
let y = 0;
|
|
if (x == 1) {
|
|
y = 2;
|
|
} else {
|
|
y = 1;
|
|
}
|
|
return { x: x, y: y };
|
|
}
|
|
|
|
let x, y;
|
|
function init() {
|
|
if (localStorage.getItem("player_x")) {
|
|
x = parseInt(localStorage.getItem("player_x"));
|
|
y = parseInt(localStorage.getItem("player_y"));
|
|
} else {
|
|
let player = create_player_stats();
|
|
x = player.x;
|
|
y = player.y;
|
|
localStorage.setItem("player_x", x);
|
|
localStorage.setItem("player_y", y);
|
|
}
|
|
return { x: x, y: y };
|
|
}
|
|
let player = init();
|
|
let gamedata = {
|
|
fishing: {
|
|
per_hour: player.x,
|
|
preserver: "No",
|
|
stored: 0,
|
|
},
|
|
foraging: {
|
|
per_hour: player.y,
|
|
boat: "No",
|
|
stored: 0,
|
|
},
|
|
hours: 16,
|
|
days: 0,
|
|
};
|
|
|
|
function updateTable() {
|
|
document.getElementById("fish_p_hour").innerText = gamedata.fishing.per_hour;
|
|
document.getElementById("wood_p_hour").innerText = gamedata.foraging.per_hour;
|
|
document.getElementById("fish_stored").innerText = gamedata.fishing.stored;
|
|
document.getElementById("wood_stored").innerText = gamedata.foraging.stored;
|
|
document.getElementById("preserver").innerText = gamedata.fishing.preserver;
|
|
document.getElementById("boat").innerText = gamedata.foraging.boat;
|
|
document.getElementById("hours").innerText = gamedata.hours;
|
|
document.getElementById("days").innerText = gamedata.days;
|
|
if (gamedata.hours < 8) {
|
|
document.getElementById("improve-fishing").disabled = true;
|
|
} else {
|
|
document.getElementById("improve-fishing").disabled = false;
|
|
}
|
|
if (gamedata.hours < 8) {
|
|
document.getElementById("improve-forgaing").disabled = true;
|
|
} else {
|
|
document.getElementById("improve-forgaing").disabled = false;
|
|
}
|
|
if (gamedata.foraging.stored < 25 || gamedata.hours < 8) {
|
|
document.getElementById("build-preserver").disabled = true;
|
|
} else {
|
|
document.getElementById("build-preserver").disabled = false;
|
|
}
|
|
if (gamedata.foraging.stored < 100 || gamedata.hours < 16) {
|
|
document.getElementById("build-boat").disabled = true;
|
|
} else {
|
|
document.getElementById("build-boat").disabled = false;
|
|
}
|
|
}
|
|
|
|
function go_fishing() {
|
|
let prompt = window.prompt("How many hours do you want to fish?");
|
|
if (prompt === null || prompt > gamedata.hours) {
|
|
window.alert("You dont have the hours for this or prompt exited");
|
|
console.log("Prompt Exited");
|
|
} else {
|
|
gamedata.fishing.stored += prompt * gamedata.fishing.per_hour;
|
|
gamedata.hours -= prompt;
|
|
if (gamedata.hours === 0) {
|
|
gamedata.days++;
|
|
gamedata.hours = 16;
|
|
}
|
|
updateTable();
|
|
}
|
|
}
|
|
|
|
function go_foraging() {
|
|
let prompt = window.prompt("How many hours do you want to foraging?");
|
|
if (prompt === null || prompt > gamedata.hours) {
|
|
window.alert("You dont have the hours for this or prompt exited");
|
|
console.log("Prompt Exited");
|
|
} else {
|
|
gamedata.foraging.stored += prompt * gamedata.foraging.per_hour;
|
|
gamedata.hours -= prompt;
|
|
if (gamedata.hours === 0) {
|
|
gamedata.days++;
|
|
gamedata.hours = 16;
|
|
}
|
|
updateTable();
|
|
}
|
|
}
|
|
document.getElementById("go-fishing").onclick = go_fishing;
|
|
document.getElementById("go-foraging").onclick = go_foraging;
|
|
|
|
updateTable();
|