4 Replies - 1468 Views - Last Post: 21 November 2011 - 07:11 PM Rate Topic: -----

#1 jhonof   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-November 11

problem with game in java

Posted 21 November 2011 - 05:18 PM

hello I am new to the forum and am currently trying to write a simple pokemon style game in java. I am having trouble in the battle sequence using my algorithm to make the health go lower. heres the code
 int attackers = (((2*treequil.getlevel()/5+2)*treequil.getAttack()*attacking/bulbeye.getdefense())/50+2);


treequil is a a guy1 class which is currently just the stats that he has (ie. attack = 20 etc.) and bulbee is a guy2 class currently. the problem may be that I am stating his health in a different class.

I am doing this for a friend and would really like some help.

This post has been edited by Atli: 21 November 2011 - 05:22 PM
Reason for edit:: Fixed the [code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: problem with game in java

#2 fromTheSprawl   User is offline

  • Bloodborne
  • member icon

Reputation: 522
  • View blog
  • Posts: 2,102
  • Joined: 28-December 10

Re: problem with game in java

Posted 21 November 2011 - 05:52 PM

Ah, an RPG battle engine. Well, here's how I would do it:

Player class:
- getAtk()
- getDef()
- setAtk()
- setDef()
- setHP()
- getHP()
- atk()
- def()

Now create all derivations of players from that base class. To instanciate a new class, just make a constructor with default values for atk, hp and def. Now that it's done, here's how I would do your question:

public int atk(int hp){
hp = this.atk - hp;
return hp;
}



Then in your battle method you could just do this when someone attacks:
Enemy.setHP(Player.atk(Enemy.getHP());

Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: problem with game in java

Posted 21 November 2011 - 05:56 PM

We are the blinds leading the blind. What datatype are:
- treequil.getLevel()
- treequil.getAttack()
- attacking
- bulbeye.getDefense()

You should seriously think of adding a println() statement to print all those values
Was This Post Helpful? 1
  • +
  • -

#4 fromTheSprawl   User is offline

  • Bloodborne
  • member icon

Reputation: 522
  • View blog
  • Posts: 2,102
  • Joined: 28-December 10

Re: problem with game in java

Posted 21 November 2011 - 05:57 PM

Whoops, I forgot to factor in defense. Which would mean, just pass the whole Enemy class to the atk method. So:
public doBattle(){
Player enemy = new Player();
enemy = Player.atk(enemy);
}
//Then on atk on the Player class

public Player atk(Player enemy){
enemy.setHP(this.getAtk() - (enemy.getHP() + enemy.getDefense()) x .1; //It's up to you how you'll use defense.
return enemy;
}


This post has been edited by fromTheSprawl: 21 November 2011 - 05:57 PM

Was This Post Helpful? 1
  • +
  • -

#5 jhonof   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-November 11

Re: problem with game in java

Posted 21 November 2011 - 07:11 PM

thanks guys soo much. I really appreciate it!

ohh and pbl they are all integer values
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1