So this is my Soldier Superclass
its for a group project and im planning on combining my work with a friends (hence why i commented what i did in the takeDamage() method. Everything looks fine in this class yet when i create my subclasses and even added the attack method to both, i get an error on the c in the class line (which i will bold) saying "constructor Soldier in class Soldier cannot be applied to given types; and proceeds to list parameters in the constructor of Soldier.
i dont see whats wrong. i'd assume its because all the private instance variables are not protected meaning that the subclasses wouldn't be able to access them but im not sure. i would change it just to see but i dont want to screw up my code more by accident so im okay with waiting for a response, thanks for the help in advance!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Soldier here.
*
* @author (Prayan Jegathees)
* @version (0.1)
*/
public abstract class Soldier extends Actor
{
/**
* Private variables used for all soldier subclasses
* stats needed to determine the overall stats
* of the character
*
* LIFE is a boolean meant to change & detect the actors "death"
* TEAM is a string meant to choose which alliance the actor belongs to
*/
private int health;
private int speed;
private int atkPower;
private int atkRate;
private boolean life;
private String team;
/**
* Constructor for all Soldiers,
*/
public Soldier(int hp, int spd, int aPwr, int aRt, String alliance)
{
health = hp;
speed = spd;
atkPower = aPwr;
atkRate = aRt;
alliance = team;
life = true;
}
/**
* Attack - An abstract method that is called when the unit subclass
* wants to deal damage to an enemy unit
*/
public abstract void attack();
/**
* takeDamage - When soldier subunits are hit by projectiles and lose health
* (amount taken varies based on the type of projectile)
*/
public void takeDamage()
{
/*
if (isTouching(PROJECTILE_ARROW.class))
{
health -= 2;
}
if (isTouching(PROJECTILE_FIREBL.class))
{
health -= 5;
}
*/
if (health == 0)
{
life = false;
}
}
public void die()
{
if (!life)
{
move(0);
getImage().setTransparency(50);
setRotation(90);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Heavy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Heavy extends Soldier
{
/**
* Act - do whatever the Heavy 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.
}
public void attack()
{
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Knight here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Knight extends Soldier
{
/**
* Act - do whatever the Knight 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.
}
public void attack()
{
}
}
