dimanche 1 novembre 2015

Exposure classes

Soo, I tried to write the code when one class acts with each other class. Here are class warior with "Tim" and class witcher with "Max". The console should speak "Now Max hp.. 50" or "Now Tim's hp.. 50 hp", but console sayed "Now Max hp.. 25" or "Now Tim's hp.. 25 hp".. 75 - 25 = 50; 100-50=50; but sayed 75 - 25 = 25; 100-50=25; Help please :c

import java.util.Random;

public class MAXvsTIMvoidVersion {

public static void main(String[] args) {

    warior Tim = new warior();
    Tim.agility = 100;
    Tim.attack = 25;
    Tim.hp = 100;
    Tim.Wariorlvl2 = true;

    witcher Max = new witcher();
    Max.mana = 150;
    Max.attack = 50;
    Max.hp = 75;
    Max.Witcherlvl1 = true;

    Random a = new Random();
    int b = a.nextInt(2);

            if (b == 0)
            {
                Tim.meleeAttack();
                System.out.print("Now Max's hp.." + Max.hp);
            }

            else if (b == 1)
            {
                Max.magicAttack();
                System.out.print("Now Tim's hp.." + Tim.hp);
            }
    }

}


class people
{
    static int hp;
    static int attack;
}

class witcher extends people
{
    int mana;
    boolean Witcherlvl1;
    boolean Witcherlvl2;
    void magicAttack()
    {
        warior.hp = warior.hp - witcher.attack;
        mana = mana - 20;
    }
}

class warior extends people
{
    int agility;
    boolean Wariorlvl1;
    boolean Wariorlvl2;
    void meleeAttack()
    {
        witcher.hp = witcher.hp - warior.attack;
        agility = agility - 20;
    }
}

Aucun commentaire:

Enregistrer un commentaire