title: How do I set up a targetting system in Java?
body: <p>I am making a command-line game in Java to help learn better about GUI and such and I ran into a problem. In the game I want to be able to target another player. I am making a method called attack(). How would I go about, if I wanted to attack a player, bar, making it so that I could use attack(bar) as a function. I don't know how to reference an object in a parameter or an object created in a different class. What I need to my code to do is basically this: Assume my name is Player foo and I am attacking Player bar. Each player has 2 instance variables, <code>Player.playerHealth</code> and <code>Player.playerDamage</code> (the damage that they do). I need it to do:</p>
  
  <pre><code>attack(playerTarget) {
      target = playerTarget
      target.playerHealth = target.playerHealth - foo.playerDamage;  
  }
  </code></pre>
  
  <p>So basically I need it to set the player losing health equal to the name in the parameters. How might I achieve this?</p>