Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Programming a Card Game (noob questions)

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Programming a Card Game (noob questions)

    Hello.

    I am new at programming, but I thought about creating a Card Game using Java.

    It is a two player game called "Crapot", and I know the rules very well.

    This game uses a lot of "drag and drop" moves, and each player has 52 cards.

    I am currently playing with Netbeans' GUI Builder, learning about jpanels, frames, labels, etc...Though, I am not still sure what kind of Swing objects I should use, and I haven't found a "Java card game tutorial for newbies" or something of the sort.

    I suppose this might be a too generic question, but I'll give a practical example : 13 of those 52 cards are on a separate deck turned upside down. When clicking on the deck, the top card should face up (so i'm guessing, this is an "Event"). Is it important to use jlabels here or something else?

    Thank you in advance and good work.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    The project sounds like it needs a lot of fancy GUI. Its hard to recommend anything without knowning more about the mechanics of play.
    Can face up cards be partially overlain or will they always show full face?
    Can cards be positioned anywhere on the table or only in fixed locations.
    How many cards could be shown face up at one time?
    Can any card be clicked on to cause an event?
    etc

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    EDIT : First of all, pardon my english. It's not my native language.

    Well, it's a kind of "solitaire" game for two.
    Each player has a 39 card deck and a small 13 card deck, both starting face down, and a "garbage deck" starting as null. The objective is to be the one first getting rid of the 52 cards.
    The small deck's top card is revealed. Both top cards are compared to check who's playing first (the lower value card wins).

    The game table is then drawn.
    The game "table" is like a 4x4 structure where cards will be placed, common to both players. They'll both interact with the same table. Both players place the first 4 cards from the big deck on the table face up, filling the side columns on the structure (of course this process is automatic, no player actions required here). I'll explain the middle columns later.

    The starting player can now move the cards on the table, by placing the cards partially over the others, with the following restriction : I can only move a card on top of a bigger value one of a different coloured suit (like moving a 4 of clubs over a 5 of hearts). Imagine each side column as an array with overlain cards, in a descending order from center to side. Example of a game table (J - Jack, Q - Queen, H - Hearts, D - Diamonds, C - Clubs, S - Spades) :

    Edit : Sorry, I couldn't align the columns here

    (6S)(7H)(8C)(9H)(10C) - - (KS)

    (10H)(JC) - - Free space

    (2C)(3D)(4C)(5H) - - (QC)

    (QC)(JD) - - (10S) (9D)

    After rearranging the cards as I see fit, I check if there is a free space. If so, I can put a card from my small deck in that space, revealling the next card. If all spaces are full, I reveal the big deck top card and try to place it on the table, following the said rules. If there's nothing else I can do with it, it will go to the garbage deck face up, starting the opponents's turn. At anytime during my turn, I can rearrange the table cards.

    The middle columns are for putting the aces first, which are the lowest value cards (two aces of each suit - 8 aces). Ex : I place and Ace of Spades in a middle space. After that I can put a 2 of Spades and so on... This also counts as "rearranging". I can also put cards from my big, small and garbage decks in the middle spaces, as long as they are immediatly higher than the top card in the target space.

    It's also important for the players to see the other player's three decks : If I draw a card from the big deck and can't place it on the table, I can always try to move the card to my opponent's garbage deck, abiding the following rule : the card has to be higher or lower and of the same suit. Ex : If the opponent has a 10 of clubs on his garbage deck, I can always "charge" is pile with a Jack of clubs or a 9 of clubs.

    When all the cards of the big deck are used, the garbage deck is turned upside down, becoming the new big deck and the game proceeds normally.

    I might be missing something, but this is the "basic" premise of the card game.
    Last edited by Taliesin; August 27th, 2011 at 03:19 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    To answer my questions
    The cards do not overlap, they go in fixed positions and any card can be clicked on.

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    Thank you.

    If so, am I using the right tools?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    Sorry, what tools? Java, Swing ???

  7. #7
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    Sorry, I meant "what Java Swing objects should I use to represent the columns, the decks, etc...??"
    I don't even know what should I use for the game layout (a panel, a frame?).

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    I guess you should look at the layout managers for how to layout your card positions.
    Would a grid layout work?
    Then maybe labels or buttons to hold the card images.

  9. #9
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    Quote Originally Posted by Norm View Post
    I guess you should look at the layout managers for how to layout your card positions.
    Would a grid layout work?
    Then maybe labels or buttons to hold the card images.
    I guess I could use GridBag as the main layout.
    I don't know how I can get multiple cards on the side columns, overlaying each other. I have to use some sort of resizable Java Swing field which could take up to 13 cards.

    By the way, I found a website with the game's explanation. I think english speaking people call it "Russian Bank". The pictures there show(almost) exactly the layout I wish to create.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    I used to know how to play Russian bank. I played it with my aunt years ago.
    I don't know how I can get multiple cards on the side columns, overlaying each other
    Perhaps a custom component where you can draw the parts of the cards that are showing as they are overlapped. There is no problem if the drawing is rectangular. Otherwise draw the images from the bottom up might give the effect you want. Double buffering could be of use here: Draw the cards in an external buffered image and then draw that image in the component's paint method.

  11. #11
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    I understand I should create classes for the "card", "deck", "player", "layout", the "game rules", etc...

    What class should be responsible for assigning a certain .jpg file reference to a given card? Is it the deck class? Or the main class itself?
    I don't even know if there's any relevance here, by choosing the "right" class to process this.
    Last edited by Taliesin; August 30th, 2011 at 02:47 PM.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    The Card class should take care of the jpg it uses. I could be passed in the constructor.

  13. #13
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    Thank you.

    I've been following a java tutorial regarding Interfaces and Abstract Methods.
    As I see it, I can use an interface if I want to re-use some of my classes (to create another card game, for instance), but I may not be grasping it's importance.
    As for abstract methods, I don't find it necessary to create subclasses, but I'm afraid I may not be looking at the whole picture here.

    What do you think? I want to design this project using UML and I should by now get understand these concepts.

    Am I following the right order of procedure? Once again, pardon my english and the rookie spam questions.

    Kind regards

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    An interface is not for reusing classes. It is for adding a "type" to a class so an instance of the class can be passed to a method that requires an object of a certain type. A common example is the addActionListener method which requires an object of type ActionListener.

    Sorry, I don't know anything about UML.

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Programming a Card Game (noob questions)

    You might not like this advice, but I strongly recommend you separate your game logic from your GUI- the best way to do that is to forget about the GUI for now. Write the game so that you can play it on the command prompt. Then when you have that completely working, you can think about what you want it to look like. Trying to deal with game logic AND gui logic is just going to be a huge frustrating headache, and you aren't very likely to finish with that approach.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Programming a Card Game (noob questions)

    Russian bank is a double solitaire game. I can't imagine how to play that from the console.
    Which cards in which pile to move to which pile.

    It's a close call on which would be harder to code: GUI or command prompt.

  17. #17
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Programming a Card Game (noob questions)

    I guess I'm not really talking about a full game- just the basics, being able to keep track of whose turn it is, what's on top of the deck, issue commands to move from stack to stack, etc. I think it could be done with some really basic ascii art printed to the console each turn, maybe?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  18. #18
    Junior Member
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming a Card Game (noob questions)

    Yes, I was already persuaded by a friend to create the game first, the GUI later. I was just trying to think ahead, but I got enough obstacles as it is in this starting phase, like choosing to implement interfaces or using abstracts (if they're of any relevance at all), or which class should control X variables, etc...
    On the other hand, I was taught (a long time ago) to draw these kinds of projects and being also able to draw the GUI that would go with them, which is why I feel a bit frustrated.

    Following your advices, I can try to create the game first and just check a few important functions on the command prompt. Let's see how it goes.

    One thing I didn't mention : One of the main objectives is making this playable over the internet. Should this be taken in account at this point, or later?

Similar Threads

  1. Card Game help....
    By macFs89H in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 2nd, 2011, 07:55 AM
  2. Card Game Problem....Need Help
    By macFs89H in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2011, 07:30 AM
  3. help on war card game project
    By sc0field1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 3rd, 2011, 04:51 AM
  4. Noob that needs some clearing up with Java style programming
    By looneylu in forum Java Theory & Questions
    Replies: 3
    Last Post: January 23rd, 2011, 11:27 PM
  5. Programming noob here, need help!
    By artenuga54 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2010, 04:04 PM