How to make a High-Low card game in Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to make a High-Low card game in Java

  1. #1
    Join Date
    Feb 2004
    Posts
    11

    Question How to make a High-Low card game in Java

    Could some be so kind to outline the simplest way to make a non-advanced Java High-Low card game. I am making one using just one .java file for fun, but I have no idea where to start. My knowledge of Java is limited so this a daunting task I have assigned myself. If the High-Low concept part needs explaining please tell me so and I will explain it. Thank you in advance.

    Manilla

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    Well i'm guessing that there will be a visible card, and whoever is playing has to guess if the next card is higher or lower? You'll have to elaborate on the rules a little so we know exactly what is going on. Also, why limit yourself to one .java file? Its always easier to write seperate classes where necessary. To start with, how are the cards chosen? Are they just taken off the top of a deck continuously until the player gets it wrong? Or are a set number of cards slected at the start, like they do in gameshows? Either way they're likely to come from a deck, so if I were doing this I would write a Deck class, and probably a Card class. The Card object will know what suit it is and what value it is, pretty simple. When the deck class is first created it will create 52 cards of the correct values, and store them in an ArrayList. When a card is taken from the top of the deck, it should be deleted from the deck because it is no longer there. There will probably be another class called CardHolder or something, which in real life would be where the cards where placed after they were picked from the deck. You will either need to write a shuffling method that shuffles the deck of cards, or you will need to randomly select a card each time one is picked.

    When you've clarified what you want the rules to be, write down any ideas you have yourself in here so we can see exactly what you want it to be like

  3. #3
    Join Date
    Feb 2004
    Posts
    11
    First of all, I dont how to link multiple .java files together, that is why I wanted it to be one file.

    Second, the program would place five cards on the screen, the first one face up, the others face down. Then there are two buttons labeled high and low. You click on one to indicate whether you think the next card will be higher or lower. Once clicked on these buttons turn over the next card. If you are wrong, the program re-deals with the remaining cards in the deck. If you are right the game advances to the next card in the line until all five are turned over.

    It is a very simple game, and I want the program to be as simple as humanly possible.

    Manilla

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    oh you do know how to use multiple .class files, you just don't realise it. Everytime you use a library class such as String you are in fact using code that is contained in a different .class file. Someone wrote those in just the same way that you're going to write this one. To keep it very simple all you need to do is put all the .class files you write into the same folder, and then make objects of the classes in the same way that you would make objects of the String class or any other class. In the long run it will be easier this way because you can write reusable code and save time and space.

    As I said before you should create a Card class and a Deck class. The Card objects have a suit and a value, the Deck object creates 52 card objects and is responsible for dealing them randomly. When it deals them, it removes them because they are no longer in the deck. That would be a good start.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center