Skip to content

Commit

Permalink
added silver resource, mines
Browse files Browse the repository at this point in the history
  • Loading branch information
Areso committed Jan 1, 2020
1 parent 2245f97 commit 03eb0eb
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions index.html
Expand Up @@ -9,30 +9,41 @@
</style>
</head>
<body>
<button id="btnUpgCopperMine" onclick="upgCopperMine()" style="width: 240px;">Улучшить медную шахту, 10 медных монет</button><br>
<button id="btnUpgCopperMine" onclick="upgCopperMine()" style="width: 240px;">Улучшить медную шахту, 15 медных монет</button><br>
Медные монеты: <span id="spnCoppersValue">0</span><br>
Скорость заработка медных монет: <span id="spnCoppersRate">1</span> в 2 секунды<br>
<button id="btnUpgSilverMine" onclick="upgSilverMine()" style="width: 240px;">Построить серебряную шахту, 50 медных монет</button><br>
Серебряные монеты: <span id="spnSilversValue">0</span><br>
Скорость заработка серебряных монет: <span id="spnSilversRate">0</span> в 2 секунды<br>
<button id="btnSaveGame" onclick="saveGame()" style="width: 240px;">Сохранить игру</button><br>
<button id="btnLoadGame" onclick="loadGame()" style="width: 240px;">Загрузить игру</button><br>
<script>
let game = {
coppers: 1,
copperGrowth: 1,
coppersUpgLevel: 1,
silvers: 0,
silverGrowth: 1,
silversUpgLevel: 0,
}
let win_condition = 50;
let silverMineBasePriceCoppers = 100;
myTimer = setInterval(endOfTurnCalc, 2000);
function endOfTurnCalc() {
if (game.coppers < win_condition) {
if (game.silvers < win_condition) {
game.coppers = game.coppers+game.copperGrowth*game.coppersUpgLevel;
game.silvers = game.silvers+game.silverGrowth*game.silversUpgLevel;
updateUI();
} else {
clearTimeout(myTimer);
alert("Вы достигли цели! Вы накопили "+win_condition.toString());
}
}
function coppersUpgCost() {
return game.coppersUpgLevel*10;
return game.coppersUpgLevel*10+5;
}
function silversUpgCost() {
return game.silversUpgLevel*10+5;
}
function upgCopperMine() {
if (game.coppers>=coppersUpgCost()){
Expand All @@ -41,12 +52,38 @@
updateUI();
}
}
function upgSilverMine() {
if (game.silversUpgLevel===0){
if (game.coppers>=silverMineBasePriceCoppers){
game.coppers = game.coppers-silverMineBasePriceCoppers;
game.silversUpgLevel = 1;
updateUI();
}
} else {
if (game.silvers>=silversUpgCost()){
game.silvers = game.silvers-silversUpgCost();
game.silversUpgLevel = game.silversUpgLevel + 1;
updateUI();
}
}
}
function updateUI() {
document.getElementById("spnCoppersValue").innerHTML = game.coppers;
document.getElementById("btnUpgCopperMine").innerHTML = "Улучшить медную шахту, ";
document.getElementById("btnUpgCopperMine").innerHTML += coppersUpgCost().toString();
document.getElementById("btnUpgCopperMine").innerHTML += " медных монет";
document.getElementById("spnCoppersRate").innerHTML = game.copperGrowth*game.coppersUpgLevel;
document.getElementById("spnCoppersValue").innerHTML = game.coppers;
document.getElementById("btnUpgCopperMine").innerHTML = "Улучшить медную шахту, ";
document.getElementById("btnUpgCopperMine").innerHTML += coppersUpgCost().toString();
document.getElementById("btnUpgCopperMine").innerHTML += " медных монет";
document.getElementById("spnCoppersRate").innerHTML = game.copperGrowth*game.coppersUpgLevel;
document.getElementById("spnSilversValue").innerHTML = game.silvers;
if (game.silversUpgLevel===0) {
document.getElementById("btnUpgSilverMine").innerHTML = "Построить серебряную шахту, ";
document.getElementById("btnUpgSilverMine").innerHTML += silverMineBasePriceCoppers.toString();
document.getElementById("btnUpgSilverMine").innerHTML += " медных монет";
} else {
document.getElementById("btnUpgSilverMine").innerHTML = "Улучшить серебряную шахту, ";
document.getElementById("btnUpgSilverMine").innerHTML += silversUpgCost().toString();
document.getElementById("btnUpgSilverMine").innerHTML += " серебряных монет";
}
document.getElementById("spnSilversRate").innerHTML = game.silverGrowth*game.silversUpgLevel;
}
function saveGame() {
localStorage.setItem('gameTutorial', JSON.stringify(game));
Expand Down

0 comments on commit 03eb0eb

Please sign in to comment.