Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Candy-box Playable #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<body>
<section class="candy-section">
<p id="candy-counter"></p>
<p id="candies-eaten-text-box"></p>
</section>
</body>
</html>
62 changes: 62 additions & 0 deletions js/game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,66 @@
$(document).ready(function() {
// The world is yours to explore!
GAME.candies = 0;
GAME.candiesEaten = 0;
GAME.lolipops = 0;
GAME.redraw();

setInterval(GAME.getMoreCandies, 750);
setInterval(GAME.redraw, 500);


GAME.addButton('candies-eaten', 'Eat All Candies', GAME.eatAllCandies);
GAME.enableButton('candies-eaten');
GAME.addButton('lolipops-made', 'Transfer Candies to Lolipops', GAME.transferCandyLolipops);
GAME.disableButton('lolipops-made');

});

//Adds candies, needs a setinterval to function properly
GAME.getMoreCandies = function() {
GAME.candies = GAME.candies + 1;
}

GAME.transferCandyLolipops = function(){
GAME.lolipops += 1;
GAME.candies -= 10;
}

//Function that eats all the canides
GAME.eatAllCandies = function(){
GAME.candiesEaten = GAME.candiesEaten + GAME.candies;
GAME.candies = 0;
GAME.setText('candies-eaten','You have eaten' + candies);
}
//Function that sets all the text in the game
GAME.setAllText = function(){
GAME.setText('candy-counter', 'You have ' + GAME.candies + " candies.");

//If Statement that sets candies-eaten-text-box.
if(GAME.candiesEaten > 0 && GAME.candiesEaten < 10){
GAME.setText('candies-eaten-text-box', 'You have eaten ' + GAME.candiesEaten + ' candies.');
}else if(GAME.candiesEaten >= 10 && GAME.candiesEaten < 100){
GAME.setText('candies-eaten-text-box', 'You have eaten '+ GAME.candiesEaten + ' candies. :)');
}else if(GAME.candiesEaten >= 100 && GAME.candiesEaten < 1000){
GAME.setText('candies-eaten-text-box', 'You have eaten '+ GAME.candiesEaten + ' candies. :>');
}else if(GAME.candiesEaten >= 1000){
GAME.setText('candies-eaten-text-box', 'You have eaten '+ GAME.candiesEaten +' candies. Y u so fat?');
}
GAME.setText('','You have ' + GAME.lolipops + 'lolipops');

//If Statement that disables eat candies button if number of canides is less than or equal to 0.
if(GAME.candies <= 0){
GAME.disableButton('candies-eaten');
}else{
GAME.enableButton('candies-eaten');
}

if(GAME.candies > 10){
GAME.enableButton('lolipops-made');
}
}

GAME.redraw = function(){
GAME.setAllText();
}