• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

How do I create a battlecode from the code I already created?

 
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Honestly, I think it's unfair to give requirements like this to students who are just learning how to program and not let them use arrays or tell them about the standard Java library utilities that are at their disposal. It's like asking inexperienced mechanics to fix an engine with just a screwdriver and a hammer and not tell them or let them use wrenches, jacks, and other tools available in the shop.  Even experienced mechanics will find it challenging and ridiculous to not use the tools that will make the job easier and get it done faster and cleaner.

Since you say that you're not going to use arrays for this, I'll show you just how easy it is to do this with an array and the java.util.Arrays utility class:

The logic is basically this:

1. put Y rolls of the die into an array with Y elements
2. sort the array
3. return the last X elements of the array

That's it. No muss, no fuss. Bim, bam, boom, you're done. It doesn't even matter if there are any rolls that are equal; the sort guarantees you'll get the highest X rolls at the end of the array, no matter if the highest X rolls are the same or even if all Y rolls are the same.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:If you do the math and figure out all the permutations of 3 different rolls, you'd have 3! permutations or 3 × 2 × 1 = 6 permutations.

You could certainly brute force all 6 permutations with a series of if-else-if-else-if-... statements but you have to do it with the consistency you have in your first if-statement:

The problem with the way you coded it is that you were not consistent in your formulation of relational expressions. You switched things up and therefore your logic train jumped the tracks.

It pays to remember your high school algebra when it comes to these kind of problems.

Also, you don't account for two or more rolls being equal to each other.  But you can reason about that later, once you figure out how to formulate your relational logic properly.



 
Ranch Hand
Posts: 86
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I'm three pages behind here but...and please excuse me if these have already been pointed out, I only have a minute or two on here and found this post interesting.  I have some questions what is the intention of adding the Die object to the hero object?  If you're rolling the die in the main Java class then what is the need in the Hero class?  Next, if you need the die rolls for some methods in the Hero class they why not roll all the die first in the main class before constructing the new Hero then pass the results to the constructor?   As for protecting the random number so it is not a negative, is there not a way within your random number generator to ensure you only get a number between a min and max value.  I need to find the class now but I think the math class had a random number generator method that returned a value between 0 and 1 in decimal form then you could add to the return to make it an int.  I need to look it up.  My thinking is that you're removing unnecessary computations and comparisons to ensure you get a random number between x and y, when you could simply just enforce your random number never returns a negative number.  Just me two cents.  Also if this has already been brought up just tell me to shut up .  I promise to read this entire post after my shower.

 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're wondering about my strange naming of the parameters, it's because an IDE like IntelliJ IDEA will actually display the code with a hint as to what the parameters mean. So, with a judicious choice of names, it actually makes your code very readable in the IDE.

This is what I'd see in my IDEA editor for highRolls():

IntelliJ IDEA 16 wrote:
Die die = new Die( faces: 8);

int[] highTwo = die.highRolls( highest: 2, outOf: 4);


I really like this new feature in my IDE.
 
Mike Corona
Ranch Hand
Posts: 71
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Honestly, I think it's unfair to give requirements like this to students who are just learning how to program and not let them use arrays or tell them about the standard Java library utilities that are at their disposal. It's like asking inexperienced mechanics to fix an engine with just a screwdriver and a hammer and not tell them or let them use wrenches, jacks, and other tools available in the shop.  Even experienced mechanics will find it challenging and ridiculous to not use the tools that will make the job easier and get it done faster and cleaner.

Since you say that you're not going to use arrays for this, I'll show you just how easy it is to do this with an array and the java.util.Arrays utility class:

The logic is basically this:

1. put Y rolls of the die into an array with Y elements
2. sort the array
3. return the last X elements of the array

That's it. No muss, no fuss. Bim, bam, boom, you're done. It doesn't even matter if there are any rolls that are equal; the sort guarantees you'll get the highest X rolls at the end of the array, no matter if the highest X rolls are the same or even if all Y rolls are the same.



I am definitely curious about arrays. So, you are creating a new object as an int? Confused me a bit there. Also, you are setting roll[i] = roll(); which is a method and I have not seen this at all. Seems extremely different and a bit confusing lol
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:This is the reason I suggested that you put the logic for determining the high X rolls out of a total of Y rolls in the Die class. That way, you'd just have to reuse the method, highRolls(x, y) from wherever you needed to.  Otherwise, you're going to end up duplicating a lot of this "find the highest X of Y rolls" in all your methods that need to pick X out of Y rolls.


This is interesting and seems extremely useful also, but I will be using this die class for future projects and assignments so I did not know if it was alright to change the code in the die class. So all you're saying is I make a new method with void return type and give it two parameters for input?
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, a call to a method that returns a value is an expression whose value is what the method returned. (Edit: I'll try to find another way to phrase that so it doesn't sound as loopy).  It's the same as what you'd expect a method called add(int, int) to evaluate to and it's the same deal as with if (camelBak.isEmpty()) from before.

If you saw code like this:
what do you expect the value of the expression calculator.add(2, 5) would be?  Naturally, you'd expect it to be 7, right? So you'd expect the variable sum to be assigned the value of 7.

Same way as the expression roll[i] = roll(). On the left-hand side of the assignment, roll[i] refers to the i-th element of the array roll. An array is just a fixed-length container of things. In this case, roll is an int array, which means it can hold int values.

So, roll[i] gets assigned the value of the next roll() of the Die. If you look at the roll() method that I wrote, it returns an int value. It's a modification of your version of roll(). Your method is declared with a void return type. I think it makes more sense to make roll() return the value that was rolled. Then the getValue() method will just keep returning that same value until the next time roll() is called.  Makes sense, right? You roll the die, it shows a face. It will just keep showing that same face until you roll it again and then it will show another face.

Look through these search results for more about What are Java arrays
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't make any changes that you're not completely confident of making. For one, you might get questioned how you came up with these ideas. I'm just sharing these things with you to give you a glimpse at other possibilities for coding this program up. However, if you are expected or required to do it in a certain way, you should probably stick to those expectations/requirements.

I know it might just add to your confusion in all this stuff but I think it's better that you are aware of other alternatives. At least that way, you'll have ideas of how the code could be written differently and you can compare one approach to another. How are you going to know your favorite flavor is chocolate if all you've ever eaten is vanilla and strawberry?
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really should consider what these two parts of your requirements imply:

addHealth - add an int value to health, the value added cannot be negative
...
addStamina -  add an int value to stamina, the value added cannot be negative

Consider also that your requirements tell you to use the results of rolling the dice to determine how much health and stamina to add.

Remember the Recruit from before? You can tell the jarhead to jump() and all it needs to know is how high?  Well, these requirements say that a hero can addHealth() and addStamina() but you have to tell each of those methods how much.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:You really should consider what these two parts of your requirements imply:

addHealth - add an int value to health, the value added cannot be negative
...
addStamina -  add an int value to stamina, the value added cannot be negative

Consider also that your requirements tell you to use the results of rolling the dice to determine how much health and stamina to add.

Remember the Recruit from before? You can tell the jarhead to jump() and all it needs to know is how high?  Well, these requirements say that a hero can addHealth() and addStamina() but you have to tell each of those methods how much.


Yeah, which the only thing I can think of is doing something like "addHealth(die3.getValue());" which does not work. Gives me an error.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried something else, let me know what you think. Btw I added a parameter to addHealth() to begin with and then made this change.

 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what you had in the first listing you posted

The method's signature was correct, it should accept a number to signify the amount of stamina to lose. The problem is with the implementation, which totally ignores the value passed in and just reduces by 10. Why would you do that?  If someone asked you to add 3 and you add 10, doesn't that seem like the wrong thing to do? If your boss paid you $100.00 and the bank only put $15 into your account, wouldn't you be outraged? Edit: I guess a better analogy would be if you went to the ATM and withdrew $20 but the bank decides to dock your account $200 instead.  You'd certainly be outraged by that, right.  Similarly, if the hero was only supposed to lose 3 points worth of stamina but you went ahead and took away 10 points, doesn't that seem a bit unfair to your hero?

The signature you have here should be what your addStamina, addHealth, removeHealth methods should follow, and all of the implementations should use the value passed in to make adjustments to their respective hero attributes.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I am feeling pretty confident about this now. Check this out and tell me if I finally got my second wind lol

Composing the addHealth()/removeHealth() methods differently.



Composing the addStamina()/removeStamina() methods differently.


Changed rest() method to understand sub methods and use them correctly.
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The addXXX and removeXXX are getting there. Good job on figuring out what to do with the parameter value that was passed in.

The conditions you're checking still are not quite right though.  It's possible for these methods to push their associated attributes outside of their valid ranges.  For example, if you have a health level of 98 and you add health of 4, then you'll end up with a health level of 102, which is invalid. On the end, if you have a stamina of 3 and removed 5 points of stamina, your code would still allow it and leave your hero with a negative stamina.

The rest() method looks a lot better and I think it's even correct if we ignore the issues with the addHealth() and addStamina() methods that I just pointed out.

You should feel good about your progress. It may feel a little slow but slow and sure progress forward is never a bad thing.

Don't forget to take breaks away from your code. Sometimes it helps to do other things totally unrelated to this work. Let your subconscious brain take over. I often have great flashes of insight after taking a break to wash dishes or clean up around the house or garden. I have one buddy who literally jumped out of bed naked and started banging frantically away at his keyboard because he didn't want to lose the idea that had just popped into his head. The funny thing about it was, well, let's just say that there was somebody who was a little mad about not getting the kind of attention the keyboard was getting...
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hahaha yeah I understand what you mean. I have so much work to do and I am not the type of person to easily let something go if I haven't finished it or don't understand it properly. Also, this is a project for my computer science class and it was due tonight but I asked for more time. My teacher had no problem with giving me a few more days because I am always turning everything in on time and correct. I also do not want to rush it because I actually want to understand the concepts behind everything I am doing so I become great at programming. Honestly, I was thinking about how those methods could still break the set limits while I was going through them again. I became distracted with figuring out the permutations for the 2 out of 4 rolls to determine strength and agility. Technically, I should be focusing on the issues in the addXXX and removeXXX methods first. Is the issue as simple as using && instead of ||? I kept thinking about that earlier but I can feel my brain melting again lol
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Corona wrote:Technically, I should be focusing on the issues in the addXXX and removeXXX methods first. Is the issue as simple as using && instead of ||? I kept thinking about that earlier but I can feel my brain melting again lol


No, it's an issue of making the proper checks and only removing or adding as much as you can/should.  Go back over my camelBak example.  The pourOut() method ensures that if I only have 4 ounces of water left in the camelBak, then I can't just magically pour out 10 ounces, no matter how loud the drill sergeant yells for me to pour out 10 more ounces.  Likewise, no matter what kind of inspirational/motivational talk a recruit is given, they can't literally give 110% of effort to getting something done. Figuratively, yes, you can give 110%, but nobody can literally give more than 100% effort.

So, if you had a hero whose health was at 96%, how much can you really add if you were asked to give the hero another 7% of health?  The math is not that hard to figure out.  Don't forget about the normal case though, where adding as much strength as was passed in is possible because the resulting total health will still be less than or equal to 100%.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this?

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tested that and it did not work. Still skips over the body of the if statement so I am lost again. :/
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I debugged and this seemed to work. Not sure to what extent it will work.

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Corona wrote:I debugged and this seemed to work. Not sure to what extent it will work.


This also seemed to work.

 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just talk through a few sample scenarios, you'd see how to properly do it.

"If I have 90 points of health, and you tried to give me 8 points of health, then I'd end up with 98 points of health"
"If I have 92 points of health, and you tried to give me 8 points of health, then I'd end up with 100 points of health"
"If I have 96 points of health, and you tried to give me 8 points of health, then I'd end up with 100 points of health"
"If I have 96 points of health, and you tried to give me 80 points of health, then I'd end up with 100 points of health"

Therefore, I can only accept as much health as it will take to get me to 100 points max.  

If you want to cut to the chase, you can just imagine measuring a level cup of flour. If you just happen to pour too much flour, then you just take a spatula and run the edge across the rim of the cup, right? So, you're basically throwing away the excess.

See if you can program that logic. Don't get caught up in the language. THINK LOGIC.

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:If you just talk through a few sample scenarios, you'd see how to properly do it.

"If I have 90 points of health, and you tried to give me 8 points of health, then I'd end up with 98 points of health"
"If I have 92 points of health, and you tried to give me 8 points of health, then I'd end up with 100 points of health"
"If I have 96 points of health, and you tried to give me 8 points of health, then I'd end up with 100 points of health"
"If I have 96 points of health, and you tried to give me 80 points of health, then I'd end up with 100 points of health"

Therefore, I can only accept as much health as it will take to get me to 100 points max.  

If you want to cut to the chase, you can just imagine measuring a level cup of flour. If you just happen to pour too much flour, then you just take a spatula and run the edge across the rim of the cup, right? So, you're basically throwing away the excess.

See if you can program that logic. Don't get caught up in the language. THINK LOGIC.


I've been trying to use that logic all day and the best i've come up with is that last piece of code. The only other thing I can think of is making health a final value of 100, but I feel like I am not understanding a simple concept of the coding portion. I know no matter what, health has to end up at 100. Creating the code to do that is where I am stuck.
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try to translate this statement to simple Java code?  "If I put more than 1 cup of flour, then I'll only use exactly 1 cup of flour. Otherwise, I'll use however much I have in the cup now."
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Literally, 3 lines of code is all you need.  Pour flour into cup that may or may not already have flour in it.  If I have more than 1 cup, then I use only exactly 1 cup.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this is closer to what you are saying because I know exactly what you mean, translating to code is much more difficult than the thought.

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Corona wrote:I hope this is closer to what you are saying because I know exactly what you mean, translating to code is much more difficult than the thought.



Well, maybe this is a bit better considering health could be any value at any point in a battle.



Not 3 lines of code though. :/
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No wait! This.

 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good job. Now the challenge for bonus points: Do it in one line of code using Math.min()
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Corona wrote:No wait! This.


Do only what you need to do. Here, you unnecessarily assign 100 to health even if it's already 100.

This:

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Good job. Now the challenge for bonus points: Do it in one line of code using Math.min()



I'm up for it. I didn't even know I could make it that simple and small lol I was really overthinking those methods.
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Corona wrote:

Junilu Lacar wrote:Good job. Now the challenge for bonus points: Do it in one line of code using Math.min()


I'm up for it. I didn't even know I could make it that simple and small lol I was really overthinking those methods.


Focusing too much on the language syntax can do that. Always go back to your intent. That's how you keep it simple. If you state your intent in simple terms, then your code tends to follow suit.

Here, the one line intent is: make health the smaller of one or the other.  Now all you have to do is figure out what "one" is and what "the other" is.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tonight is my last night. lol the only thing I can't seem to understand now is the attack() and block() methods.



Am I overthinking these also?
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirements certainly don't help you figure out that stuff very much. From what I understand, both block() and attack() have to be executed in response to another player's attack move.  It's like this:  Your hero gets attacked by a certain amount. Given whatever intensity of attack your hero is subjected, you can respond by blocking it, or counterattacking it.  A block will give you a chance to avoid damage entirely since the move is purely defensive.  A counterattack provides you no protection and you can incur damage as you are trying to inflict it to the enemy who is attacking you.

Because of this, your block() and attack() methods needs to know how much of an attack from an enemy your hero is responding to.  Right now, your methods don't have that. That's the "subtle" hint.

The not so subtle hint, in case you didn't catch the subtle one, is this:  addStamina(), removeStamina() all take a parameter that tells the methods by how much they should change stamina.  Well, block() and attack() also need to be told "how much" except in their case, they need to be told how much of an attack they are responding to.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:The requirements certainly don't help you figure out that stuff very much. From what I understand, both block() and attack() have to be executed in response to another player's attack move.  It's like this:  Your hero gets attacked by a certain amount. Given whatever intensity of attack your hero is subjected, you can respond by blocking it, or counterattacking it.  A block will give you a chance to avoid damage entirely since the move is purely defensive.  A counterattack provides you no protection and you can incur damage as you are trying to inflict it to the enemy who is attacking you.

Because of this, your block() and attack() methods needs to know how much of an attack from an enemy your hero is responding to.  Right now, your methods don't have that. That's the "subtle" hint.

The not so subtle hint, in case you didn't catch the subtle one, is this:  addStamina(), removeStamina() all take a parameter that tells the methods by how much they should change stamina.  Well, block() and attack() also need to be told "how much" except in their case, they need to be told how much of an attack they are responding to.


That's a bit trickier. In order to do this wouldn't I need another method for that case?....or i'd only be able to include this is one of the two methods.
 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added a few things here. I don't think I have them in the right places though. I figured I could declare the variable actualHit as a hit value from the attack() method minus the dodge value. In the attack() method, I made a villain as a parameter and set it to block the damage calculated.

 
Mike Corona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But then I get confused as to why these methods are required to return anything. Shouldn't they return void?
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you've thought through the attack() method clearly.

Think of it like this:  Your hero's attack() method will be called as a result of you choosing the "Attack" action to respond to an enemy's attack move. That means that attack() will be called with the value returned by your enemy's attack() method, i.e., the intensity of your enemy's attack.  So if I were playing your enemy and I attack your Hero with an intensity of 10, then your Hero's attack() method would get called with a value of 10, that is, yourHero.attack(enemyAttackIntensity) where enemyAttackIntensity is 10 because that's what I said just now (that the enemy will attack you with an intensity of 10).

Clear as mud yet?  Bottom line, I don't think your interpretation of attack(Hero villain) is correct.  For one, the names make no sense semantically. How can a Hero be a villain? It doesn't sound like your game is "Suicide Squad" or "Guardians of the Galaxy".
 
Junilu Lacar
Sheriff
Posts: 15988
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of "villain", a better word to use might be "opponent". At least that's a little more neutral term. Refer to your requirements again. It says you are going to play rounds where both players select a move, one from user input, the other from a random choice. That fits what I was saying earlier about what the block and attack methods would take as a parameter, it's whatever level of attack the opponent chose to launch against your Hero object.
 
permaculture is giving a gift to your future self. After reading this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic