This site requires JavaScript, please enable it in your browser!
Greenfoot back
milanapa
milanapa wrote ...

2011/12/21

HELLO

milanapa milanapa

2011/12/21

#
anyone can check my coding. i want to make the score appear when eat fish import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.util.List; import java.util.ArrayList; import java.awt.Color; import java.awt.Font; import java.util.Calendar; public class ular extends Makhluk { public int ikan2Makan; public static final float FONT_SIZE = 20.0f; public static final int WIDTH = 400; public static final int HEIGHT = 300; public ular() { ikan2Makan = 0; } public void act() { jumpaIkan2( ); //keyControlMove(); jumpaRumpai2(); mouse(); } private void upScore() { Ocean a = (Ocean) getWorld(); // Counter counter = a.getCounter(); // counter.bumpCount(1); } public void keyControlMove()//controls movement of ghost { if( Greenfoot.isKeyDown( "up")) { setLocation(getX(), getY()-10); } if( Greenfoot.isKeyDown( "down")) { setLocation(getX(), getY()+10); } if( Greenfoot.isKeyDown( "left")) { setLocation(getX()-10, getY()); } if( Greenfoot.isKeyDown( "right")) { setLocation(getX()+10, getY()); } } public void jumpaIkan2( ) { if (canSee(Ikan.class)) { eat(Ikan.class); Greenfoot.playSound("au.wav"); upScore(); World w = getWorld(); w.addObject ( new buih(), getX(), getY()); w.addObject ( new tulangIkan(), getX(), getY()); ikan2Makan = ikan2Makan + 1; if (ikan2Makan == 10) { Greenfoot.stop(); javax.swing.JOptionPane.showMessageDialog(null, "Game over!!!"); } } } public void jumpaRumpai2( ) { if (canSee(rumpai.class)) { eat(rumpai.class); upScore(); Greenfoot.playSound("au.wav"); World w = getWorld(); w.addObject ( new buih(), getX(), getY()); w.addObject ( new tulangIkan(), getX(), getY()); ikan2Makan = ikan2Makan + 1; if (ikan2Makan == 10) { Greenfoot.stop(); javax.swing.JOptionPane.showMessageDialog(null, "Game over!!!"); } } } public void mouse() {if (Greenfoot.mouseMoved(null) ) { MouseInfo mouse = Greenfoot.getMouseInfo(); setLocation (mouse.getX(), mouse.getY()); } } }
Royalblue64 Royalblue64

2011/12/21

#
I suppose that the bumpCount method adds the specified number to the target score, so I really don't see any problem with the code if you uncomment those lines. I actually just worked with score counters myself, and it was rather difficult to figure out how to access them, but from what I know, this looks like it should be okay. However, by you posting this, it probably doesn't work properly, so the problem may be in the Counter class?
milanapa milanapa

2011/12/21

#
maybe the problem in counter class.my counter class is import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class Counter extends Actor { public int totalCount = 0; public Counter() { setImage(new GreenfootImage("JUMLAH IKAN (^_^): ", 20, Color.WHITE, Color.BLUE)); } public void bumpCount(int amount) { totalCount += amount; setImage(new GreenfootImage("JUMLAH IKAN (^_^): " + totalCount, 20, Color.WHITE, Color.BLACK)); } }
Royalblue64 Royalblue64

2011/12/21

#
Well, for one thing you're using GreenfootImage for a string, you should probably use a getImage().setColor(Color.BLACK) // Or whatever color you want drawString("JUMLAH IKAN (^_^): " + totalCount, x coordinate, y coordinate) The way that is shown here is not really a good idea, if you want to take a look at the counter that Michael Kolling created, it's fully functional (of course). I tried doing it on my own, but it didn't work out because it is far too complicated for me. I suggest taking a look at Michael's counter for ideas if you won't use it.
You need to login to post a reply.