I'm trying to add a Ingame-shop System to my game, but now I get this Error and don't know what to do. Please help :)
Can you help me?
java.lang.ClassCastException: BossFight cannot be cast to game at Player.shop(Player.java:76) at Player.act(Player.java:29) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
int life = 3;
boolean canFire = true;
boolean canBuy = true;
boolean canBuy2 = true;
int abzug = 0;
int money = 0;
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Player()
{
setRotation(180);
}
public void act()
{
move();
fire();
shop();
hitByProjectile();
hitByProjectileMultiplayer();
}
public void move()
{
if(Greenfoot.isKeyDown("right"))
{
setLocation(getX()+8,getY());
}
if(Greenfoot.isKeyDown("left"))
{
setLocation(getX()-8,getY());
}
}
public void fire()
{
if (Greenfoot.isKeyDown("space") && canFire == true)
{
if (Greenfoot.getRandomNumber(100)<50)
{
getWorld().addObject(new Shot(),getX()+60, getY()-30);
canFire = false;
}
else
{
getWorld().addObject(new Shot(),getX()-60, getY()-30);
canFire = false;
}
}
else if (!Greenfoot.isKeyDown("space"))
{
canFire = true;
}
}
public void hitByProjectile()
{
Actor bossshot = getOneIntersectingObject(BossShot.class);
if (bossshot != null)
{
Greenfoot.setWorld(new CreditsLose());
}
}
public void shop()
{
World world = getWorld();
game game = (game)world;
Coins coins = game.getCoins();
money = game.getCoins().coins;
if (Greenfoot.isKeyDown("1") && canBuy == true && money > 50)
{
getWorld().addObject(new smallfleet(), 100, 500);
getWorld().addObject(new smallfleet(), 250, 500);
getWorld().addObject(new smallfleet(), 650, 500);
getWorld().addObject(new smallfleet(), 800, 500);
abzug = abzug+50;
canBuy = false;
} else if (!Greenfoot.isKeyDown("1"))
{
canBuy = true;
}
if (Greenfoot.isKeyDown("2") && canBuy2 == true && money > 100)
{
getWorld().addObject(new bigfleet(), 125, 450);
getWorld().addObject(new smallfleet(), 350, 500);
getWorld().addObject(new smallfleet(), 600, 500);
getWorld().addObject(new bigfleet(), 775, 450);
abzug = abzug+100;
canBuy = false;
} else if (!Greenfoot.isKeyDown("2"))
{
canBuy2 = true;
}
}
public void hitByProjectileMultiplayer()
{
Actor player2shot = getOneIntersectingObject(Player2Shot.class);
if (player2shot != null)
{
getWorld().removeObject(player2shot);
life--;
}
if (life == 0)
{
Greenfoot.setWorld(new Credits());
}
}
}