Card games

Hello everyone,

I am proficient in Java, but I am new in game development, and I would like some guidance please :slight_smile:

I would like to develop a Java card game, but after identifying the obvious classes:

Card
Hand
Deck
Player(Abstract) extended by Human, Computer
Table

I am stuck :frowning:

Do you think Hand should be part of the Player class (Vector for example)?
Do you think Player should be objects inside Table?

Can you recommends any resources with examples so I can understand how to start? I know that I must make objects communicate to simulate the game, but what is the “proper” way or pattern used?

I read that you can use pattern such as MVC or observer observable to have the same game be played from console window, GUI, remote client etc… I like this idea, but I don’t have the experience to implement it :frowning:

Also, I read about the Facade pattern were you sum up all the objects into a single class so it becomes like a framework. What methods should a proper Facade support in a card game? game.start() game.bet()?

I would like to start coding a simple game with only console input/output and then worry about graphics etc, and use good design practises so I dont need to keep stating from scratch all the time if I add/remove to it.

Thanks for your time, and any help is very appreciated :slight_smile:

I can’t give you any complete resources articles about making a game, but as for my own experience, I’m able to give you some guidelines to follow up.

  • first, a MVC interface is roughly recommended vs. a console command line input interface, whatever is your knowledge about UI.
    MVC is roughly based on setting up a PREVIEW of how will your game look like, as exactly as you can, what you see is what you get (maybe a WYSIWYG builder like Matisse can help you at this step).

  • afterwards your MVC is completed, launch your first MVC build in shell or IDE builder and try focusing your user actions on the essential features, e.g. a non-exhausitve list of Action’s :
    - start game
    - quit game
    - help dialog
    - scores and highscores
    - multiplayer interface, pop-ups, pause/resume, window look & feel, etc.

  • consequently but not the least, the background algorithm can be now implemented in such Swing Timer’s or Thread looping. MachinePlayer is confronted to the HumanPlayer and vice-versa as well as other combinaisons like RemotePlayer against MachinePlayer etc… Threading knowledge is the most valuable beyond all of the graphics facilities and inputs.

That’d be all and complete for a game. :slight_smile:
It’s not my personal view, but a logical structure that you can find in many High-School curses and Java Books. ;D

some other things:
choose if you will use active or passive drawing. Awt or Swing.
Also note that when you use mvc you have to use events/listeners to let other objects know that something should be done.
This is an example http://www.ibm.com/developerworks/java/library/j-tetris/ that uses mvc.
Don’t put everything inside one class, It’s even better to put related classes into another package.

Thanks for the info, the article is oh help.

Also, can someone check out my design and say if it ok? Do I need to make more classes? less? Hand can be an arraylist in player of type Card for example?

I really need a java “card games” tutorial/article please.

I feel I am lost :confused:

It’s impossible to answer to such a question. Just go ahead with one design an change it when you need to.

It’s not important that how many or few classes there are. Most important is that the code is easy to maintain - then you can always mold the architecture to suit new requirements. Writing code using the TDD style helps in keeping software “soft”.

[quote=“Javec,post:4,topic:30961”]
Less - If you don’t know why you need a class then don’t have one. As a rule; simpler==better.
A lot depends on what game you’re writing; Beggar-my-neighbour is very different from Poker.
As an exercise, imagine that the pack is represented by the numbers 0-51 (where 0-12 is hearts, 13-25 clubs &c) so a poker hand would simply be an array of 5 numbers. See if you can work with that, if not, decide why not. What extra information would you need and why?

I designed my game, but I came to a point were I don’t know how to make the classes work together.

I got

Card
Deck (52 Card)
User (extends Player)
Computer (extends Player)
Table

and a Game class which will be the main loop. However, I am not sure how to implement betting

Table.bet(player.bet(10)); could mean deduct 10 from the player object and add to the pot instance variable of table.

Is this “proper”? or a bad design?

http://www.javaworld.com/javaworld/jw-08-1996/jw-08-cards.html

Betting can be done like this:
The Player class contains an int to store the betting info. The Player.bet() method can subtract the amount from the Player’s pool and add it to the tables pot like Table.addToPot(Player.bet()).
The betting sequence will go like this:
Game gets to betting section
Loop through all the players and get their betting amount.
Add that amount to the total pot

And when the round is over you check to see who won and add the pot to his cash pool.

Helpfull, but source code not available to reference when reading :frowning: