Advanced Search

Results 1 to 6 of 6

Thread: help me with my code plz

  1. #1
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help me with my code plz

    this is the class skill
    Code:
    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];
    	}
    }
    Last edited by traq; 03-07-2013 at 11:32 PM. Reason: please use [code] tags

  2. #2
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    this is the test class
    Code:
    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());
    	}
    }
    Last edited by traq; 03-07-2013 at 11:31 PM. Reason: please use [code] tags

  3. #3
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    any one help me plz

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  5. #5
    Join Date
    Aug 2009
    Location
    @charset "UTF-8"
    Posts
    122
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default

    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

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    @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.
    Last edited by jscheuer1; 09-18-2013 at 03:24 AM. Reason: clarity
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

Similar Threads

  1. Replies: 3
    Last Post: 05-12-2011, 03:43 AM
  2. Secret code / hidden message / obfuscated code - ???
    By newbie01.others in forum JavaScript
    Replies: 2
    Last Post: 01-14-2011, 10:29 AM
  3. Replies: 15
    Last Post: 06-11-2009, 12:27 PM
  4. Replies: 2
    Last Post: 10-27-2008, 05:16 AM
  5. Help - Code discrepency - Full Screen code
    By kurson in forum JavaScript
    Replies: 6
    Last Post: 05-10-2006, 06:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •