I am trying create a simple card game. I have created four classes. One class holds a method for constructing a single card. Another class holds a method for making a deck from single cards. One class holds a method for shuffling the deck. And the fourth class is attempting to call each of these methods to create and shuffle a deck. I've looked through other posts on here so I believe I am calling the functions properly.
Here is the card constructor class:
package com.company;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class Card_Class {
private String suit, face;
private int value;
public BufferedImage cardImage;
public Card_Class(String suit, String face, int value, BufferedImage card) {
this.suit = suit;
this.face = face;
this.value = value;
cardImage = card;
}
Here is the deck constructor class (this class runs fine when calling the card constructor class)
package com.company;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class Deck {
public static Card_Class[] deckOfCards;
private int currentCard;
public Deck() throws IOException {
String[] faces = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
String[] suits = {"Diamonds", "Clubs", "Hearts", "Spades"};
deckOfCards = new Card_Class[52];
currentCard = 0;
final int width = 88;
final int height = 133;
final int rows =4;
final int columns = 13;
BufferedImage bigImage = ImageIO.read(new File("AllCards.png"));
BufferedImage tempCardImage;
for(int suit=0;suit <4; suit++){
for(int face=0;face<13;face++){
tempCardImage = bigImage.getSubimage(
face*width+(face*10)+8,
suit*height+(suit*10)+38,
width,
height);
deckOfCards[(face+(suit*13))] = new Card_Class(suits[suit],faces[face],(13*suit+face),tempCardImage);
}
}
Now I have a class to shuffle cards:
package com.company;
public class ShuffleDeck {
public static void main(String[] args) {
}
public static Object shuffle(Object[] cardDeck){
int place = 0;
for (int i = 0; i < cardDeck.length; i++) {
int n = (int) Math.ceil(Math.random() * cardDeck.length - 1);
Object a = cardDeck[i];
cardDeck[i] = cardDeck[n];
cardDeck[n] = a;
}
return cardDeck;
}
}
And my last class attempts to call all three of the methods to create an object array of cards and shuffle them.
package com.company;
import java.io.IOException;
public class CardDealer {
public static int[][] board = new int[4][14];
Deck CardDeck = new Deck();
ShuffleDeck riff = new ShuffleDeck();
riff.shuffle(CardDeck);
}
The errors I get say 'Cannot resolve symbol shuffle' and 'Unknown class CardDeck'. Again I have looked at other posts and can't figure out what is wrong. I think I need to be doing something to 'shuffle' so the program can find a path to that method, but I'm not sure how to do this.
I'm really stuck here so any help would be appreciated.