This site requires JavaScript, please enable it in your browser!
Greenfoot back
mariq_rasyid29
mariq_rasyid29 wrote ...

2021/2/28

how making the player level up ?

mariq_rasyid29 mariq_rasyid29

2021/2/28

#
here the variable form lv 1
     private int level=1;
     private int mana=80;
     private int Health=100;
     private double defense=0.5;
     private int attack=10;
     private int exp=0
if exp get 100 then will be lv up to lv 2 the player will be get increased health+15. mana +5, defense+0.1, attack+2 also for the next lv up
danpost danpost

2021/2/28

#
Add parameter for level to Player constructor:
public Player(int level)
{
    this.level = level;
    mana = 80+5*(level-1);
    health = 100+15*(level-1);
    defense = 0.5+0.1*(level-1);
    attack = 10+2*(level-1);
    ...
}
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
mmm, sir what this is "..." mean?
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
also sir after im adding that code to my player class now i can't to add the player to the world it said "Constructor Player in class Player cannot be applied to given types; required : int found : no arguments reason : actual and formal argument list differ in length"
danpost danpost

2021/3/1

#
mariq_rasyid29 wrote...
mmm, sir what this is "..." mean?
It means anything else you might want to do when you create a player.
mariq_rasyid29 wrote...
also sir after im adding that code to my player class now i can't to add the player to the world it said "Constructor Player in class Player cannot be applied to given types; required : int found : no arguments reason : actual and formal argument list differ in length"
In world, use: new Player(level)
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
mmm if want check player lv/ lv up what is the code? like this code?
public void level()
{if(exp==100)
{
  }
}
or others?
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
if type in world
addObject (new Player(level), x,y);
get error cant find symbol - variable level
danpost danpost

2021/3/1

#
mariq_rasyid29 wrote...
if type in world
addObject (new Player(level), x,y);
get error cant find symbol - variable level
Maybe it is "lv", not "level" (in your world class)?
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
in world class is nothing like int level or i must input public int level=1 in Player.class?
danpost danpost

2021/3/1

#
mariq_rasyid29 wrote...
in world class is nothing like int level or i must input public int level=1 in Player.class?
Then just use: new Player(1)
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
if the player was lv up sir ? the player will be downgrade?
danpost danpost

2021/3/1

#
Maybe I was confused here. Go back to simple "new Player()" with "public Player()". That is, scratch everything above. Try:
if (exp >= 100 && level == 1) level = 2;
and use similar formulas as in my first code post (lines 3 thru 7) to work values.
danpost danpost

2021/3/1

#
If level is to increase at a constant rate (increasing for every 100 exp points), then you can simply do this:
if (exp/100 == level)
{
    ++level;
    mana += 5;
    health += 15;
    defense += 0.1;
    attack += 2;
}
You need to login to post a reply.