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());
}
}
}