Skip to content

Commit

Permalink
added one more exclusive brackground
Browse files Browse the repository at this point in the history
  • Loading branch information
daimessdn committed Mar 10, 2021
1 parent 7708417 commit 7aa759d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 63 deletions.
3 changes: 2 additions & 1 deletion aquarium.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ <h3 id="game-notification"></h3>

<h3 id="game-helper">
<kbd>1</kbd>buy a fish ($100)<br />
<kbd>2</kbd>buy a background ($1000)<br />
<kbd>2</kbd>buy background 1 ($1000)<br />
<kbd>3</kbd>buy background 2 ($2000)<br />
<kbd>esc</kbd>toggle pause mode<br />
<kbd>shift</kbd> + <kbd>/</kbd>toggle help<br />
<kbd>0</kbd>switch background<br />
Expand Down
65 changes: 35 additions & 30 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,36 +297,10 @@ document.body.addEventListener("keydown", (event) => {
}
}
else if (event.key === "2") {
if (game.isPaused === false) {
// in case of you still have fish
if (game.fish.length > 0) {
if (game.cash >= 1000 && !fishTanks.includes("aquarium2")) {
// if your money is enought and you can afford the background
fishTanks.push("aquarium2");
tankAddedSound.play();
triggerNotification("Congratulations! You've bought a new background! Your fish must be love it.", "");
aquariumIteration += 1;
aquarium.style.backgroundImage = `linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
url("src/img/aquariums/${fishTanks[aquariumIteration % fishTanks.length]}.svg")`;
game.cash -= 1000;
game.updateStats();
}
else if (fishTanks.includes("aquarium2")) {
// in case you already ahve a background
triggerNotification("You have already bought a background!", "");
}
else {
// your money is not enough
triggerNotification("Your money is not enough to buy a background!", "");
}
}
else {
triggerNotification("Your game is already over. You cannot buy a background anymore.", "All your fish are died. Please reload (Ctrl + R) to restart game.");
}
}
else {
triggerNotification("You cannot buy a background in paused mode!", "Game paused");
}
buyBackground("aquarium2", 1000);
}
else if (event.key === "3") {
buyBackground("aquarium3", 2000);
}
else if (event.key === "0") {
// switch background
Expand Down Expand Up @@ -365,3 +339,34 @@ function pauseGame() {
feedInput.disabled = game.isPaused ? true : false;
gameNotification.textContent = game.isPaused ? "Game paused" : "";
}
function buyBackground(background, price) {
if (game.isPaused === false) {
// in case of you still have fish
if (game.fish.length > 0) {
if (game.cash >= 1000 && !fishTanks.includes(background)) {
// if your money is enought and you can afford the background
fishTanks.push(background);
tankAddedSound.play();
triggerNotification("Congratulations! You've bought a new background! Your fish must be love it.", "");
aquarium.style.backgroundImage = `linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
url("src/img/aquariums/${background}.svg")`;
game.cash -= price;
game.updateStats();
}
else if (fishTanks.includes(background)) {
// in case you already ahve a background
triggerNotification("You have already bought a background!", "");
}
else {
// your money is not enough
triggerNotification("Your money is not enough to buy a background!", "");
}
}
else {
triggerNotification("Your game is already over. You cannot buy a background anymore.", "All your fish are died. Please reload (Ctrl + R) to restart game.");
}
}
else {
triggerNotification("You cannot buy a background in paused mode!", "Game paused");
}
}
69 changes: 37 additions & 32 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,38 +377,9 @@ document.body.addEventListener("keydown", (event) => {
"Game paused");
}
} else if (event.key === "2") {
if (game.isPaused === false) {
// in case of you still have fish
if (game.fish.length > 0) {
if (game.cash >= 1000 && !fishTanks.includes("aquarium2")) {
// if your money is enought and you can afford the background
fishTanks.push("aquarium2");

tankAddedSound.play();
triggerNotification("Congratulations! You've bought a new background! Your fish must be love it.", "");

aquariumIteration += 1;
aquarium.style.backgroundImage = `linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
url("src/img/aquariums/${
fishTanks[aquariumIteration % fishTanks.length]
}.svg")`;
game.cash -= 1000;
game.updateStats();
} else if (fishTanks.includes("aquarium2")) {
// in case you already ahve a background
triggerNotification("You have already bought a background!", "");
} else {
// your money is not enough
triggerNotification("Your money is not enough to buy a background!", "");
}
} else {
triggerNotification("Your game is already over. You cannot buy a background anymore.",
"All your fish are died. Please reload (Ctrl + R) to restart game.");
}
} else {
triggerNotification("You cannot buy a background in paused mode!",
"Game paused");
}
buyBackground("aquarium2", 1000);
} else if (event.key === "3") {
buyBackground("aquarium3", 2000);
} else if (event.key === "0") {
// switch background
aquariumIteration += 1;
Expand Down Expand Up @@ -450,4 +421,38 @@ function pauseGame() {

feedInput.disabled = game.isPaused ? true : false;
gameNotification.textContent = game.isPaused ? "Game paused" : "";
}

function buyBackground(background: string, price: number) {
if (game.isPaused === false) {
// in case of you still have fish
if (game.fish.length > 0) {
if (game.cash >= 1000 && !fishTanks.includes(background)) {
// if your money is enought and you can afford the background
fishTanks.push(background);

tankAddedSound.play();
triggerNotification("Congratulations! You've bought a new background! Your fish must be love it.", "");

aquarium.style.backgroundImage = `linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
url("src/img/aquariums/${
background
}.svg")`;
game.cash -= price;
game.updateStats();
} else if (fishTanks.includes(background)) {
// in case you already ahve a background
triggerNotification("You have already bought a background!", "");
} else {
// your money is not enough
triggerNotification("Your money is not enough to buy a background!", "");
}
} else {
triggerNotification("Your game is already over. You cannot buy a background anymore.",
"All your fish are died. Please reload (Ctrl + R) to restart game.");
}
} else {
triggerNotification("You cannot buy a background in paused mode!",
"Game paused");
}
}

0 comments on commit 7aa759d

Please sign in to comment.