Java-无法从另一个类

时间:2017-11-19 16:05:54

标签: java class methods

我正在尝试创建一个简单的纸牌游戏。我创建了四个班级。一类拥有构建单张卡的方法。另一个类有一种用单张牌制作牌组的方法。一个班级有一个洗牌的方法。并且第四类试图调用这些方法中的每一种来创建和洗牌。我已经浏览了这里的其他帖子,所以我相信我正在正确地调用这些功能 这是卡构造函数类:

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;


    }

这是deck构造函数类(调用card构造函数类时该类运行正常)

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);
            }
        }

现在我有一个课程来洗牌:

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;
    }
}

我的上一堂课试图调用所有三种方法来创建卡片的对象数组并将它们随机播放。

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);
}

我得到的错误是“无法解决符号洗牌”和“未知类CardDeck”。我再次查看其他帖子,无法弄清楚出了什么问题。我想我需要做一些“洗牌”,所以程序可以找到该方法的路径,但我不知道该怎么做。

我真的被困在这里所以任何帮助都会受到赞赏。

0 个答案:

没有答案