Loading files

Per the instructions
"You will need to check whether the first field is Troll, Jinn, Wall, etc. to determine the type of opponent to create. Once the opponent is created, add it to the opponents array list."

It looks good so far as I can tell, you haven't stated what the requirements are for the opposition (maybe that's unimportant for now). You are creating an Obstruction but you aren't doing anything with the 'o' variable. Can you describe what you're stuck on?

Well, honeslty I just wanted to see if that was the correct way to do it. I only had little pieces to go off of, but I do get a arrayindexoutofbounds:1 exception.
Id have more to add on like reporting line number errors, but I want to get this working first

If a line starts with "Troll", first you create an Obstacle("Troll"), Next you create 4 Trolls that get added to the opponents list. So with four lines in the file starting with "Troll" you add 16 Trolls in total. Is this really according to the assignment?

Cody Biggs

Ranch Hand

Posts: 335

3

posted 1 year ago

Well, I showed the instructor and he didn’t say anything about it being wrong. The only hints he gave me were

“You might want to check the length of the array or do something different when it comes to a wall”

Also in your initial code you have have hardcoded values which you passing to Troll constructor, these as I see reassemble the values (numeric) which appear next to each Troll in a file, that is why you have them 4 created, again, in hardcoded way. That is of course not correct too. This is what Piet hinted to you why you creating 16 of them (Trolls) in total.

1. What you most likely need to do is, to have an interface or abstract class Obstacle, where each concrete obstacles either extend or implement (based on either it is abstract class or interface you choose to go with).

2.Then based on the obstacle you find out during the file read you create concrete object and add to Obstacles array or list or other data structure you need to. Factory method might would be helpful to have so you wouldn't pollute class where main logic is laid down with lots of if's/else's.

3. During the creation of concrete obstacle you need to take into account, that some (actually just one at this moment of requirements) obstacles have just a name of them (i.e. Wall), meaning have no numeric value after the comma, which you didn't tell us yet what it means.

3.1 So, when you create concrete obstacle, you need to either know beforehand that there is no second parameter (numerical) or let constructor figure out that there is no such numeric value - Piet hinted about that too.

Things go in some chaotic way as I see (I've done that many times too). So what I usually do when that happens - I delete code and start over. Would suggest that to you too, just this time take smaller steps.

You could. I’ve changed up a few methods of the player and enemy class from not paying attention

Piet Souris

Master Rancher

Posts: 3080

108

posted 1 year ago

Liutauras Vilda wrote:By the way, Obstacles sounds like a Dutch word, but it is English, I thought where I heard this word...

The Dutch word is 'obstakel' (single, plural 'obstakels'), with the emphasize on 'sta'.

Piet Souris

Master Rancher

Posts: 3080

108

posted 1 year ago

Still left with the problem that Obstacle has no one-argument constructor...

Cody Biggs

Ranch Hand

Posts: 335

3

posted 1 year ago

True. At this point im so confused

Ruben Demuynck

Greenhorn

Posts: 8

1

posted 1 year ago

1

I.s.o. looking for obstacle with single argument constructor, you should use the Wall object.
Use new Wall() for creating a wall, it will create an obstacle with strength 10:

As per your info:

Piet Souris

Master Rancher

Posts: 3080

108

posted 1 year ago

Very true.

However, the discussion started with the misery of creating an Obstacle in case of a wall. Two questions arise:

1) must OP really create an Obstacle? Why? The opponents are created anyway.
2) Or, if it really is necessary, might the omission of that constructor be one of those details that must be fixed?

I bet the first option!

Ruben Demuynck

Greenhorn

Posts: 8

1

posted 1 year ago

I agree with number 1:

When creating a Wall you are allready creating the obstacle (or opponent). It makes no sense to create another obstacle for that same wall...

In general it makes sense to:
* For Producing/Construction classes: Specific classes are used (Troll, Wall, ...)
* In the parts of the code that Consume/use classes, use Generic Interfaces or - in this case - parent classes (Obstacle)

As a tip it can be considered "cleaner" if you seperate the creation of your functional objects(logical/functional part) from the reading/parsing of the file (technical part).
To make this more clear an example which is pretty similar:

Here you see : first read the file, then create the objects, also the object creation is encapsulated in a factory which returns objects for consumers, but creates/produces specific objects

1. Your methods isAlive() in all classes are incorrect at the moment.
2. Method drink() in Player class is also incorrectly implemented. There is a warning even issued by the instructor. I see you tried something, but unfortunately it isn't correct - re-read and give a try again.
3. Method relinquishVials() also incorrectly implemented. Read once again what is required to return.

Instructions place X wrote:Game
This class controls the game itself. Most of it has been implemented for you. This is all you need to do to this class for a grade of ‘C’.

Instructions place Y wrote:For a grade of C:
Just implement the above classes and interfaces and load the opponents from a file.

Grading system kind of contradicting a bit. Not really clear what you need to do for Grade "C". Of course you supposed to be interested only in the description of grade "A".

Minor comment: In class Game you have...
Instead, try...
That way if you want to change the implementation of the List<>, you can.

All things are lawful, but not all things are profitable.

Cody Biggs

Ranch Hand

Posts: 335

3

posted 1 year ago

Y'all I have to apologize.... me and not paying attention made this way harder on y'all. I was an idiot, and was not paying attention to my line which was creating a obstacle, even though it was pointed out probably 5 times. I misunderstood what the instructor was telling me, and made everything a mess that should have been avoided.......again im sorry to everyone

this is what I have to make it work. Which is as straight forward as it should have been if I wasnt an idiot............

All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad: