so currently I have a class with a method that prints something with the class name of the actor causing it to print.
But how can I make it so that no matter where I insert this method it pulls the name of the actor that is using the method?
right now this prints in the terminal:
TextPrinter:
Thank you for playing my game Angry Flappy
Please press ENTER to try again
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class TextPrinter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TextPrinter
{
String className = getClass().getName();
/**
* Constructor for objects of class TextPrinter
*/
public void endGame()
{
System.out.print("\f");
System.out.println(className + ":");
System.out.println("Thank you for playing my game Angry Flappy");
System.out.println("Please press ENTER to try again");
System.out.println();
return;
}
}TextPrinter printer = new TextPrinter();
public class Birdy extends Actor
{
public void birdDead()
{
GameMusic.stop();
Greenfoot.playSound("MBGameOver.mp3");
getWorld().addObject(new GameOver(), getWorld().getWidth()/2,getWorld().getHeight()/2);
printer.endGame();
}
}
