Java Card Game (Carioca)

Hi everyone.
Im currently making a card game in java for a south american game called Carioca
originally i had
CariocaController, which controlled game logic such as creating cards and players, dealing the cards setting the cards etc.
btnStartGame in GUI would run controller method startGame which would initialize everything then set the GUI.
CariocaTablelGUI, which extended JFrame and set the game GUI by using swingcomponents (JButtons with ImageIcons for cards)
Card, like it says, card suit, no and value
Deck, which created an ArrayList<Card> + 2 jokers.
Pile which extended ArrayList<Card>. (Used for creating the 2deck game, player hands, putdown pile)
Ive never been to good with GUI's and not enjoying my inopropriate gui structure i decided to read about java game designs.
I read OReilly Killer Game Programming in Java chapters 1-13 before it got into 3d java. and not feeling it provided the examples i needed i went back to my old book
Deitel & Deitel How to program Java Fifth edition. which has a case study of ElevatorSimulation which uses the Model View Controller design pattern.
I have used this simulation as my guide to reform my code structure as i want to create this game as proffesionally and efficiently as possible.
Now i have.
CariocaTable which extends JFrame and in its constructor;
          // instantiate model, view and ,controller
          model = new CariocaModel();
          view = new CariocaPanel();
          controller = new CariocaController(model);
          // register View for Model events
          model.setCariocaListener( view );
          add(view, BorderLayout.CENTER);
          add(controller, BorderLayout.SOUTH);CariocaPanel in it has 4 player panels (4 player max game) which would contain their hands. then a center panel which contains the pickup and putdown piles.
I am having alot of trouble implementing this pattern to my game (mybe im on the wrong track).
the controller (in the ElevatorSimulation ) has 2 buttons which executes model method addPerson, thats about all the controller does which rocks my understanding.
the model implements ElevatorSimulationListener (which extends all needed listeners) and has private variabels for all listeners.
it then has a setElevatorSimulationListener(ElevatorSimulationListener listener) which is set with the view class.
i have trouble understanding the communication between controller-view and model-view.. controller has to go threw model to talk to view but model only talks to view through listener methods
public void lightTurnedOff( LightEvent lightEvent )
//variable lightListener is the view.
      lightListener.lightTurnedOff( lightEvent );
   }i dont know where all the logic should go. i currently have model with the startGame method which creates players and cards, deals cards etc.
am i on the right track. am i misunderstanding the design pattern? im sorry for the lengthy post, im having trouble understanding this and would like assistance with my understanding or even refer me to a book or website the would be helpful. if u would like more information please do ask.

morgalr wrote:
OK, I'll make a few assumptions and you can correct me if I am wrong on any of them:
1 - the game is for 1 person to play against the computer
2 - you may want to expend to multiplayer at some point
3 - you would like to have the structure of the game as modular as possible to allow changesThank you for replying, yes thats exactly right.
My approach now is to maintain the same structure as before instead of using the ElevatorSimulation as a guide.
CariocaController will contain game logic and the static main method, and will update CariocaTable threw set methods.
i will keep the revamped GUI classes, using what ive learned about using 2d instead of Swing Components, ive created an ImageLoader class which CariocaTable instantiates that loads all images into a hash map. PlayerPanel for each player, each panel contains variable Player, Pile hand, Pile downHand (objective of the game). Mybe i should get rid of the pile variables since the class Player already contains them?
Its the drawing of the GUI that gets to me. Any other suggestions or ideas?

Similar Messages

  • Need some OO design pointers for a Java card game I wrote for uni

    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
         private int value;                    //variable for the value of the card
         private int suit;                         //variable for the suit of the card
         private ImageIcon frontOfCard;     //Displays the image of the front of the cards
         private ImageIcon backOfCard;          //displays the image of the back of the cards
         public Card (int Value, int Suit, ImageIcon front, ImageIcon back)
              value = Value;               
              suit = Suit;               
              frontOfCard = front;     
              backOfCard = back;
              setIcon(backOfCard);     //To make it non-visible when dealt
         }As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    Card class
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instance
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.
    AI Class extends Player Class
    GUI Class
    Deck Class <-- contains 52 cards
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    Any help on this would be greatly appreciated!
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.

    Faz_86 wrote:
    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    Admirable, and the best way to learn, doing something that interests you.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    Do a quick Google on the model view controller pattern. Your listeners are your controllers. Your JPanel, JButton, etc. are your view. The AI, Player, Card and Deck (and presumably something like Score) are your model. Your model should be completely testable and not dependent on either the controller or the view. Imagine you could play the game from the command line. Get that working first. Then you can add all the bells and whistles for the UI.
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
    (redacted)
    As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.Extending JPanel is fine. As you noted, you need something to add listeners to. However, I would separate things a bit. First, a card really only has a rank and suit (and perhaps an association to either the deck or a player holding the card). The notion of setIcon() is where you are tripping up. The card itself exists in memory. You should be able to test a card without using a UI. Create a separate class (CardPanel or something similar) that has a reference to a Card and the additional methods needed for your UI.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    I am not an animation buff, so I will assume the above works.
    Card classRemove the UI aspects to this class, and I think you are all set here.
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instancePresumably this is where main() resides. It will certainly have a reference to model classes (player, game, deck, etc.) and likely the master JFrame (or a controller class you create yourself).
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.Does a player really have multiple hands? It seems to me more of a one-to-one relationship (or a player has a one-to-many relationship to Card).
    AI Class extends Player ClassWhy extend Player? Create a Player interface, then have a HumanPlayer and AIPlayer implementation. Common parts could be refactored out into either a helper class (delegation) or AbstractPlayer (inheritance).
    GUI ClassMy assumption is that this class has a reference to the master JFrame.
    Deck Class <-- contains 52 cards
    Yes. You may end up recycling this class such that a Deck can also function as a Hand for a given player. If there are differences between the two, create an interface and have a Hand and a Deck implementation. Coding to interfaces is a good thing.
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?You need to pass a reference to the appropriate view class. That is how MVC works. The controller receives a request from the view, dispatches to some model functionality you write (such as GameRulesEngine, Deck, etc.) and returns a result to the view (which could be the same view or a different one, imagine someone clicking 'high scores').
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    That is up to you to write the animation code. In principle, you have a mouse listener, and then you take the appropriate rendering steps.
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    See above.
    Any help on this would be greatly appreciated!
    You are welcome.
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.No, you have been doing fine.
    - Saish

  • Card Game related question

    Hello, I am not sure what forum this goes to or if it goes under any forum, but I was wonder if anyone has a way of taking an array of 7 cards placing an array of 5 cards made from the seven in a hashtable so that it will drop ever possible combination of those cards.
    Or if you have a better way of doing that
    If you are wonder I am making a Texas Holdem style poker game...
    Thank you for any and all help :)

    Start here:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
    Good beginner card game examples there.
    As far as every possible combination, you will probably need a recursive combinations method of some sort.

  • Question - making rummy card game applet

    Hi, I am not sure if this is the right place to be putting this, if not please let me know. I'm trying to make an applet for the card game rummy for my final project for school. I was wondering if I could get some help on how to load a card image from a file and randomizing the images for the deal button or if not that then I am also trying a much simpler way due to time constraints. I was trying to make two arrays of strings: one for the facevalue of the card and another for the suit value, then randomize those and draw a string to the correct places for the dealt hand. I can't seem to get this to work well so far. Any help is greatly appreciated. Here is the code for the basic gui that I have now.
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.Random;
    import java.lang.*;
    public class CardGame extends Applet implements ActionListener {
         Button Deal;
         Button NewGame;
         Button PutDown;
         Color bgColor;
         Color rectColor;
         Image deck;
         MediaTracker mt;
         CheckboxGroup radioGroup;
         Checkbox radio1;
         Checkbox radio2;
         Checkbox radio3;
         Checkbox radio4;
         Checkbox radio5;
         Checkbox radio6;
         Checkbox radio7;
    **Its hard to tell but the arrays are commented out for now.     
         //String[] faceValue = {"ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"};
    //     String[] suitValue = {"CLUBS", "HEARTS", "SPADES", "DIAMONDS"};
         public void init()
              setLayout(null);
              mt = new MediaTracker(this);
              Deal = new Button("Deal");
              NewGame = new Button("New Game");
              PutDown = new Button("Put Down");
              Deal.setBounds(750, 450, 75, 25);
              NewGame.setBounds(750, 475, 75, 25);
              PutDown.setBounds(750, 425, 75, 25);
              add(Deal);
              add(NewGame);
              add(PutDown);
              Deal.addActionListener(this);
              NewGame.addActionListener(this);
              PutDown.addActionListener(this);
              radioGroup = new CheckboxGroup();
              radio1 = new Checkbox(" ", radioGroup, false);
              radio2 = new Checkbox(" ", radioGroup, false);
              radio3 = new Checkbox(" ", radioGroup, false);
              radio4 = new Checkbox(" ", radioGroup, false);
              radio5 = new Checkbox(" ", radioGroup, false);
              radio6 = new Checkbox(" ", radioGroup, false);
              radio7 = new Checkbox(" ", radioGroup, false);
              add(radio1);
              add(radio2);
              add(radio3);
              add(radio4);
              add(radio5);
              add(radio6);
              add(radio7);
              radio1.setBounds(143, 525, 10, 10);
              radio2.setBounds(222, 525, 10, 10);
              radio3.setBounds(301, 525, 10, 10);
              radio4.setBounds(380, 525, 10, 10);
              radio5.setBounds(459, 525, 10, 10);
              radio6.setBounds(538, 525, 10, 10);
              radio7.setBounds(617, 525, 10, 10);
         public void Randomize()
              //this is where I need the help mostly.
         public void Stop()
         public void actionPerformed(ActionEvent evt)
         if (evt.getSource()== Deal)
                   setBackground(Color.green); //test
              else
                   Deal.setLabel("Not there, here!"); //another test
         if(radio1.getState())
                   setBackground(Color.blue); //just a test to make sure I know how to use the radio buttons
         public void paint(Graphics g) {
              g.drawString("Welcome to Rummy!!", 300, 50 );
              g.drawRect(100, 100, 600, 440);
              g.drawRect(110, 420, 75, 100);
              g.drawRect(190, 420, 75, 100);
              g.drawRect(270, 420, 75, 100);
              g.drawRect(350, 420, 75, 100);
              g.drawRect(430, 420, 75, 100);
              g.drawRect(510, 420, 75, 100);
              g.drawRect(590, 420, 75, 100);
              g.drawRect(110, 120, 75, 100);
              g.drawRect(190, 120, 75, 100);
              g.drawRect(270, 120, 75, 100);
              g.drawRect(350, 120, 75, 100);
              g.drawRect(430, 120, 75, 100);
              g.drawRect(510, 120, 75, 100);
              g.drawRect(590, 120, 75, 100);
              g.drawRect(300, 250, 75, 100);
              g.drawRect(380, 250, 75, 100);
              g.drawString("A S", 220, 445);
    }

    thanks for that...could I use something like this for the playing card class though:
    public class Card {
    public final static int SPADES = 0, // Codes for the 4 suits.
    HEARTS = 1,
    DIAMONDS = 2,
    CLUBS = 3;
    public final static int ACE = 1, // Codes for the non-numeric cards.
    JACK = 11, // Cards 2 through 10 have their
    QUEEN = 12, // numerical values for their codes.
    KING = 13;
    private final int suit; // The suit of this card, one of the constants
    // SPADES, HEARTS, DIAMONDS, CLUBS.
    private final int value; // The value of this card, from 1 to 11.
    public Card(int theValue, int theSuit) {
    // Construct a card with the specified value and suit.
    // Value must be between 1 and 13. Suit must be between
    // 0 and 3. If the parameters are outside these ranges,
    // the constructed card object will be invalid.
    value = theValue;
    suit = theSuit;
    public int getSuit() {
    // Return the int that codes for this card's suit.
    return suit;
    public int getValue() {
    // Return the int that codes for this card's value.
    return value;
    public String getSuitAsString() {
    // Return a String representing the card's suit.
    // (If the card's suit is invalid, "??" is returned.)
    switch ( suit ) {
    case SPADES: return "Spades";
    case HEARTS: return "Hearts";
    case DIAMONDS: return "Diamonds";
    case CLUBS: return "Clubs";
    default: return "??";
    public String getValueAsString() {
    // Return a String representing the card's value.
    // If the card's value is invalid, "??" is returned.
    switch ( value ) {
    case 1: return "Ace";
    case 2: return "2";
    case 3: return "3";
    case 4: return "4";
    case 5: return "5";
    case 6: return "6";
    case 7: return "7";
    case 8: return "8";
    case 9: return "9";
    case 10: return "10";
    case 11: return "Jack";
    case 12: return "Queen";
    case 13: return "King";
    default: return "??";
    public String toString() {
    // Return a String representation of this card, such as
    // "10 of Hearts" or "Queen of Spades".
    return getValueAsString() + " of " + getSuitAsString();
    } // end class Card
    except now how would I make something like this random I know theres a bunch of work before that, but just curious. Thanks

  • Pls: I have some problems with GOP java card. who can help me?

    hello, all
    I am going to install my cap file into Global Open Platform Card( S1-TiEx-S32J, which uses GP2.0.1) now.
    but, I have failed.
    I use J2SDK1.4.2.10 when I compile the java file.
    And use Java Card 2.2.1 Development Kit when I convert to cap file.
    The sequences of the command / response are below;
    [SEND]00A4040007A0000000030000
    [RECV]611F
    [SEND]00C000001F
    [RECV]6F188408A000000003000000A50D9F6E0A42505042474F317601019F6501FE9000
    [SEND]80500000082021222324252627
    [RECV]611C
    [SEND]00C000001C
    [RECV]0000FFFFFFFFFFFFFFFF0000E1C81BD9C2573DF5AA8EEB95251A95A59000
    [SEND]8482000010A8BD185CD6A3940C83855021A4DFF412
    [RECV]9000
    [SEND]80E60200050000000000
    [RECV]6700
    What was wrong?
    If you are experience with this kind of java card, pls help me.
    with best regards,
    yong lee

    Andalib3,
    There are a couple of options that you have as far as getting this to work. First off go to Control Panel and then to Sounds and Audio Devices (or multimedia depending on the version of windows). In here go to the Audio tab and then under preferred Midi Playback Device you should have a couple of options. There are two settings here that will work:
    ) Microsoft GS Wavetable Synth - This is a very basic midi sound set that is emulated by the OS
    2) Li've! Midi Synth (A or B) - This is the hardware midi synth on the card.
    Make sure one of these is selected as the default midi playback device and then test your games again.
    Jeremy

  • Playing online card games such as euchre or spades

    All right here is my problem: I want to play card games online with other users. I'm new to Mac and so far this is my only problem. On my old PC I could go online to pogo.com or anywhere and play a card game no problem. Now I get the room loaded for the game but it's only the outline. There are no users and no tables. Everything is blank. I thought it could be something to do with java, but I'm not sure. I have done software updates, downloaded adobe shockwave and tried numerous different java settings. Any ideas? Am I missing another piece of software?

    What browser are you using? Could be the site is optimized for windows compatible browser. Contact the web site and find out if your browser has issues with their site and which Mac browsers are compatible.

  • HT5268 I down loaded the new update today, now I can't play my favorite card game..? HELP!

    I downloaded the new java update today, now I can't play my favorite card game : ( Why?

    I don't know.  But you should check to see if there is an update available for the card game.

  • Client Server card game

    Hi all,
    I wanted to make a card game that my friends and I could all play, but I have no experience at all with network programming. I am assuming I need a client and a server class. Is there a good tutorial, or does someone have some really simple sample code to get me started for each the client and the server? I have searched google, but I didn't find anything good, (the only thing I found was using Datagrams, and I didn't think that would work since messages aren't guaranteed to be delivered, and they aren't guaranteed to be in order).
    Any help would be greatly appreciated. Thanks!

    try Java Tutorial about networking:
    http://java.sun.com/docs/books/tutorial/networking/index.html
    there's a section about sockets (better than datagrams for your task) and it includes sample client/server app.
    another sources for you:
    http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html
    http://bdn.borland.com/article/31995
    and a list of articles, some of them seem interesting:
    http://www.javaolympus.com/J2SE/NETWORKING/JavaSockets/JavaSockets.jsp

  • Complete beginner: Creating Card Game program

    I am brand new to object oriented programming, i'm trying to write a simple card game program, without using arrays or importing packages or vectors (whatever they all are?). can someone please help me?

    First of all, arrays are a very good idea, as are other datastructures such as the hashtable. But you can also use a String, which is basically an array of characters.
    The initial hurdle you will have in writing a card game will be modelling a single playing card. Your program will likely understand the sequence of cards as 2,3,4,5,6,7,8,9,10,11,12,13, even tho you will want to present this to your user as 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Computers deal well with the numbers, Humans like to refer to cards using the familiar symbolic references (J, Q, K, A). Suits likewise will probably be stores as integers (0-3).
    Your program will have to determine whether one playing card is less than or greater than another, whether it is in the same suit, what value the card will have (for BlackJack, for instace). All of these behaviors can be engineered into your PlayingCard class.
    To get going with your card game, you must thus begin an abstraction of the real-word PlayingCard. Start with a class such as this:
    class PlayingCard {
    final static String nums = "234567891JQKA" ;
    final static String [] suits = "DCHS";
    private int num, suit; // i.e. of this instance
    public PlayingCard (String card) { // constructor
    num = values.indexOf(card.charAt(0)) ;
    suit = suits.indexOf(card.charAt(card.length()-1);
    public String toString() {
    return nums.charAt(value)+((num==8)?"0":"")+suits.charAt(suit);
    int value() { return suit*4+num; }
    boolean compareValue(PlayingCard first, PlayingCard second) {
    return first.value() - second.value();
    boolean sameSuitAs(PlayingCard p) {
    return (this.suit == p.suit);
    // etc.
    For a BlackJackPlayingCard, extend PlayingCard and add/override specific behaviors such as counting (i.e. face cards = 10, Ace's two values, etc).
    Have fun. Java is a great language.

  • Anyone else here have Laggy performance in Java Applet Games?

    I noticed that when i play at pokerroom.com the games lag.  It is not internet lag for sure.  The poker games perform perfectly on my old PIII but on my new system teh games are choppy and laggy.
    I noticed that people are having choppiness and stuttering on their online games.  Perhaps this is linked.  Anyone else wanna give their experience?

    Quote
    Originally posted by Ludic
    I installed the card games for Firefox, and I am experiencing what you are talking about. I believe they are Javascript games. I don't experience any similar symptoms in regular 3d games.
    ok so you are experience this crappy perfromance in java applets then as well.  its not only me.
    unfortunatly i RMA'd my Motherboard and Processor already thinking one of those may have been the culprit.
    I guess this is an issue with the nvidia drivers...  hopefuly it will get fixed.  its pathetic that games are performing better on my PIII

  • Taking strict turns in a cards game

    I am implementing a cards game on the web and the clients are threads . how do I make them alternate strictly in turns on the server. Is there any way I can identify which thread it is and block its information.

    You can identify which thread is running with static method Thread.getCurrentThread() (or it can call the synchronized method with some arguments identifying it). It is easy then to have it wait if it is not ist turn. The server is passive, it has no specific thread. It knows of all players thread and of their ordering. Player threads will run its play method. In this method, they will wait until their turn has come.
    Here are too little classes that will sketch the system:
    import java.util.Date;
    public class GameServer extends Thread {
      private final Thread[] players;
      int currentPlayerIndex = 0;
      public GameServer() {
        players = new Thread[4];
        for (int p = 0; p < players.length; p++){
          players[p] = new PlayerThread(this, "Player " + (p+1));
          players[p].start();
      public synchronized void play(String playerName, long thinkTime){
        try{
          long waitStart = new Date().getTime();
          while(Thread.currentThread() != players[currentPlayerIndex])
            wait();
          long waitTime = new Date().getTime() - waitStart;
          System.out.println(playerName + " is playing. "
              + " Took " + thinkTime + " ms to think"
              + " Had then to wait for " + waitTime + " ms.");
          currentPlayerIndex = (currentPlayerIndex + 1) % players.length;
          notifyAll();
        } catch (InterruptedException e){
          e.printStackTrace();
      public static void main(String[] args){
        GameServer server = new GameServer();
    }Here is player thread
    public class PlayerThread extends Thread {
      private final GameServer server;
      public PlayerThread(GameServer aServer, String name) {
        super(name);
        server = aServer;
      public void run(){
        try {
          while(true){
            long thinkTime = Math.round(3000 * Math.random());
            Thread.sleep(thinkTime); // think
            server.play(getName(), thinkTime);
        } catch (InterruptedException e){
      }Two points:
    1) This has to be improved to resist one player thread going down. Otherwise, when its turn comes, over will wait forever. You might need to be more careful with InterruptedException, and to set up a ThreadGroup for players so that you be notified with uncaughtException.
    2) If players work the way I wrote them, you cannot do your scheduling with priorities. If a thread is sleeping (or waiting for some resource, or user input), giving it a high priority will not make its wait shorter. Another thread which happens to get its resource or input quicker will run first.. Better use priorities only as hints for optimization rather than for strongly constrained synchronization.

  • JCDE (Java Card Plugin) menu is not work on Eclipse

    I want to add JavaCard Applet into my existing project on Eclipse 4.2. So,
    1.I download EclipseJCDE and extract it into the plugin folder of Eclipse.
    2.When I open the eclipse, There are 2 menus appeared that is Java Card and JCWDE
    3.I add the Java Card Applet file into my project.
    Then I have a problem.

    Your reply did not help me access an update to JAVA to work with 10.8.3 to play JAVA related games. This is a REAL PROBLEM! As I subscribe to game websites and my family cannot play these games. I have contacted Apple Support and we tried uninstalling JAVA and reinstalling it from JAVA .com. We made sure my computer (IMAC) was set up to accept JAVA was turned on and I still have the same problem. JAVA related games will not play. The error message says "An updated JAVA has not been detected" So what am I to do? Who can help me with this type of problem? Apple Support asked me to contact JAVA by phone 1-800-223-1711 but they do not have any phone support. I was directed to a site called Live Support" and they charge $80.00 to resolve problems for an Apple computer or $1.00 a minute. Great choices! I accepted this offer however Apple will not allow third party developers to help. Do you have any ideas that will really help me?

  • Regarding java card programming

    hi all,
    i am very new to the java card tech. now i want to do a project in the smart card area. how can i ready to programming (downloadables)? i need some basic idea about tools to be downloaded. please provide me some ideas.
    Thanks and Ragards
    __Vasantha kumar

    Start with something more simple. You're just asking
    for trouble trying to start with something "big".Agreed. You may want to make a non-AI version of the game first. In other words, if you want to make a game of blackjack with an AI dealer. First make the blackjack game with no AI. So the user would deal his own cards and decide when to hit, stand, etc... After you understand how to let the player do that, you can move on to dealing with how a computer would do it.

  • Arrays- Cannot get card game to display a straight or full house

    Been trying to get this card game to tell the user if he/she's card hand contains a straight or a full house. Please e-mail me ASAP at [email protected] if you have an answer or idea. Thanks
    This is what i have so far:
    public void aStraight(Card[] hand)
    boolean haveAStraight = false;
    for(int i=0;i < hand.length;i++)
    for(int j=i+1;j < hand.length;j++)
    {  if(hand[i].getFace().equals(hand[j].getFace()))
    haveAStraight = true;
    else
    haveAStraight = false;
    i=5;j=5;
    if(haveAStraight)
    System.out.println("Your hand contains a Straight!!!");
    public void fullHouse(Card[] hand)
    boolean haveFullHouse = false;
    for(int i = 0; i < 2; i++)
    for(int j = i+1; j < 3; j++)
    if(hand.getFace().equals(hand[j].getFace()))
    haveFullHouse = true;
    else{
    haveFullHouse = false;
    i=2;j=3;
    if(haveFullHouse)
    System.out.println("Your hand contains a Full House!!!");

    Don't crosspost!
    Please answer in the other thread, because the other thread has slightly better formatting:
    http://forum.java.sun.com/thread.jspa?threadID=689861

  • Need suggestion regarding simulation of Java Card using a floppy

    Hi All,
    I am working on a project wherein I have to simulate a Java Card application using a floppy. I am writing my own Card Terminal and CardTerminalFactory. Thats what I have started working on. Will that serve the purpose or do I have to think about some other approach like just overriding the cardInserted method of CTListener class? I want to achieve communication between the host application and the floppy(which is my java card) Please advise.
    I would like to thank DurangoVa and Nilesh for helping me out sorting out the error in running the converter.
    Thanks in advance

    Are you referring to a Floppy diskette drive ?

Maybe you are looking for

  • Select Data from aufm too slow

    Hi experts, I have a query in my report but its performance too slow. is there any proper way or any way to improve the performance of below query. SELECT  * FROM  aufm     into table i_aufm          " collecting input material document numbers      

  • Error whilst trying to upload itunes 9

    Recently I have gotten a new Ipod (ipod classic, 160GB) and when I plugged it into my computer it said I need to update my itunes to itunes 9. When I tried to do this, at first it said it had downloaded and then when I tried to open it it would say E

  • Iphone missing auto-check messages

    I just got my wife an iphone and when I went to set her auto-check for her email in her settings she doesnt have that option.....anybody have any ideas? Thanks!

  • 0x8007004 Windows 8.1 Error (Detailed Error log)

    After trying to install 8.1 at least 10 times i found a thread that lead me to look for my error log file i pasted below. If anyone (Microsoft or none) can help that would be nice. Its to the point where most downloads require 8.1. Thanks in advanced

  • Dragging folder of photos does not create new roll

    The help system says if I drag an entire folder into the photo viewing area, iPhoto 4 creates a new roll. But when I try it, it just sorts them all into by date year folders -- often incorrectly. Can someone tell me what I'm doing wrong? Thanks.