Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method problem

 
Harold Pint
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm new to Java, learning it for my Computing course at university.

For a project over Easter I must make a simple game on the concept of rock, paper, scissors.
Note the game is nothing graphical yet, just command line stuff.

The first activity is to create a class to make the base units. (This game is using land, sea and air instead of rock, paper and scissors.)
I have done this, however I need methods to make the units attack each other.

I need two methods, one to attack, and another to calculate the damage. The attack method is called and uses the damage method to deal damage to the other unit.

How can I instruct the attack method to use the damage method?


Here is my code:



and the main method to test this:



The attack and damage methods are currently incomplete. If I comment them out and run the program, it returns this result:
Base Unit (100/100)
Gary (75/100) false



So how can I code this problem? I remember one of my classmates working on it, and having something like


Is this on the right lines?

I hope you can help me.

Thanks in advance.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, I don't think you will find anyone to do your homework for you on this or any other site.

With that in mind, all you have done, providing that everything compiles okay, is to output the data
represented by your first reference to the Unit object, and the second reference. Also, our not passing anything into the dead
method so it is really not doing anything useful.

status should be a class member like boolean STATUS.

What you might think about doing is to give paper, rock, and scissors a value to compare against one another.
Then you would have something to compare against.


 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

What is the d parameter in the damage() method? You appear not to be using it; why not?

I think you need to get a pencil and paper and write down what each method is supposed to do, and how the class should be constituted. In the attack method, you need to invoke the damage method on your opponent's object reference.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic