Carey Brown wrote:
What happens if characterCurrentDrinks is exactly 9?
I wrote:People who are familiar enough with pop culture and the books or movies can easily figure out that LOTR stands for "Lord of the Rings"
Marius Semeon wrote:in the OPs Character class, two separate methods instantiate new Random objects each time they're called. Wouldn't it be simpler to declare and instantiate a random object as an instance variable of the Character class and just use this same object in each of the methods?
Marius Semeon wrote:I would love to learn the specifics in workflow/style towards writing more compact, eloquent and maintainable code- but it's difficult to learn it quickly, compared to nuts and bolts stuff like syntax (/ the appropriate usage of it) or expanding your knowledge of the API.
Adam Thompson wrote:Do I seem to be understanding the basics of how to structure my code in an OOP manner? Am I using classes, methods, etc. appropriately?
I wrote:Then, implement randomOpponent() as something like this:
Junilu Lacar wrote:
Adam Thompson wrote:Do I seem to be understanding the basics of how to structure my code in an OOP manner? Am I using classes, methods, etc. appropriately?
The more I read through the code, the less I understand your motivation for structuring it the way you did and choosing the names and relationships of the classes the way you did. The LOTRGame class creates a Game object which in turn creates a Character object. Then it creates a new DrinkingGame object each time the user says they want to keep playing. The whole thing seems like an overly complicated Rube Goldberg machine that uses way too much code to achieve its goal.
It seems to me that having three different "game" classes is unnecessary. Try to cut it down to one class that drives the flow of the game. Then try to make the methods smaller and focused on smaller tasks. Try to see what each task logically belongs to: either a Character object or the Game object.
Then think of the high-level code you write as a script, and each object plays its role, interacting with the other object as needed. Kind of like "Game object asks user which character he wants to play. Game object creates a random opponent character. Game object tells the main character to drink. Game object tells the opponent to drink. Each character drinks and updates its status based on its race and inherent ability to hold up and not pass out. Game object checks if opponent is still standing. Game object checks if main character is still standing. Game is over when one or both are too drunk to stay standing."
When you have a script like this, it's easier to see where fields should be assigned and initialized, what methods need to be assigned to each class, what the return types should be, etc.
Junilu Lacar wrote:
Can you get a better sense of a story from this code?
Marius Semeon wrote:Thank you for introducing me to all these concepts, I'd never heard of WET, DRY, SOlID, etc. I will have a look at those books too.
I wrote:
Can you get a better sense of a story from this code?
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|