• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Question about classes / objects regarding my university project  RSS feed

 
Szabolcs Maár
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone!

I have to create a small game in Java as my university project and I'm kind of lost about how it would be optimal to create my classes / subclasses / objects. Problem is, most of the score I can get for it depends on how well I handled object orientation.
The game needs to have:
- Randomized character generation. Every character needs to have 10 skills. All of the skills are random between 1 and 100. They also receive a % cut from the mission rewards based on their highest skill.
- Every skill has a related challenge, meaning there are 10 different types of challenges. A challenge has a random difficulty between 25 and 125. In order to beat the challenge the character(s) taking it on need to have a higher related skill, than the challenge's difficulty.
- The characters you select need to take on missions, which have anywhere between 4 - 9 challenges.
- The characters can have either 1 or 2 out of 9 possible tasks assigned to them. Assigned tasks can effect their skills, or add the character a special ability. Tasks also increase the cut a character receives from the mission reward.
- Every Task has 1, 2, or 3 related challenges. Every character can only take on challenges, that their assigned task / tasks are related to.

How would you go about creating the classes for this game?

Thank you for any help you can provide!
 
 
Campbell Ritchie
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Szabolcs Maár wrote:Hello Everyone!

Welcome to the Ranch and hello.

. . . Problem is, most of the score I can get for it depends on how well I handled object orientation.

That isn't a problem, I don't think; it suggests to me that you are being taught well

. . .
- Randomized character generation. . . .

Divide and rule. Do the whole thing in small parts and get each part working before you move onto the next part.
I suggest you go through the specification and create classes for all your kinds of characters but don't create a class called Character. Similarly for your tasks/challenges. What does it mean that characters have a repertoire of tasks? Does every instance of class X have the same repertoire? If not, what do you know about resources in the Collections Framework or elsewhere to link characters to skills, etc?
The bits about getting skills and points suggests there might be a Skill class with subclasses, but I am not 100% certain. But it doesn't suggest there should necessarily be classes to calculate points and shares of the reward. That sort of thing sounds more like what you want a method for. Write down a formula for random generation without using any computing words, and then work out how you can change that to a method.
 
Szabolcs Maár
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, thank you for the reply!

Originally characters only have their 10 types of Skills (Driving, Accuracy, Computers and such). The 9 types of Tasks (Driver, Gunman, Hacker ect…) can be assigned to them later. These Tasks all have a few (1-3) related Challenges that they can take on. In order to pass a Challenge, the Character or Characters, who has/have the Task related to the Challenge need to have a higher Skill level, then the difficulty of the Challenge.

I think I have the random number generation part figured out. Will see how it goes if build the separate parts. You would not suggest building a Characters class?

We only touched Collections briefly during the course. Should I use them here for something?
 
Junilu Lacar
Marshal
Posts: 13447
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:it suggests to me that you are being taught well


Color me cynical but I will reserve judgement until I've seen code and get a better feel for what exactly is coming from the instructor and what is on the student.  

Szabolcs Maár wrote:You would not suggest building a Characters class?

We only touched Collections briefly during the course. Should I use them here for something?


Some cracks are starting to show with this.
 
Junilu Lacar
Marshal
Posts: 13447
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not having code to base discussion on leads to speculation and assumption of what you're doing. These may or may not be correct so it's best you show us some code so we know exactly what we're talking about.
 
Szabolcs Maár
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it's a correspondence course, meaning they have pretty much 0 time to teach us well. So, while I'm not sure about being taught well, if object orientation being valued highly is good, that'd mean the requirements of the course are set up well at least.

I realize now, that the task is way too complex to ask generalized questions like I did. I'll just go with partial problems if something comes up.

This is my character creator. It puts my characters in the Characters ArrayList. Every character must have a unique name. Because of this I have created another for cycle within the creator, to check if the currently created character matches any of the ones stored.
Staff note (Junilu Lacar):

When posting code, please use code tags. See this page: https://coderanch.com/wiki/659781/Code-Tags to learn how.

 
Jim Venolia
Ranch Hand
Posts: 523
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)  Pull your maximum declarations out of the loop.
2)  Make the things that don't change static
3)  Capitalize your constants
4)  Indent your code correctly
5)  Try to keep lines < 80 characters



As for your question, I'd say it's wrong to have to characters with the same name.
 
Jim Venolia
Ranch Hand
Posts: 523
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh, I wish I could edit my replies.

If it was me, when I got a character name I'd remove it from the list of possible names.  Say your possible names are "a", "b", "c", "d".  You get a "b".  Modify the list so it's now "a", "c", "d".
 
Szabolcs Maár
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your insight. I'll be sure to work on the appearance of my code in the future, but right now that is a low priority issue for me.

Yes, that would be the easiest solution. Unfortunately the program needs to be able to shuffle the character pool later on. And if that happens a lot, charname{} would run out of potential names very soon. This means that if a character died, or is sent away their name would need to be put back into the charname{}. Would you still chose this option?
 
Jim Venolia
Ranch Hand
Posts: 523
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing clean code helps you to spot bugs.

When a character dies why not stick his name back into the available name pool?
 
Szabolcs Maár
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would certainly be the more efficient program, as mine may run a lot of unnecessary loops. For now though, this seems to eliminate duplicates just fine, and I think it's simpler.

 
Campbell Ritchie
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jim Venolia wrote:. . .. . . .

Don't you know why you shouldn't call that class Character? And the List's identifer shouldn't have a capital C.
 
Jim Venolia
Ranch Hand
Posts: 523
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that fell into the "wish I could edit my posts" category.  I got stuck on the look and feel of the code without paying attention to the actual code, and didn't notice until I hit the submit button.
 
Szabolcs Maár
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Jim Venolia wrote:. . .. . . .

Don't you know why you shouldn't call that class Character? And the List's identifer shouldn't have a capital C.


Very good point. Fixed it. Class is called Member now.

Jim Venolia wrote:Yeah, that fell into the "wish I could edit my posts" category.  I got stuck on the look and feel of the code without paying attention to the actual code, and didn't notice until I hit the submit button.


 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!