Search code examples
javaimageslick2d

Add a pictures to a card value?


I'm currently making a card game(made a custom one instead of lame poker), and basically I want to add pictures based on the value of the card. It's separated into a/b(a being the suit, b being the value).

Chunk of code I'm assuming will change to add pictures (or it's the card class?)

cards = new ArrayList < > ();
   for (int a = 0 ; a <= 3 ; a++)
    {
        for (int b = 0 ; b <= 12 ; b++)
        {
            cards.add (new Card (a, b));
        }
    }
}

//Method to draw a card and remove card from the current deck
public Card PlayerCardDraw ()
{
    Random generator = new Random ();
    int index = generator.nextInt (cards.size ());
    return cards.remove (index);
}

//Adds a card to player 1's hand kept in an arraylist to group cards to an individual player

public ArrayList <Card> p1Hand;
public ArrayList  Card> P1CardDraw ()
{
    p1Hand = new ArrayList < > ();
    p1Hand.add (PlayerCardDraw ());
    return p1Hand;
}

Solution

  • While I typed up the following answer, the asker wrote that he's using slick2D. That changes things.

    New Answer

    You should add slick2d as one of the tags for your question to get attention of the right crowd.

    Old Answer

    It seems like you have started with the underlying algorithm but you don't have any graphics or UI(User Interface) code done yet.

    This means you need to decide What technology you will use to write your code.

    If you want to write a game that sits on a computer (desktop/laptop) as an application and runs on it, then your options are Swing/AWT or Eclipse/SWT. They are pretty comparable, so I'd say whichever technology you can find an expert in.

    Another option is that this is a game that will sit in a web server, and people will play it through web browser. In that case you need to look into javascript or Swing/AWT. Google has this technology called GWT which works over web and integrates java and javascript well-together. That might be a great option for your needs.

    On the other hand, you might be writing a mobile game. If it's android then I'd suggest you look at it's sdk and make your decision. I believe you can write java apps for android. It might also be using GWT but not sure.

    Or it could be an iPhone app. I don't think iPhone apps can be written in Java. You need to get iPhone's SDK and learn it.

    Once you have decided on your platform and technology, that's when you are close to asking the question that you are asking right now.

    Still before you ask this question, you need to figure out, what your main window will look like, what kind of buttons and other widgets will be there.

    In short you are long way from putting that picture on the card, but with hard work and study of the technologies, you can get there.