How to make a multiplier game like cookie clicker?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class cookie here. * * @author (your name) * @version (a version number or a date) */ public class cookie extends Actor { /** * Act - do whatever the cookie wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int cookies = 0 ; public void act() { if (Greenfoot.mouseClicked( this )) { cookies ++; } // Add your action code here. } public int getScore(){ return cookies; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class cookiespersec here. * * @author (your name) * @version (a version number or a date) */ public class cookiespersec extends Actor { /** * Act - do whatever the cookiespersec wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Color; import java.awt.Graphics; /** * Counter that displays a text and number. * * @author CWR * @version 1 - based on MIK's asteroid counter */ public class cookies extends Actor { private static final Color TEXT_COLOR = new Color( 250 , 250 , 250 ); private static final Color TRANSPARENT_COLOR = new Color( 0 , 0 , 0 , 0 ); private cookie cookie; public cookies(cookie cookie) { this .cookie = cookie; updateImage(); } public void act() { updateImage(); } private void updateImage() { String text = "" + cookie.getScore(); GreenfootImage image = new GreenfootImage(text, 50 , TEXT_COLOR, TRANSPARENT_COLOR); setImage(image); } } |