• Post Reply Bookmark Topic Watch Topic
  • New Topic

Would enum Limit Duplication?  RSS feed

 
Richard Warner
Greenhorn
Posts: 16
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, my name is Richard Warner. I'm brand new to programming this last month and am determined to make a JAVA version on Eclipse of an old card game I created long ago, called "Flank."

// addendum: Sorry for the verbose post! If you're mentally compiling this, skip to mainQuestion(); in green.

This game will take 28 unique card faces with various final attributes: some shared, some unique. All cards will be grouped into four "suit" backs (allowing players semi-educated guesses concerning the face). But each instance of each of the 28 card faces (excepting its coordinates on the deck-board) is intended to NOT be unique, but can be a duplicate of any number of others on a randomly generated board.

I've been trying to read up here and elsewhere (but mostly watching some YouTube video examples of others' projects) while planning how to tackle this project and was wondering:

public class Question implements Ignorance{
public volatile boolean mainQuestion(){
/* Would enum restrict me in err.. instantiating duplicate cards? It sounds like it's the preferred method by folks making most card-type games, and looks much more succinct, but then again, most card-type games have one and only one instance of any given card. Sounds like this limitation/advantage (depending on what one is trying to do!) is... sort of built in? Flank cannot have a standard deck in that sense. (Like a magician saying "Is this your card"? is only impressive because most everyone suspects every standard deck to have only one instance of any given card) */
return JAVAwisdom;
}
}

if (myenumWorry == true){ I suspect even then there's always a work around with you clever code wranglers, but I don't want to be generating any more unorthodox code than I already inherently do that will undoubtedly confuse myself and others later. }

Would an Object Class for each card's face (and its associated properties) inheriting from its respective suit be better in this case? That's what I've been trying to do so far, and I'm hoping it'll allowed me to generate random deck-board layouts and simply call card.playMethod(); to get each one to perform its very unique behavior (or not-so unique if a duplicate) when err... referenced, which is why I'm intrigued but worried by the prospect of diving into enums. But while Objects for each card makes more sense to me, it feels less elegant (package explorer feels a bit overpopulated, and I'm just imagining all the mess of card objects splattering everywhere across the memory with my shakily-constructed imitations of for loops when populating the deck) and while I'm struggling a bit with cross-class referencing all its many components within my main class, I know I'll get it eventually, though, if this is the better way!

I've been trying out examples (i.e. blatantly stealing and adjusting to fit my needs) on both approaches, trying to break down videos of people coding to see why they're taking each step, but I can't find a clear "why" on this concept so far. (Given I'm still fiddling with the basics of getting much to display as I intend, it's hard for me to know whether I have two or one of something in actuality while testing) I am worried about the long road down one path or the other biting me later on. Or am I worried about something that's not a problem and either route is fine? (Should I just pick whichever one makes more sense to me?)

(Sorry if I'm using some wrong terms here, I'm still very new to this language)

Thanks!
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard, and welcome.

I kind of scanned your question a couple of times before realizing the "code" is really an inventive way you chose to phrase your question. Pretty clever, but it actually confused me a bit. You'll find a lot of helpful folks here (including me, I hope), but this is a very multicultural place. With all the international users, English is not the first language for a lot of us. So, if you'd repost your question in a more prosaic fashion, it might be clearer and get you more replies.

Best of luck with your project.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard,

Check this out, you might find it useful as well > HowToAskQuestionsOnJavaRanch
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would enum restrict me in err.. instantiating duplicate cards?


Not per se. It depends on how you implement it.

Should I just pick whichever one makes more sense to me?


I think that's a good place to start. Write out an outline of what you want to do, pick an implementation, and code it. Compile often (after every 10 lines or so). Then, if you have a specific problem, post the code (remember to UseCodeTags), and we'll try to help.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enum is useful if you have a fixed set of constant values.

playing cards are an example where enums are useful, since each playing card has a suit and a rank. Suit and rank are values that are both chosen from a fixed set of constant values, so enums would be suited for modeling suit and rank in a program. For example:

A card would then be a class with two member variables, a Suit and a Rank.

Oracle has many useful Java tutorials, including one about enum types.
 
Richard Warner
Greenhorn
Posts: 16
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies, all for the cutesy Pseudo Code / Red Herring faux pas (read the HowToAskQuestionsOnJavaRanch!)

Thanks folks! I'm going the route with all the card subclasses with this project now that I've found some tutorials on LinkedList, Stack, etc. and hope I'll find more built-in stuff to make this work. (I think I've been trying and failing to reinvent the wheel a bit) Based on a few tutorials, I assumed the built-in stuff was much more limited than it is because I didn't have any idea there was such a vast repertoire of commands to manipulate each (I thought calling any one did exactly what the tutorial before me showed and no more). I finally found F2 focus on Eclipse by accident and found I could read up on all the bits pertinent to each one right inside Eclipse! I'll have to tackle learning enums on my second project. It's nice to know enums would work for this project (implementation depending) if I get in a pinch with the route I'm taking now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!