Log in

View Full Version : help me with my code plz



waleed
03-07-2013, 08:33 PM
this is the class skill


import java.util.HashMap;

public class Skill {
HashMap<String, Boolean> h;
int [] array ;
public static final String[] EFFECTKEYS = {"Heal", "Stun", "Silence", "Basic"};

public Skill(int[] array, HashMap<String, Boolean> h) {
this.array = array;
this.h = h;
}
public Skill() {
this.array = new int[3];

}

public boolean isHeal() {
return h.get("EFFECTKEYS[0]");
}
public boolean isStun() {
return h.get("EFFECTKEYS[1]");
}
public boolean isBasic() {
return h.get("EFFECTKEYS[3]");
}
public boolean isSilence() {
return h.get("EFFECTKEYS[2]");
}
public void setBasic(boolean ba) {
h.put("Basic", ba);
}

public void setStun(boolean st) {
h.put("Stun", st);
}
public void setSilence(boolean si) {
h.put("Silence", si);
}
public void setHeal(boolean he) {
h.put("Heal", he);
}
public int getManaCost() {
return array[1];
}
public int getHealthCost() {
return array[0];
}
public void setManaCost(int manaPrice) {
array[1] = manaPrice;
}
public void setHealthCost(int healthPrice) {
array[0] = healthPrice;
}
public int getPhysicalDamage() {
return array[2];
}
public int getMagicalDamage() {
return array[3];
}
public void setPhysicalDamage(int pD) {
array[2] = pD;
}
public void setMagicalDamage(int mD) {
array[3] = mD;
}
public String toString() {
return "Mana:- " + array[1] + "\n" + "Health:- " + array[0] + "\n"
+ "MagicalDamage:- " + array[3] + "\n" + "PhysicalDamage:- " + array[2];
}
}

waleed
03-07-2013, 08:35 PM
this is the test class


public class PublicChampionTests {
int maxHealth, maxMana;
String name;
Skill[]skills;
HashMap<String, Integer> attributes;
Champion instance;
@Before
public void setup()
{
maxHealth = 500;
maxMana = 360;
attributes = new HashMap<String, Integer>();
attributes.put("AttackPower", 62);
attributes.put("AbilityPower", 80);
attributes.put("MagicResist", 36);
skills = new Skill[2];
skills[0] = new Skill();
skills[0].setBasic(true);
skills[0].setPhysicalDamage(20);
skills[0].setMagicalDamage(50);
skills[1] = new Skill();
skills[1].setStun(true);
skills[1].setPhysicalDamage(30);
skills[1].setMagicalDamage(60);
skills[1].setManaCost(50);
try {
instance = new Champion("Fizz", attributes, maxHealth, maxMana);
}
catch (Exception e) {
System.out.println("Mistake");
}
}

@Test(timeout = 1000)
public void testGetName()
{
assertEquals("Name should be fizz as expected from construction",
"Fizz", instance.getName());
}

@Test(timeout = 1000)
public void testGetMaxHealth() {
assertEquals("MaxHealth ShouldBe As Set In Constuctor", 500, instance.getMaxHealth());
}

@Test(timeout = 1000)
public void testGetMaxMana() {
assertEquals("MaxManaShouldBeAsSetInConstructor", 360, instance.getMaxMana());
}

@Test(timeout = 1000)
public void testGetCurrentHealth() {
assertEquals("CurrentHealth should equal max health", 500, instance.getCurrentHealth());
}

@Test(timeout = 1000)
public void testGetCurrentMana() {
assertEquals("CurrentHealth should equal max health", 360, instance.getCurrentMana());
}

@Test(timeout = 1000)
public void testGetMagicResist() {
assertEquals("Current Mana should equal max mana", 36, instance.getMagicResist());
}

@Test(timeout = 1000)
public void testGetAbilityPower() {
assertEquals("CurrentHealth should equal max health", 80, instance.getAbilityPower());
}

@Test(timeout = 1000)
public void testGetAttackPower() {
assertEquals("CurrentHealth should equal max health", 62, instance.getAttackPower());
}



@Test(timeout = 1000)
public void testRevive() {
instance.setCurrentHealth(400);
instance.setCurrentMana(200);
instance.setStunned(true);
instance.revive();
assertTrue(!instance.isSilenced() & !instance.isStunned()
& instance.getMaxHealth() == instance.getCurrentHealth()
& instance.getMaxMana() == instance.getCurrentMana());
}

@Test(timeout = 1000)
public void testGetBasicSkill() {
instance.setSkills(skills);
Skill basic = instance.getBasicSkill();
assertTrue(basic.isBasic());
}

@Test(timeout = 1000)
public void testSetAttackPower() {
instance.setAttackPower(50);
assertEquals("Attack power should change to 50", instance.getAttackPower(), 50);
}

@Test(timeout = 1000)
public void testIsDead() {
instance.setCurrentHealth(0);
assertTrue("Champion should be dead", instance.isDead());
instance.setCurrentHealth(100);
assertFalse("Champion should be alive", instance.isDead());
}

@Test(timeout = 1000)
public void testIsStunned() {
assertFalse("In the beginning champions should not be stunned", instance.isStunned());
}

@Test(timeout = 1000)
public void testIsSilenced() {
assertFalse("In the beginning champions should not be silenced", instance.isSilenced());
}

@Test(timeout = 1000)
public void testSetStunned() {
instance.setStunned(true);
assertTrue("Now the champion should be Stunned", instance.isStunned());
instance.setStunned(false);
assertFalse("Now the champion should not be Stunned", instance.isStunned());
}

@Test(timeout = 1000)
public void testSetSilenced() {
instance.setSilenced(true);
assertTrue("Now the champion should be silenced", instance.isSilenced());
instance.setSilenced(false);
assertFalse("Now the champion should not be silenced", instance.isSilenced());
}

@Test(timeout = 1000)
public void testSetSkills() {
assertNull("As no skills were set, the getSkills Should be null", instance.getSkills());
}

@Test(timeout = 1000)
public void testGetSkills() {
instance.setSkills(skills);
assertSame("The returned skill array should be the same", instance.getSkills(), skills);
}

@Test(timeout = 1000)
public void testUseSkill() {
instance.setSkills(skills);
Champion target = new Champion("Annie", attributes, 500, 400);
instance.useSkill(target, 0, true);
assertEquals("Target should lose health as expected", 383, target.getCurrentHealth());
}
}

waleed
03-07-2013, 08:39 PM
any one help me plz

traq
03-08-2013, 12:36 AM
If you have a question, you need to ask it.

Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?

In addition, this is java, not javascript. I'm moving your thread to the appropriate forum. I don't use java, and I'm not sure many other members here do either, but someone may be able to help.

FrickenTrevor
04-08-2013, 06:33 AM
Agreeing with traq, if you want more people to help with your post please have a question instead of "help me with my code plz".
Try asking a question, for instance "How do I write an array?"

Aside from that, if you explain yourself more I will be willing to help. But until I can understand your question I cannot help.

The more you help us, the more we can help you

traq
09-18-2013, 01:53 AM
@waleed, if you have any other questions, please feel free to open a new thread and ask them. I am closing this thread now though because it continually attracts spam posts.