Menu
  • HOME
  • TAGS

(Java)How to change picture(War Card Game)

java,swing,user-interface,war,playing-cards

From your code, I am guessing you have a hidden instance variable declared and in your switch statement, you are adding icon to this JLabel. But in your if condition, you are not using this hidden variable, but creating a new one. Fix: Inside your for loop, search for all...

Solitaire: storing guaranteed wins cheaply

space-complexity,playing-cards

Given no prior information, the theoretical limit on how compactly you can represent an ordered deck of cards is 226 bits. Even the simple naive 6-bits-per card is only 312 bits, so you probably won't gain much by being clever. If you're willing to sacrifice a large part of the...

Creating a Deck of Cards

java,arrays,object,playing-cards

I don't have the time to test this, but what's intended is something like: deck[13 * i + k - 2] = new Card(suits[i], k); though personally I would use integers for suits as well--just a waste of time and space to use strings....

Reading in card deck

java,input,output,playing-cards

You could go with the traditional String#replace way. Example below. File file = ...; try { Scanner scanner = new Scanner(file); while(scanner.hasNextLine()) { String line = scanner.nextLine(); String[] values = line.split("-"); String rank = values[0].replace("[", "").trim(); String suite = values[1].replace("]", "").trim(); System.out.println(rank + " of " + suite + "...

How to make cards work in python [closed]

python,python-3.x,random,playing-cards

Not sure what you're trying to do, but here is a way to generate a shuffled deck of cards: ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] suite = ['clubs', 'hearts', 'spades', 'diamonds'] deck = [r + ' ' + s for r...

How to define and access list in a class - How to access a Player's hand in a Card Game

c#,list,playing-cards

This code in startGame keeps dealing until there are no cards left: while (newdeck.CountCards() != 0) { newdeck.dealCards(); } But dealCards is accessing the static (i.e. shared by all instances of the class) Player.hand, so all the cards get added to that. (I guess you were getting 60 when you...

F# modeling playing cards

f#,playing-cards

Since Color can always be inferred from Suit, there's no reason to model it explicitly; you'll want to make illegal states unrepresentable. You can still get a nice programming experience out of your model, and have a nice way of modelling colour, using an Active Pattern: type Suit = |...

Setting 13 cards on screen in Android

java,android,android-imageview,playing-cards

The issue is once you run out of horizontal space, you need to create a new row and add cards to that until that row runs out of space, etc. A GridLayout would be better suited for what you're trying to accomplish. You could also use a GridView or TableLayout....

Reading a text file of deck of cards and replacing strings [closed]

java,playing-cards

I'd recommend test driving a function to do the mapping. The file reading/writing is trivial to look up. Test driving leads to this: Tests: public class CardsTests { @Test public void TwoOfHearts() { Assert.assertEquals("Two of hearts (value = 2)", Card.fromString("2-H")); } @Test public void ThreeOfHearts() { Assert.assertEquals("Three of hearts (value...

Correcting and improving java code

java,if-statement,int,output,playing-cards

You can create an array of cardPlayers and cardComputers. For instance try this below int numPlayers = 14; int [] cardPlayer = new int[numPlayers]; int [] cardComputer = new int[numPlayers]; for (int i = 0; i < numPlayers; i++) { System.out.println("Player Card " + i + ": " + cardPlayer[i]);...

Enum types may not be instantiated error

java,arrays,enums,playing-cards

You can't instantiate an enum like you would instantiate a class. The statement new Rank(r.getRankValue(), r.toString()) is incorrect. This is what you can do instead : cards[posInDeck] = new Card(s.toString(),r,false); ...