Nothing is withheld from us what we have conceived to do.
-Russel Kirsch-
Steve
Nothing is withheld from us what we have conceived to do.
-Russel Kirsch-
Justin Coombs wrote:Keep in mind I'm a beginner and I just want to figure out how to make things work without errors right now
The Player has to create a new Card to access the methods of the Card class...I thought that that is a normal thing;
to instantiate an instance of a separate class in order to access their methods. Why would I need to initialize all of its fields (with a constructor I haven't made yet :P) when its just a local variable made to access methods in the card class and then disappear after Player.hand
has been assigned the return data from Card.getHand. The name temp is named temp because its only there to do a job temporarily and then go away.
So if I made a separate deck class as you suggest, I would still be required to essentially create the exact same method in the deck class in order to getCard 52 times from the card class...this will bring me right back to the same issue I'm having right now, which is how do I pass an ArrayList. It would just be the Player class calling the deck instead of the card in that case...either way, I still don't know how to do it.
...issue I'm having right now, which is how do I pass an ArrayList...either way, I still don't know how to do it.
Steve
so the player should no make the deck.
Nothing is withheld from us what we have conceived to do.
-Russel Kirsch-
Justin Coombs wrote:
so the player should no make the deck.
Am I missing something here? The player does not make the deck. I don't understand where you're making that assumption. Look at the code for class Player I posted. It has 2 methods, one to display an ArrayList and the other to simply receive 2 cards from the Card class. The player does not have anything to do with instantiating or initializing the fields of a deck, or the Card objects contained within that deck. deck is called in class Card, but class Player has nothing to do with making a deck. In fact, if you look at game manager and the order in which the stack would execute, you would see that by the time the execution gets to touching class Player, the preDeck had already been created, filled with Card objects and all necessary fields stamped on each card, and ArrayList deck had already had 52 card objects appended to it.
I don't see how player has anything to do with making a deck.
Why is it bad style to basically say "A Card has such and such instance variables, and when we take 2 or more cards and add them to an ArrayList of type Card, we shall call it something different to indicate its nature of plurality, such as - in this case - Card(Singular) vs deck(2 or more Cards). I don't understand how that is bad design style.
Also, local variables are consumables. They can be just arbitrary things you don't give a hoot about; you only use it as a means to an end. And when that local variable goes out of scope, its all fine and well because I never intended to keep the thing around anyway...so why should I bother to initialize its fields in the case of the Player.receiveHand?
If its only a tool card to simply allow access to class card and I don't want to keep it afterwards, why make it a King of spades for example?
It's just gonna disappear when I execution passes the closing brace anyway.
Not only that, but also, why in the heck would I want to make ANOTHER King of Spades when there's already one in Card.deck.
I was always taught to think about programming design in terms of tangible objects. Like "what does a Card object know about itself(i.e. face, suit) and what does and object do(its methods)." In keeping with that approach to object oriented design, I don't understand why a deck in class card is such a bad idea.
All a deck is is a collection of cards.
All an ArrayList, in this program, is a collection of objects. The getHand method essentially just takes Cards from the bigger pile dubbed "deck" and arranges them into a smaller pile dubbed "temp" which can then be passed to the player to become his own hand, quite like in real life.
The only way to make it more proper i guess would be to make a dealer class that handles the passing of cards...
but then the dealer class would still have to create a card in order to access the card objects of the card class, and as you said, a [dealer/player] in real life does not simply snap their fingers and CREATE a card(especially not a BLANK one), so again, back to the same issue.
I understand that there are certain standards in object oriented design that must be adhered to for code to be readable and maintainable and things like that, as well as make sense to people adding to or patching previously written code, but you're not going to get java whizzes in the "beginning java" section of the forums.
As a newbie, its extremely frustrating trying to learn and understand how to use the colossal library of tools available in the java API without getting error messages, and its difficult to get so much advise about proper design patterns and things like that when you try to reach out for help about a specific issue that personally is what you are stuck on at the moment.
I'm not stuck on proper class layout and software design principles. I haven't even got there yet.
I'm still trying to figure out how to make the machine count to 10.
Steve
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |