Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将驱动程序分配给UNO DiscardPile.java?_Java_Eclipse - Fatal编程技术网

如何将驱动程序分配给UNO DiscardPile.java?

如何将驱动程序分配给UNO DiscardPile.java?,java,eclipse,Java,Eclipse,我正在创建一个UNO项目,对于如何将驱动程序分配给我的类有点困惑 提前感谢您的回答 真诚地, 杰达M 我向我的同学们寻求帮助,并在互联网上搜寻任何可能对我有帮助的东西。我的教授一点帮助都没有哈哈 这是Driver.java文件的完整代码。如果你需要我给你任何其他的,我这样做没有问题 package unoGame; import java.util.Random; //import java.util.Collections; public class Driver { public

我正在创建一个UNO项目,对于如何将驱动程序分配给我的类有点困惑

提前感谢您的回答

真诚地, 杰达M

我向我的同学们寻求帮助,并在互联网上搜寻任何可能对我有帮助的东西。我的教授一点帮助都没有哈哈

这是Driver.java文件的完整代码。如果你需要我给你任何其他的,我这样做没有问题

package unoGame;
import java.util.Random;
//import java.util.Collections;

public class Driver {
    public static unoDeck theDeck = new unoDeck();
    public static PlayerHand[] thePlayers;
    public static DiscardPile dp = new DiscardPile();
    public static int nextPlayer;
    public static Random getRandom = new Random();

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        thePlayers = new PlayerHand[3];
        thePlayers[0] = new PlayerHand("name 1");
        thePlayers[1] = new PlayerHand("name 2");
        thePlayers[2] = new PlayerHand("name 3");

        theDeck.shuffle();
        System.out.println("Here is the Deck:  " + theDeck);

        System.out.println(" Welcome to UNO! ");

        if (dp.isEmpty()) {
            System.out.println(" Discard is Empty ");
        }
        else {
            System.out.println(" Not Empty ");
        }

        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < thePlayers.length; j++) {
                thePlayers[j].addCard(theDeck.deal());
            }
        }
        nextPlayer = 0;
        showPlayers();

        dp.addCard(theDeck.deal());

        while (checkForWin() == false) {
            findNextPlayer();

            if (theDeck.isEmpty()) {
                theDeck.replenish(dp.clear());
            }
            playerTurn();
        }
        System.out.println(thePlayers[nextPlayer], getName() + " Wins!")
    }
        public static void showPlayers() {
            for (PlayerHand p : thePlayers)
                System.out.println(p);
        }
        public static boolean checkForWin() {
            if (p.isWin()) {
                win = true;
            }
            return win;
        }

    public static void findNextPlayer() {
        nextPlayer++;
        nextPlayer = nextPlayer % thePlayers.length;
        if(dp.getTopCard().getValue()=="SK") {
            nextPlayer++;
            nextPlayer = nextPlayer % thePlayers.length;
        }
        if(dp.getTopCard().getValue() == "D2") {
            for(int i = 0; i <= 1; i++) {
                thePlayers[nextPlayer].addCard(theDeck.deal());
            }
        }
        if(dp.getTopCard().getValue() == "W4") {
            for(int i = 0; i <= 3; i++) {
                thePlayers[nextPlayer].addCard(theDeck.deal());
            }
        }
        if(dp.getTopCard().getValue() == "RV") {
            for(int i = 0; i < thePlayers.length / 2; i++) {
                PlayerHand rev = thePlayers[i];
                thePlayers[i] = thePlayers[thePlayers.length - i -1];
                rev = thePlayers[thePlayers.length - i -1];
                if(nextPlayer == 0) {
                    nextPlayer = 0;
                }
                if(nextPlayer == 2) {
                    nextPlayer = 1;
                }
            }
            nextPlayer++;
        }
    }
    public static void playerTurn() {
        if (thePlayers[nextPlayer].hasMatch(dp.getTopCard())) {
            System.out.println(thePlayers[nextPlayer].getName() + " has a match!");
            unoCard c = thePlayers[nextPlayer].playCard(dp.getTopCard());
            dp.addCard(c);
            if(c.getValue().equals("W")) {
                c.setColor(theDeck.newColor());
            }
            if(c.getValue().equals("W4")) {
                c.setColor(theDeck.newColor());
            }
            System.out.println(thePlayers[nextPlayer].getName() + " played a: "  dp.getTopCard());
            System.out.println(thePlayers[nextPlayer]);
        }
        else {
            unoCard c = theDeck.deal();
            thePlayers[nextPlayer]c.addCard(c);
            System.out.println(thePlayers[nextPlayer].getName() + " drew a: " + c);
        }
    }
}
打包游戏;
导入java.util.Random;
//导入java.util.Collections;
公务舱司机{
public static unoDeck theDeck=新建unoDeck();
公共静态播放器和播放器;
公共静态丢弃桩dp=新丢弃桩();
公共静态int-nextPlayer;
public static Random getRandom=new Random();
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
thePlayers=新玩家和[3];
thePlayers[0]=新玩家手(“名称1”);
thePlayers[1]=新的演奏者乐队(“名字2”);
thePlayers[2]=新的演奏者乐队(“名字3”);
theDeck.shuffle();
System.out.println(“这是甲板:“+theDeck”);
System.out.println(“欢迎来到UNO!”);
if(dp.isEmpty()){
System.out.println(“丢弃为空”);
}
否则{
System.out.println(“非空”);
}
对于(int i=0;i<7;i++){
对于(int j=0;j对于(int i=0;i这是您的
驱动程序
类,已修复编译问题。我建议您将其与当前代码进行比较,以查看我更改了什么

我还需要在类
unoDeck
中添加方法
infully()
,因为它不存在,并且是从类
Driver
调用的。现在该方法不起任何作用。正如我所说,我添加它只是为了修复编译错误

打包游戏;
导入java.util.Random;
公务舱司机{
public static unoDeck theDeck=新建unoDeck();
公共静态播放器和播放器;
公共静态丢弃桩dp=新丢弃桩();
公共静态int-nextPlayer;
public static Random getRandom=new Random();
公共静态void main(字符串[]args){
thePlayers=新玩家和[3];
thePlayers[0]=新玩家手(“名称1”);
thePlayers[1]=新的演奏者乐队(“名字2”);
thePlayers[2]=新的演奏者乐队(“名字3”);
theDeck.shuffle();
System.out.println(“这是甲板:“+theDeck”);
System.out.println(“欢迎来到UNO!”);
if(dp.isEmpty()){
System.out.println(“丢弃为空”);
}
否则{
System.out.println(“非空”);
}
对于(int i=0;i<7;i++){
对于(int j=0;j对于(int i=0;我为我难以置信的无知道歉,但哪一行是第46行?也请原谅我,但我的水晶球正在修复,所以你能发布你声称得到的错误的详细信息吗?啊,我的坏哈哈:46是deck.inful(dp.clear());我将用错误图片更新我的问题…你的问题并发布类
Driver
Done deal mate的所有代码。你希望我也发布其他相应的文件(DiscardPile、PlayerHand等)?非常感谢您的帮助!很抱歉在交流过程中遇到了麻烦,这是我的错,哈哈。祝您休息好。我会记住您的指导:)